Skip to content

Commit 8fd31c1

Browse files
authored
Set per_page=100 on paginated PyTorchBot GitHub calls (#8579)
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * #8584 * #8582 * #8580 * __->__ #8579 * #8578 * #8576 **Impact:** torchci webhook bots (merge, label, CRCR, cancel-on-close) **Risk:** low ## What Add `per_page=100` to the paginated GitHub REST reads in the webhook bots — PR reviews and repo labels (`pytorchBotHandler`), issue comments (`crcrOncallBot`), and workflow runs (`cancelWorkflowsOnCloseBot`) — replacing the default page size of 30. ## Why These installation-token calls share a single hourly rate limit that torchci periodically exhausts, resulting in intermittent 403s. Bumping the page size to the maximum cuts the number of requests each paginated call needs, trimming steady load on the failing bucket at effectively zero cost. # Notes Tests updated to expect the `per_page=100` query string on the mocked endpoints; no behavior change beyond page size. Signed-off-by: Jean Schmidt <contato@jschmidt.me>
1 parent 12b5aef commit 8fd31c1

7 files changed

Lines changed: 29 additions & 26 deletions

torchci/lib/bot/cancelWorkflowsOnCloseBot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function cancelWorkflowsOnCloseBot(app: Probot): void {
4747
owner,
4848
repo,
4949
head_sha: headSha,
50-
per_page: 30,
50+
per_page: 100,
5151
}
5252
);
5353

torchci/lib/bot/crcrOncallBot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async function findExistingComment(
4848
owner,
4949
repo,
5050
issue_number: prNumber,
51+
per_page: 100,
5152
});
5253
for (const comment of comments) {
5354
if (comment.body?.includes(marker)) {

torchci/lib/bot/pytorchBotHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ The explanation needs to be clear on why this is needed. Here are some good exam
171171
owner: this.owner,
172172
repo: this.repo,
173173
pull_number: this.prNum,
174+
per_page: 100,
174175
}
175176
);
176177

@@ -417,6 +418,7 @@ The explanation needs to be clear on why this is needed. Here are some good exam
417418
{
418419
owner: owner,
419420
repo: repo,
421+
per_page: 100,
420422
}
421423
);
422424
return labels.map((d: any) => d.name);

torchci/test/cancelWorkflowsOnCloseBot.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("accept bot", () => {
2626
merge_base_commit: { sha: "idk something else" },
2727
})
2828
.get(
29-
"/repos/pytorch/pytorch/actions/runs?head_sha=381ace654ad6474357cedad09418340896d16d90&per_page=30"
29+
"/repos/pytorch/pytorch/actions/runs?head_sha=381ace654ad6474357cedad09418340896d16d90&per_page=100"
3030
)
3131
.reply(200, [
3232
{ id: 6647495490, status: "in_progress" },

torchci/test/crcrOncallBot.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("crcrOncallBot", () => {
6363

6464
test("posts comment on L3 CRCR check run failure", async () => {
6565
const scope = nock("https://api.github.com")
66-
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`)
66+
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments?per_page=100`)
6767
.reply(200, [])
6868
.post(
6969
`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`,
@@ -89,7 +89,7 @@ describe("crcrOncallBot", () => {
8989

9090
test("posts comment on L4 CRCR check run failure", async () => {
9191
const scope = nock("https://api.github.com")
92-
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`)
92+
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments?per_page=100`)
9393
.reply(200, [])
9494
.post(
9595
`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`,
@@ -143,7 +143,7 @@ describe("crcrOncallBot", () => {
143143

144144
test("dedup: does not comment twice if marker already exists", async () => {
145145
const scope = nock("https://api.github.com")
146-
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`)
146+
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments?per_page=100`)
147147
.reply(200, [
148148
{
149149
id: 100,
@@ -191,7 +191,7 @@ L3:
191191

192192
test("posts comment when external_id contains PR number for cross-fork PR", async () => {
193193
const scope = nock("https://api.github.com")
194-
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`)
194+
.get(`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments?per_page=100`)
195195
.reply(200, [])
196196
.post(
197197
`/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments`,

torchci/test/labelCommands.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("label-bot", () => {
5757
const pr_number = event.payload.issue.number;
5858
const comment_number = event.payload.comment.id;
5959
const scope = nock("https://api.github.com")
60-
.get(`/repos/${owner}/${repo}/labels`)
60+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
6161
.reply(200, existingRepoLabelsResponse)
6262
.post(
6363
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -89,7 +89,7 @@ describe("label-bot", () => {
8989
const issue_number = event.payload.issue.number;
9090
const comment_number = event.payload.comment.id;
9191
const scope = nock("https://api.github.com")
92-
.get(`/repos/${owner}/${repo}/labels`)
92+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
9393
.reply(200, existingRepoLabelsResponse)
9494
.post(
9595
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -123,7 +123,7 @@ describe("label-bot", () => {
123123
const comment_number = event.payload.comment.id;
124124

125125
const scope = nock("https://api.github.com")
126-
.get(`/repos/${owner}/${repo}/labels`)
126+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
127127
.reply(200, existingRepoLabelsResponse)
128128
.post(
129129
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -167,7 +167,7 @@ describe("label-bot", () => {
167167
// With the new behavior, labels are still added even without approval,
168168
// but a comment warns that CI won't be triggered until approved.
169169
const scope = nock("https://api.github.com")
170-
.get(`/repos/${owner}/${repo}/labels`)
170+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
171171
.reply(200, existingRepoLabelsResponse)
172172
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
173173
expect(JSON.stringify(body)).toContain(
@@ -220,7 +220,7 @@ describe("label-bot", () => {
220220
const default_branch = event.payload.repository.default_branch;
221221

222222
const scope = nock("https://api.github.com")
223-
.get(`/repos/${owner}/${repo}/labels`)
223+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
224224
.reply(200, existingRepoLabelsResponse)
225225
.post(
226226
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -263,7 +263,7 @@ describe("label-bot", () => {
263263
const user = event.payload.comment.user.login;
264264

265265
const scope = nock("https://api.github.com")
266-
.get(`/repos/${owner}/${repo}/labels`)
266+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
267267
.reply(200, existingRepoLabelsResponse)
268268
.get(`/repos/${owner}/${repo}/collaborators/${user}/permission`)
269269
.reply(200, {
@@ -293,7 +293,7 @@ describe("label-bot", () => {
293293
const user = event.payload.comment.user.login;
294294

295295
const scope = nock("https://api.github.com")
296-
.get(`/repos/${owner}/${repo}/labels`)
296+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
297297
.reply(200, existingRepoLabelsResponse)
298298
.get(`/repos/${owner}/${repo}/collaborators/${user}/permission`)
299299
.reply(200, {
@@ -328,7 +328,7 @@ describe("label-bot", () => {
328328
const comment_number = event.payload.comment.id;
329329

330330
const scope = nock("https://api.github.com")
331-
.get(`/repos/${owner}/${repo}/labels`)
331+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
332332
.reply(200, existingRepoLabelsResponse)
333333
.post(
334334
`/repos/${owner}/${repo}/issues/${issue_number}/comments`,
@@ -362,7 +362,7 @@ describe("label-bot", () => {
362362
const user = event.payload.comment.user.login;
363363

364364
const scope = nock("https://api.github.com")
365-
.get(`/repos/${owner}/${repo}/labels`)
365+
.get(`/repos/${owner}/${repo}/labels?per_page=100`)
366366
.reply(200, existingRepoLabelsResponse)
367367
.get(`/repos/${owner}/${repo}/collaborators/${user}/permission`)
368368
.reply(200, { permission: "read" })

torchci/test/mergeCommands.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe("merge-bot", () => {
130130
return true;
131131
})
132132
.reply(200, {})
133-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
133+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
134134
.reply(200, requireDeepCopy("./fixtures/pull_request_reviews.json"));
135135

136136
const additionalScopes = [
@@ -178,7 +178,7 @@ describe("merge-bot", () => {
178178
return true;
179179
})
180180
.reply(200, {})
181-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
181+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
182182
.reply(200, requireDeepCopy("./fixtures/pull_request_reviews.json"));
183183

184184
const additionalScopes = [
@@ -206,7 +206,7 @@ describe("merge-bot", () => {
206206
const pr_number = event.payload.issue.number;
207207
const comment_number = event.payload.comment.id;
208208
const scope = nock("https://api.github.com")
209-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
209+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
210210
.reply(200, requireDeepCopy("./fixtures/pull_request_reviews.json"))
211211
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
212212
expect(JSON.stringify(body)).toContain(
@@ -958,7 +958,7 @@ describe("merge-bot", () => {
958958
return true;
959959
})
960960
.reply(200, {})
961-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
961+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
962962
.reply(200, requireDeepCopy("./fixtures/pull_request_reviews.json"));
963963

964964
await probot.receive(event);
@@ -1054,7 +1054,7 @@ describe("merge-bot", () => {
10541054
return true;
10551055
})
10561056
.reply(200, {})
1057-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1057+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
10581058
.reply(200, requireDeepCopy("./fixtures/pull_request_reviews.json"));
10591059
await probot.receive(event);
10601060

@@ -1405,7 +1405,7 @@ some other text lol
14051405
const pr_number = event.payload.issue.number;
14061406
const comment_number = event.payload.comment.id;
14071407
const scope = nock("https://api.github.com")
1408-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1408+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
14091409
.reply(200, pull_requests)
14101410
.post(
14111411
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -1443,7 +1443,7 @@ some other text lol
14431443
const pr_number = event.payload.issue.number;
14441444
const comment_number = event.payload.comment.id;
14451445
const scope = nock("https://api.github.com")
1446-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1446+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
14471447
.reply(200, pull_requests)
14481448
.post(
14491449
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -1488,7 +1488,7 @@ some other text lol
14881488
const pr_number = event.payload.issue.number;
14891489
const comment_number = event.payload.comment.id;
14901490
const scope = nock("https://api.github.com")
1491-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1491+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
14921492
.reply(200, pull_requests)
14931493
.post(
14941494
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -1527,7 +1527,7 @@ some other text lol
15271527
const pr_number = event.payload.issue.number;
15281528
const comment_number = event.payload.comment.id;
15291529
const scope = nock("https://api.github.com")
1530-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1530+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
15311531
.reply(200, pull_requests)
15321532
.post(
15331533
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -1559,7 +1559,7 @@ some other text lol
15591559
const pr_number = event.payload.issue.number;
15601560
const comment_number = event.payload.comment.id;
15611561
const scope = nock("https://api.github.com")
1562-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1562+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
15631563
.reply(200, pull_requests)
15641564
.post(
15651565
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,
@@ -1597,7 +1597,7 @@ some other text lol
15971597
const comment_number = event.payload.comment.id;
15981598

15991599
const scope = nock("https://api.github.com")
1600-
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews`)
1600+
.get(`/repos/${owner}/${repo}/pulls/${pr_number}/reviews?per_page=100`)
16011601
.reply(200, pull_requests)
16021602
.post(
16031603
`/repos/${owner}/${repo}/issues/comments/${comment_number}/reactions`,

0 commit comments

Comments
 (0)