Skip to content

Commit 5d6b250

Browse files
serhiilenivClaude
authored andcommitted
fix(scripts): paginate comments and reactions in auto-close-duplicates
Both reads used GitHub's default page size of 30 and never followed pagination, unlike the issues list in the same script and every list call in sweep.ts. A thumbs-down past the first 30 reactions, or human replies after a dupe notice sitting at comment position 30, were invisible to the guards, so issues auto-closed despite objections. Add a githubRequestAllPages helper (per_page=100, follows pages until a short page) and use it for both reads. Fixes anthropics#80506
1 parent 32cf711 commit 5d6b250

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎scripts/auto-close-duplicates.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ async function githubRequest<T>(endpoint: string, token: string, method: string
4646
return response.json();
4747
}
4848

49+
// List endpoints return at most 100 items per page (30 by default), so
50+
// follow pagination until a short page signals the end of the collection.
51+
async function githubRequestAllPages<T>(
52+
endpoint: string,
53+
token: string
54+
): Promise<T[]> {
55+
const results: T[] = [];
56+
const perPage = 100;
57+
const separator = endpoint.includes("?") ? "&" : "?";
58+
59+
for (let page = 1; page <= 20; page++) {
60+
const pageItems: T[] = await githubRequest(
61+
`${endpoint}${separator}per_page=${perPage}&page=${page}`,
62+
token
63+
);
64+
results.push(...pageItems);
65+
if (pageItems.length < perPage) break;
66+
}
67+
68+
return results;
69+
}
70+
4971
function extractDuplicateIssueNumber(commentBody: string): number | null {
5072
// Try to match #123 format first
5173
let match = commentBody.match(/#(\d+)/);
@@ -153,7 +175,7 @@ async function autoCloseDuplicates(): Promise<void> {
153175
);
154176

155177
console.log(`[DEBUG] Fetching comments for issue #${issue.number}...`);
156-
const comments: GitHubComment[] = await githubRequest(
178+
const comments: GitHubComment[] = await githubRequestAllPages(
157179
`/repos/${owner}/${repo}/issues/${issue.number}/comments`,
158180
token
159181
);
@@ -217,7 +239,7 @@ async function autoCloseDuplicates(): Promise<void> {
217239
console.log(
218240
`[DEBUG] Issue #${issue.number} - checking reactions on duplicate comment...`
219241
);
220-
const reactions: GitHubReaction[] = await githubRequest(
242+
const reactions: GitHubReaction[] = await githubRequestAllPages(
221243
`/repos/${owner}/${repo}/issues/comments/${lastDupeComment.id}/reactions`,
222244
token
223245
);

0 commit comments

Comments
 (0)