mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 15:36:25 +00:00
fix(github): paginationField for check runs (#10003)
This commit is contained in:
parent
b210ef668f
commit
f946b7407e
3 changed files with 45 additions and 3 deletions
|
@ -920,6 +920,7 @@ export async function getBranchStatus(
|
|||
accept: 'application/vnd.github.antiope-preview+json',
|
||||
},
|
||||
paginate: true,
|
||||
paginationField: 'check_runs',
|
||||
};
|
||||
const checkRunsRaw = (
|
||||
await githubApi.getJson<{
|
||||
|
|
|
@ -59,6 +59,36 @@ describe(getName(), () => {
|
|||
const trace = httpMock.getTrace();
|
||||
expect(trace).toHaveLength(3);
|
||||
});
|
||||
it('uses paginationField', async () => {
|
||||
const url = '/some-url';
|
||||
httpMock
|
||||
.scope(githubApiHost)
|
||||
.get(url)
|
||||
.reply(
|
||||
200,
|
||||
{ the_field: ['a'], total: 4 },
|
||||
{
|
||||
link: `<${url}?page=2>; rel="next", <${url}?page=3>; rel="last"`,
|
||||
}
|
||||
)
|
||||
.get(`${url}?page=2`)
|
||||
.reply(
|
||||
200,
|
||||
{ the_field: ['b', 'c'], total: 4 },
|
||||
{
|
||||
link: `<${url}?page=3>; rel="next", <${url}?page=3>; rel="last"`,
|
||||
}
|
||||
)
|
||||
.get(`${url}?page=3`)
|
||||
.reply(200, { the_field: ['d'], total: 4 });
|
||||
const res: any = await githubApi.getJson('some-url', {
|
||||
paginate: true,
|
||||
paginationField: 'the_field',
|
||||
});
|
||||
expect(res.body.the_field).toEqual(['a', 'b', 'c', 'd']);
|
||||
const trace = httpMock.getTrace();
|
||||
expect(trace).toHaveLength(3);
|
||||
});
|
||||
it('attempts to paginate', async () => {
|
||||
const url = '/some-url';
|
||||
httpMock
|
||||
|
|
|
@ -25,6 +25,7 @@ interface GithubInternalOptions extends InternalHttpOptions {
|
|||
|
||||
export interface GithubHttpOptions extends InternalHttpOptions {
|
||||
paginate?: boolean | string;
|
||||
paginationField?: string;
|
||||
pageLimit?: number;
|
||||
token?: string;
|
||||
}
|
||||
|
@ -208,12 +209,22 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
|
|||
}
|
||||
);
|
||||
const pages = await pAll(queue, { concurrency: 5 });
|
||||
if (opts.paginationField) {
|
||||
result.body[opts.paginationField] = result.body[
|
||||
opts.paginationField
|
||||
].concat(
|
||||
...pages
|
||||
.filter(Boolean)
|
||||
.map((page) => page.body[opts.paginationField])
|
||||
);
|
||||
} else {
|
||||
result.body = result.body.concat(
|
||||
...pages.filter(Boolean).map((page) => page.body)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
handleGotError(err, url, opts);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue