diff --git a/lib/platform/gitea/__snapshots__/gitea-got-wrapper.spec.ts.snap b/lib/platform/gitea/__snapshots__/gitea-got-wrapper.spec.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..7fa9d87a6d38e6c280e8044dd50f1a8090f92bf4 --- /dev/null +++ b/lib/platform/gitea/__snapshots__/gitea-got-wrapper.spec.ts.snap @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`platform/gitea/gitea-got-wrapper supports root-level pagination 1`] = ` +Array [ + Array [ + "https://gitea.renovatebot.com/api/v1/pagination-example-1", + Object { + "baseUrl": "https://gitea.renovatebot.com/api/v1", + "hostType": "gitea", + "json": true, + "method": "GET", + "paginate": true, + }, + ], + Array [ + "https://gitea.renovatebot.com/api/v1/pagination-example-1?page=2", + Object { + "baseUrl": "https://gitea.renovatebot.com/api/v1", + "hostType": "gitea", + "json": true, + "method": "GET", + "paginate": true, + }, + ], + Array [ + "https://gitea.renovatebot.com/api/v1/pagination-example-1?page=3", + Object { + "baseUrl": "https://gitea.renovatebot.com/api/v1", + "hostType": "gitea", + "json": true, + "method": "GET", + "paginate": true, + }, + ], +] +`; diff --git a/lib/platform/gitea/gitea-got-wrapper.spec.ts b/lib/platform/gitea/gitea-got-wrapper.spec.ts index 31ec065dfa429390a5590d580c3054c2647bbab7..4dc23f28215df2d4ed021adde4d5df308d7d2a7d 100644 --- a/lib/platform/gitea/gitea-got-wrapper.spec.ts +++ b/lib/platform/gitea/gitea-got-wrapper.spec.ts @@ -48,10 +48,13 @@ describe('platform/gitea/gitea-got-wrapper', () => { }) ); - const res = await api.get('pagination-example-1', { paginate: true }); + const res = await api.get(`${baseURL}/pagination-example-1`, { + paginate: true, + }); expect(res.body).toHaveLength(6); expect(res.body).toEqual(['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr']); + expect(got.mock.calls).toMatchSnapshot(); expect(got).toHaveBeenCalledTimes(3); }); diff --git a/lib/platform/gitea/gitea-got-wrapper.ts b/lib/platform/gitea/gitea-got-wrapper.ts index 84bac293aa631bdcd4bd06f2c041146e045e06ce..26f4d7cff71c9b92c92b9ec2618173648f14869d 100644 --- a/lib/platform/gitea/gitea-got-wrapper.ts +++ b/lib/platform/gitea/gitea-got-wrapper.ts @@ -1,7 +1,7 @@ -import URL from 'url'; -import { GotApi, GotApiOptions, GotResponse } from '../common'; +import { URL } from 'url'; import { PLATFORM_TYPE_GITEA } from '../../constants/platforms'; import got from '../../util/got'; +import { GotApi, GotApiOptions, GotResponse } from '../common'; const hostType = PLATFORM_TYPE_GITEA; let baseUrl: string; @@ -28,15 +28,15 @@ async function get(path: string, options?: any): Promise<GotResponse> { const res = await got(path, opts); const pc = getPaginationContainer(res.body); if (opts.paginate && pc) { - const url = URL.parse(res.url, true); + const url = new URL(res.url); const total = parseInt(res.headers['x-total-count'] as string, 10); - let nextPage = parseInt(url.query.page as string, 10) || 1 + 1; + let nextPage = parseInt(url.searchParams.get('page') || '1', 10); while (total && pc.length < total) { nextPage += 1; - url.query.page = nextPage.toString(); + url.searchParams.set('page', nextPage.toString()); - const nextRes = await got(URL.format(url), opts); + const nextRes = await got(url.toString(), opts); pc.push(...getPaginationContainer(nextRes.body)); } }