From eb48a37a4869c83b90f311a283ce5339415943fe Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Fri, 8 Aug 2025 11:21:27 -0700 Subject: [PATCH] Improve auto-close duplicates script pagination and filtering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add pagination to fetch more than 100 issues (up to 20 pages/2000 issues) - Filter to only process issues created more than 3 days ago - Add created_at field to GitHubIssue interface 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- scripts/auto-close-duplicates.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/scripts/auto-close-duplicates.ts b/scripts/auto-close-duplicates.ts index 9985ba8c..1b358946 100644 --- a/scripts/auto-close-duplicates.ts +++ b/scripts/auto-close-duplicates.ts @@ -10,6 +10,7 @@ interface GitHubIssue { number: number; title: string; user: { id: number }; + created_at: string; } interface GitHubComment { @@ -61,11 +62,32 @@ async function autoCloseDuplicates(): Promise { `[DEBUG] Checking for duplicate comments older than: ${threeDaysAgo.toISOString()}` ); - console.log("[DEBUG] Fetching open issues..."); - const issues: GitHubIssue[] = await githubRequest( - `/repos/${owner}/${repo}/issues?state=open&per_page=100`, - token - ); + console.log("[DEBUG] Fetching open issues created more than 3 days ago..."); + const allIssues: GitHubIssue[] = []; + let page = 1; + const perPage = 100; + + while (true) { + const pageIssues: GitHubIssue[] = await githubRequest( + `/repos/${owner}/${repo}/issues?state=open&per_page=${perPage}&page=${page}`, + token + ); + + if (pageIssues.length === 0) break; + + // Filter for issues created more than 3 days ago + const oldEnoughIssues = pageIssues.filter(issue => + new Date(issue.created_at) <= threeDaysAgo + ); + + allIssues.push(...oldEnoughIssues); + page++; + + // Safety limit to avoid infinite loops + if (page > 20) break; + } + + const issues = allIssues; console.log(`[DEBUG] Found ${issues.length} open issues`); let processedCount = 0;