diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts index 6996df7fc0..fc259cbdb7 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts @@ -38,7 +38,8 @@ export class GithubApi { return this.request('post', path, data); } - public getPaginated(pathname: string, baseParams: RequestParams = {}, currentPage: number = 0): Promise { + // In GitHub API paginated requests, page numbering is 1-based. (https://developer.github.com/v3/#pagination) + public getPaginated(pathname: string, baseParams: RequestParams = {}, currentPage: number = 1): Promise { const perPage = 100; const params = { ...baseParams, diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/mock-external-apis.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/mock-external-apis.ts index db39e3289a..34875e22a0 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/mock-external-apis.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/mock-external-apis.ts @@ -76,7 +76,7 @@ const GITHUB_PULLS_URL = `/repos/${AIO_GITHUB_ORGANIZATION}/${AIO_GITHUB_REPO}/p const GITHUB_TEAMS_URL = `/orgs/${AIO_GITHUB_ORGANIZATION}/teams`; const getIssueUrl = (prNum: number) => `${GITHUB_ISSUES_URL}/${prNum}`; -const getFilesUrl = (prNum: number, pageNum = 0) => `${GITHUB_PULLS_URL}/${prNum}/files?page=${pageNum}&per_page=100`; +const getFilesUrl = (prNum: number, pageNum = 1) => `${GITHUB_PULLS_URL}/${prNum}/files?page=${pageNum}&per_page=100`; const getCommentUrl = (prNum: number) => `${getIssueUrl(prNum)}/comments`; const getTeamMembershipUrl = (teamId: number, username: string) => `/teams/${teamId}/memberships/${username}`; @@ -97,7 +97,7 @@ const githubApi = nock(GITHUB_API_HOST).log(log).persist().matchHeader('Authoriz ////////////////////////////// // GENERAL responses -githubApi.get(GITHUB_TEAMS_URL + '?page=0&per_page=100').reply(200, TEST_TEAM_INFO); +githubApi.get(GITHUB_TEAMS_URL + '?page=1&per_page=100').reply(200, TEST_TEAM_INFO); githubApi.post(getCommentUrl(PrNums.TRUST_CHECK_ACTIVE_TRUSTED_USER)).reply(200); // BUILD_INFO errors diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts index 7d5250cce4..b512c1507e 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts @@ -126,8 +126,8 @@ describe('GithubApi', () => { (api as any).getPaginated('/foo/bar'); (api as any).getPaginated('/foo/bar', {baz: 'qux'}); - expect(api.get).toHaveBeenCalledWith('/foo/bar', {page: 0, per_page: 100}); - expect(api.get).toHaveBeenCalledWith('/foo/bar', {baz: 'qux', page: 0, per_page: 100}); + expect(api.get).toHaveBeenCalledWith('/foo/bar', {page: 1, per_page: 100}); + expect(api.get).toHaveBeenCalledWith('/foo/bar', {baz: 'qux', page: 1, per_page: 100}); }); @@ -162,9 +162,9 @@ describe('GithubApi', () => { const paramsForPage = (page: number) => ({baz: 'qux', page, per_page: 100}); expect(apiGetSpy).toHaveBeenCalledTimes(3); - expect(apiGetSpy.calls.argsFor(0)).toEqual(['/foo/bar', paramsForPage(0)]); - expect(apiGetSpy.calls.argsFor(1)).toEqual(['/foo/bar', paramsForPage(1)]); - expect(apiGetSpy.calls.argsFor(2)).toEqual(['/foo/bar', paramsForPage(2)]); + expect(apiGetSpy.calls.argsFor(0)).toEqual(['/foo/bar', paramsForPage(1)]); + expect(apiGetSpy.calls.argsFor(1)).toEqual(['/foo/bar', paramsForPage(2)]); + expect(apiGetSpy.calls.argsFor(2)).toEqual(['/foo/bar', paramsForPage(3)]); expect(data).toEqual(allItems);