fix(backend-git-gateway): re-write GitHub pagination links (#3135)
This commit is contained in:
committed by
Shawn Erquhart
parent
48afa8dfe4
commit
834f6b9e45
@ -66,7 +66,7 @@ describe('getAllResponses', () => {
|
||||
|
||||
it('should return all paged response', async () => {
|
||||
interceptCall({ repeat: 3, data: generatePulls(70) });
|
||||
const res = await getAllResponses('https://api.github.com/pulls');
|
||||
const res = await getAllResponses('https://api.github.com/pulls', {}, 'next', url => url);
|
||||
const pages = await Promise.all(res.map(res => res.json()));
|
||||
|
||||
expect(pages[0]).toHaveLength(30);
|
||||
|
@ -80,7 +80,8 @@ export const parseLinkHeader = flow([
|
||||
export const getAllResponses = async (
|
||||
url: string,
|
||||
options: { headers?: {} } = {},
|
||||
linkHeaderRelName = 'next',
|
||||
linkHeaderRelName: string,
|
||||
nextUrlProcessor: (url: string) => string,
|
||||
) => {
|
||||
const maxResponses = 30;
|
||||
let responseCount = 1;
|
||||
@ -95,7 +96,7 @@ export const getAllResponses = async (
|
||||
const nextURL = linkHeader && parseLinkHeader(linkHeader)[linkHeaderRelName];
|
||||
|
||||
const { headers = {} } = options;
|
||||
req = nextURL && unsentRequest.fromFetchArguments(nextURL, { headers });
|
||||
req = nextURL && unsentRequest.fromFetchArguments(nextUrlProcessor(nextURL), { headers });
|
||||
pageResponses.push(pageResponse);
|
||||
responseCount++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user