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',
|
accept: 'application/vnd.github.antiope-preview+json',
|
||||||
},
|
},
|
||||||
paginate: true,
|
paginate: true,
|
||||||
|
paginationField: 'check_runs',
|
||||||
};
|
};
|
||||||
const checkRunsRaw = (
|
const checkRunsRaw = (
|
||||||
await githubApi.getJson<{
|
await githubApi.getJson<{
|
||||||
|
|
|
@ -59,6 +59,36 @@ describe(getName(), () => {
|
||||||
const trace = httpMock.getTrace();
|
const trace = httpMock.getTrace();
|
||||||
expect(trace).toHaveLength(3);
|
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 () => {
|
it('attempts to paginate', async () => {
|
||||||
const url = '/some-url';
|
const url = '/some-url';
|
||||||
httpMock
|
httpMock
|
||||||
|
|
|
@ -25,6 +25,7 @@ interface GithubInternalOptions extends InternalHttpOptions {
|
||||||
|
|
||||||
export interface GithubHttpOptions extends InternalHttpOptions {
|
export interface GithubHttpOptions extends InternalHttpOptions {
|
||||||
paginate?: boolean | string;
|
paginate?: boolean | string;
|
||||||
|
paginationField?: string;
|
||||||
pageLimit?: number;
|
pageLimit?: number;
|
||||||
token?: string;
|
token?: string;
|
||||||
}
|
}
|
||||||
|
@ -208,9 +209,19 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const pages = await pAll(queue, { concurrency: 5 });
|
const pages = await pAll(queue, { concurrency: 5 });
|
||||||
result.body = result.body.concat(
|
if (opts.paginationField) {
|
||||||
...pages.filter(Boolean).map((page) => page.body)
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue