MCPcopy Create free account
hub / github.com/anthropics/claude-code / autoCloseDuplicates

Function autoCloseDuplicates

scripts/auto-close-duplicates.ts:99–272  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97}
98
99async function autoCloseDuplicates(): Promise<void> {
100 console.log("[DEBUG] Starting auto-close duplicates script");
101
102 const token = process.env.GITHUB_TOKEN;
103 if (!token) {
104 throw new Error("GITHUB_TOKEN environment variable is required");
105 }
106 console.log("[DEBUG] GitHub token found");
107
108 const owner = process.env.GITHUB_REPOSITORY_OWNER || "anthropics";
109 const repo = process.env.GITHUB_REPOSITORY_NAME || "claude-code";
110 console.log(`[DEBUG] Repository: ${owner}/${repo}`);
111
112 const threeDaysAgo = new Date();
113 threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
114 console.log(
115 `[DEBUG] Checking for duplicate comments older than: ${threeDaysAgo.toISOString()}`
116 );
117
118 console.log("[DEBUG] Fetching open issues created more than 3 days ago...");
119 const allIssues: GitHubIssue[] = [];
120 let page = 1;
121 const perPage = 100;
122
123 while (true) {
124 const pageIssues: GitHubIssue[] = await githubRequest(
125 `/repos/${owner}/${repo}/issues?state=open&per_page=${perPage}&page=${page}`,
126 token
127 );
128
129 if (pageIssues.length === 0) break;
130
131 // Filter for issues created more than 3 days ago
132 const oldEnoughIssues = pageIssues.filter(issue =>
133 new Date(issue.created_at) <= threeDaysAgo
134 );
135
136 allIssues.push(...oldEnoughIssues);
137 page++;
138
139 // Safety limit to avoid infinite loops
140 if (page > 20) break;
141 }
142
143 const issues = allIssues;
144 console.log(`[DEBUG] Found ${issues.length} open issues`);
145
146 let processedCount = 0;
147 let candidateCount = 0;
148
149 for (const issue of issues) {
150 processedCount++;
151 console.log(
152 `[DEBUG] Processing issue #${issue.number} (${processedCount}/${issues.length}): ${issue.title}`
153 );
154
155 console.log(`[DEBUG] Fetching comments for issue #${issue.number}...`);
156 const comments: GitHubComment[] = await githubRequest(

Callers 1

Calls 3

closeIssueAsDuplicateFunction · 0.85
githubRequestFunction · 0.70

Tested by

no test coverage detected