clew-code 0.2.29 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/clew.cjs +2 -2
- package/package.json +5 -2
- package/scripts/auto-close-duplicates.ts +277 -0
- package/scripts/backfill-duplicate-comments.ts +213 -0
- package/scripts/codegraph.ts +221 -0
- package/scripts/comment-on-duplicates.sh +95 -0
- package/scripts/edit-issue-labels.sh +84 -0
- package/scripts/final-peer-rename.mjs +46 -0
- package/scripts/fix-encoding.mjs +83 -0
- package/scripts/fix-inconsistencies.mjs +67 -0
- package/scripts/generate-docs.ts +307 -0
- package/scripts/gh.sh +96 -0
- package/scripts/install.ps1 +37 -0
- package/scripts/install.sh +49 -0
- package/scripts/issue-lifecycle.ts +38 -0
- package/scripts/lifecycle-comment.ts +53 -0
- package/scripts/normalize-html.mjs +37 -0
- package/scripts/preload.ts +159 -0
- package/scripts/rename-content-peer-to-swarm.mjs +67 -0
- package/scripts/rename-hooks-mesh.mjs +6 -0
- package/scripts/rename-peer-to-swarm.mjs +62 -0
- package/scripts/run_devcontainer_claude_code.ps1 +152 -0
- package/scripts/scrape.py +82 -0
- package/scripts/session.ts +195 -0
- package/scripts/sweep.ts +168 -0
- package/scripts/write-discovery-test.cjs +93 -0
- package/scripts/write-discovery-test2.cjs +65 -0
- package/scripts/write-server-final.cjs +108 -0
- package/scripts/write-server-test.cjs +69 -0
- package/scripts/write-server-test2.cjs +99 -0
- package/scripts/write-server-test3.cjs +59 -0
- package/scripts/write-server-test4.cjs +108 -0
- package/scripts/write-server-v2.cjs +142 -0
- package/scripts/write-server-v2b.cjs +129 -0
- package/scripts/write-server-v2c.cjs +136 -0
- package/scripts/write-store-test.cjs +12 -0
- package/scripts/write-store-test2.cjs +163 -0
package/bin/clew.cjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clew-code",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30",
|
|
4
4
|
"description": "ClewCode — multi-provider AI coding agent CLI",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"bin/",
|
|
13
13
|
"dist/",
|
|
14
14
|
"docs/",
|
|
15
|
+
"scripts/",
|
|
15
16
|
"README.md",
|
|
16
17
|
"LICENSE.md"
|
|
17
18
|
],
|
|
@@ -42,7 +43,9 @@
|
|
|
42
43
|
"docs:watch": "bun --watch run scripts/generate-docs.ts",
|
|
43
44
|
"preload": "bun run scripts/preload.ts",
|
|
44
45
|
"session": "bun run scripts/session.ts",
|
|
45
|
-
"relay": "bun run src/remote/relay-server.ts"
|
|
46
|
+
"relay": "bun run src/remote/relay-server.ts",
|
|
47
|
+
"install:unix": "bash scripts/install.sh",
|
|
48
|
+
"install:win": "powershell -ExecutionPolicy Bypass -File scripts/install.ps1"
|
|
46
49
|
},
|
|
47
50
|
"keywords": [
|
|
48
51
|
"ai",
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
var process: {
|
|
5
|
+
env: Record<string, string | undefined>;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface GitHubIssue {
|
|
10
|
+
number: number;
|
|
11
|
+
title: string;
|
|
12
|
+
user: { id: number };
|
|
13
|
+
created_at: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface GitHubComment {
|
|
17
|
+
id: number;
|
|
18
|
+
body: string;
|
|
19
|
+
created_at: string;
|
|
20
|
+
user: { type: string; id: number };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface GitHubReaction {
|
|
24
|
+
user: { id: number };
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function githubRequest<T>(endpoint: string, token: string, method: string = 'GET', body?: any): Promise<T> {
|
|
29
|
+
const response = await fetch(`https://api.github.com${endpoint}`, {
|
|
30
|
+
method,
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${token}`,
|
|
33
|
+
Accept: "application/vnd.github.v3+json",
|
|
34
|
+
"User-Agent": "auto-close-duplicates-script",
|
|
35
|
+
...(body && { "Content-Type": "application/json" }),
|
|
36
|
+
},
|
|
37
|
+
...(body && { body: JSON.stringify(body) }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`GitHub API request failed: ${response.status} ${response.statusText}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return response.json();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function extractDuplicateIssueNumber(commentBody: string): number | null {
|
|
50
|
+
// Try to match #123 format first
|
|
51
|
+
let match = commentBody.match(/#(\d+)/);
|
|
52
|
+
if (match) {
|
|
53
|
+
return parseInt(match[1], 10);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Try to match GitHub issue URL format: https://github.com/owner/repo/issues/123
|
|
57
|
+
match = commentBody.match(/github\.com\/[^\/]+\/[^\/]+\/issues\/(\d+)/);
|
|
58
|
+
if (match) {
|
|
59
|
+
return parseInt(match[1], 10);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async function closeIssueAsDuplicate(
|
|
67
|
+
owner: string,
|
|
68
|
+
repo: string,
|
|
69
|
+
issueNumber: number,
|
|
70
|
+
duplicateOfNumber: number,
|
|
71
|
+
token: string
|
|
72
|
+
): Promise<void> {
|
|
73
|
+
await githubRequest(
|
|
74
|
+
`/repos/${owner}/${repo}/issues/${issueNumber}`,
|
|
75
|
+
token,
|
|
76
|
+
'PATCH',
|
|
77
|
+
{
|
|
78
|
+
state: 'closed',
|
|
79
|
+
state_reason: 'duplicate',
|
|
80
|
+
labels: ['duplicate']
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
await githubRequest(
|
|
85
|
+
`/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
|
|
86
|
+
token,
|
|
87
|
+
'POST',
|
|
88
|
+
{
|
|
89
|
+
body: `This issue has been automatically closed as a duplicate of #${duplicateOfNumber}.
|
|
90
|
+
|
|
91
|
+
If this is incorrect, please re-open this issue or create a new one.
|
|
92
|
+
|
|
93
|
+
🤖 Generated with [Claude Code](https://claude.ai/code)`
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async 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(
|
|
157
|
+
`/repos/${owner}/${repo}/issues/${issue.number}/comments`,
|
|
158
|
+
token
|
|
159
|
+
);
|
|
160
|
+
console.log(
|
|
161
|
+
`[DEBUG] Issue #${issue.number} has ${comments.length} comments`
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const dupeComments = comments.filter(
|
|
165
|
+
(comment) =>
|
|
166
|
+
comment.body.includes("Found") &&
|
|
167
|
+
comment.body.includes("possible duplicate") &&
|
|
168
|
+
comment.user.type === "Bot"
|
|
169
|
+
);
|
|
170
|
+
console.log(
|
|
171
|
+
`[DEBUG] Issue #${issue.number} has ${dupeComments.length} duplicate detection comments`
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
if (dupeComments.length === 0) {
|
|
175
|
+
console.log(
|
|
176
|
+
`[DEBUG] Issue #${issue.number} - no duplicate comments found, skipping`
|
|
177
|
+
);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const lastDupeComment = dupeComments[dupeComments.length - 1];
|
|
182
|
+
const dupeCommentDate = new Date(lastDupeComment.created_at);
|
|
183
|
+
console.log(
|
|
184
|
+
`[DEBUG] Issue #${
|
|
185
|
+
issue.number
|
|
186
|
+
} - most recent duplicate comment from: ${dupeCommentDate.toISOString()}`
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
if (dupeCommentDate > threeDaysAgo) {
|
|
190
|
+
console.log(
|
|
191
|
+
`[DEBUG] Issue #${issue.number} - duplicate comment is too recent, skipping`
|
|
192
|
+
);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
console.log(
|
|
196
|
+
`[DEBUG] Issue #${
|
|
197
|
+
issue.number
|
|
198
|
+
} - duplicate comment is old enough (${Math.floor(
|
|
199
|
+
(Date.now() - dupeCommentDate.getTime()) / (1000 * 60 * 60 * 24)
|
|
200
|
+
)} days)`
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const commentsAfterDupe = comments.filter(
|
|
204
|
+
(comment) => new Date(comment.created_at) > dupeCommentDate
|
|
205
|
+
);
|
|
206
|
+
console.log(
|
|
207
|
+
`[DEBUG] Issue #${issue.number} - ${commentsAfterDupe.length} comments after duplicate detection`
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (commentsAfterDupe.length > 0) {
|
|
211
|
+
console.log(
|
|
212
|
+
`[DEBUG] Issue #${issue.number} - has activity after duplicate comment, skipping`
|
|
213
|
+
);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
console.log(
|
|
218
|
+
`[DEBUG] Issue #${issue.number} - checking reactions on duplicate comment...`
|
|
219
|
+
);
|
|
220
|
+
const reactions: GitHubReaction[] = await githubRequest(
|
|
221
|
+
`/repos/${owner}/${repo}/issues/comments/${lastDupeComment.id}/reactions`,
|
|
222
|
+
token
|
|
223
|
+
);
|
|
224
|
+
console.log(
|
|
225
|
+
`[DEBUG] Issue #${issue.number} - duplicate comment has ${reactions.length} reactions`
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const authorThumbsDown = reactions.some(
|
|
229
|
+
(reaction) =>
|
|
230
|
+
reaction.user.id === issue.user.id && reaction.content === "-1"
|
|
231
|
+
);
|
|
232
|
+
console.log(
|
|
233
|
+
`[DEBUG] Issue #${issue.number} - author thumbs down reaction: ${authorThumbsDown}`
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
if (authorThumbsDown) {
|
|
237
|
+
console.log(
|
|
238
|
+
`[DEBUG] Issue #${issue.number} - author disagreed with duplicate detection, skipping`
|
|
239
|
+
);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const duplicateIssueNumber = extractDuplicateIssueNumber(lastDupeComment.body);
|
|
244
|
+
if (!duplicateIssueNumber) {
|
|
245
|
+
console.log(
|
|
246
|
+
`[DEBUG] Issue #${issue.number} - could not extract duplicate issue number from comment, skipping`
|
|
247
|
+
);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
candidateCount++;
|
|
252
|
+
const issueUrl = `https://github.com/${owner}/${repo}/issues/${issue.number}`;
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
console.log(
|
|
256
|
+
`[INFO] Auto-closing issue #${issue.number} as duplicate of #${duplicateIssueNumber}: ${issueUrl}`
|
|
257
|
+
);
|
|
258
|
+
await closeIssueAsDuplicate(owner, repo, issue.number, duplicateIssueNumber, token);
|
|
259
|
+
console.log(
|
|
260
|
+
`[SUCCESS] Successfully closed issue #${issue.number} as duplicate of #${duplicateIssueNumber}`
|
|
261
|
+
);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error(
|
|
264
|
+
`[ERROR] Failed to close issue #${issue.number} as duplicate: ${error}`
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
console.log(
|
|
270
|
+
`[DEBUG] Script completed. Processed ${processedCount} issues, found ${candidateCount} candidates for auto-close`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
autoCloseDuplicates().catch(console.error);
|
|
275
|
+
|
|
276
|
+
// Make it a module
|
|
277
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
var process: {
|
|
5
|
+
env: Record<string, string | undefined>;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface GitHubIssue {
|
|
10
|
+
number: number;
|
|
11
|
+
title: string;
|
|
12
|
+
state: string;
|
|
13
|
+
state_reason?: string;
|
|
14
|
+
user: { id: number };
|
|
15
|
+
created_at: string;
|
|
16
|
+
closed_at?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface GitHubComment {
|
|
20
|
+
id: number;
|
|
21
|
+
body: string;
|
|
22
|
+
created_at: string;
|
|
23
|
+
user: { type: string; id: number };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function githubRequest<T>(endpoint: string, token: string, method: string = 'GET', body?: any): Promise<T> {
|
|
27
|
+
const response = await fetch(`https://api.github.com${endpoint}`, {
|
|
28
|
+
method,
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: `Bearer ${token}`,
|
|
31
|
+
Accept: "application/vnd.github.v3+json",
|
|
32
|
+
"User-Agent": "backfill-duplicate-comments-script",
|
|
33
|
+
...(body && { "Content-Type": "application/json" }),
|
|
34
|
+
},
|
|
35
|
+
...(body && { body: JSON.stringify(body) }),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`GitHub API request failed: ${response.status} ${response.statusText}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return response.json();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function triggerDedupeWorkflow(
|
|
48
|
+
owner: string,
|
|
49
|
+
repo: string,
|
|
50
|
+
issueNumber: number,
|
|
51
|
+
token: string,
|
|
52
|
+
dryRun: boolean = true
|
|
53
|
+
): Promise<void> {
|
|
54
|
+
if (dryRun) {
|
|
55
|
+
console.log(`[DRY RUN] Would trigger dedupe workflow for issue #${issueNumber}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await githubRequest(
|
|
60
|
+
`/repos/${owner}/${repo}/actions/workflows/claude-dedupe-issues.yml/dispatches`,
|
|
61
|
+
token,
|
|
62
|
+
'POST',
|
|
63
|
+
{
|
|
64
|
+
ref: 'main',
|
|
65
|
+
inputs: {
|
|
66
|
+
issue_number: issueNumber.toString()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function backfillDuplicateComments(): Promise<void> {
|
|
73
|
+
console.log("[DEBUG] Starting backfill duplicate comments script");
|
|
74
|
+
|
|
75
|
+
const token = process.env.GITHUB_TOKEN;
|
|
76
|
+
if (!token) {
|
|
77
|
+
throw new Error(`GITHUB_TOKEN environment variable is required
|
|
78
|
+
|
|
79
|
+
Usage:
|
|
80
|
+
GITHUB_TOKEN=your_token bun run scripts/backfill-duplicate-comments.ts
|
|
81
|
+
|
|
82
|
+
Environment Variables:
|
|
83
|
+
GITHUB_TOKEN - GitHub personal access token with repo and actions permissions (required)
|
|
84
|
+
DRY_RUN - Set to "false" to actually trigger workflows (default: true for safety)
|
|
85
|
+
MAX_ISSUE_NUMBER - Only process issues with numbers less than this value (default: 4050)`);
|
|
86
|
+
}
|
|
87
|
+
console.log("[DEBUG] GitHub token found");
|
|
88
|
+
|
|
89
|
+
const owner = "anthropics";
|
|
90
|
+
const repo = "claude-code";
|
|
91
|
+
const dryRun = process.env.DRY_RUN !== "false";
|
|
92
|
+
const maxIssueNumber = parseInt(process.env.MAX_ISSUE_NUMBER || "4050", 10);
|
|
93
|
+
const minIssueNumber = parseInt(process.env.MIN_ISSUE_NUMBER || "1", 10);
|
|
94
|
+
|
|
95
|
+
console.log(`[DEBUG] Repository: ${owner}/${repo}`);
|
|
96
|
+
console.log(`[DEBUG] Dry run mode: ${dryRun}`);
|
|
97
|
+
console.log(`[DEBUG] Looking at issues between #${minIssueNumber} and #${maxIssueNumber}`);
|
|
98
|
+
|
|
99
|
+
console.log(`[DEBUG] Fetching issues between #${minIssueNumber} and #${maxIssueNumber}...`);
|
|
100
|
+
const allIssues: GitHubIssue[] = [];
|
|
101
|
+
let page = 1;
|
|
102
|
+
const perPage = 100;
|
|
103
|
+
|
|
104
|
+
while (true) {
|
|
105
|
+
const pageIssues: GitHubIssue[] = await githubRequest(
|
|
106
|
+
`/repos/${owner}/${repo}/issues?state=all&per_page=${perPage}&page=${page}&sort=created&direction=desc`,
|
|
107
|
+
token
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (pageIssues.length === 0) break;
|
|
111
|
+
|
|
112
|
+
// Filter to only include issues within the specified range
|
|
113
|
+
const filteredIssues = pageIssues.filter(issue =>
|
|
114
|
+
issue.number >= minIssueNumber && issue.number < maxIssueNumber
|
|
115
|
+
);
|
|
116
|
+
allIssues.push(...filteredIssues);
|
|
117
|
+
|
|
118
|
+
// If the oldest issue in this page is still above our minimum, we need to continue
|
|
119
|
+
// but if the oldest issue is below our minimum, we can stop
|
|
120
|
+
const oldestIssueInPage = pageIssues[pageIssues.length - 1];
|
|
121
|
+
if (oldestIssueInPage && oldestIssueInPage.number >= maxIssueNumber) {
|
|
122
|
+
console.log(`[DEBUG] Oldest issue in page #${page} is #${oldestIssueInPage.number}, continuing...`);
|
|
123
|
+
} else if (oldestIssueInPage && oldestIssueInPage.number < minIssueNumber) {
|
|
124
|
+
console.log(`[DEBUG] Oldest issue in page #${page} is #${oldestIssueInPage.number}, below minimum, stopping`);
|
|
125
|
+
break;
|
|
126
|
+
} else if (filteredIssues.length === 0 && pageIssues.length > 0) {
|
|
127
|
+
console.log(`[DEBUG] No issues in page #${page} are in range #${minIssueNumber}-#${maxIssueNumber}, continuing...`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
page++;
|
|
131
|
+
|
|
132
|
+
// Safety limit to avoid infinite loops
|
|
133
|
+
if (page > 200) {
|
|
134
|
+
console.log("[DEBUG] Reached page limit, stopping pagination");
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.log(`[DEBUG] Found ${allIssues.length} issues between #${minIssueNumber} and #${maxIssueNumber}`);
|
|
140
|
+
|
|
141
|
+
let processedCount = 0;
|
|
142
|
+
let candidateCount = 0;
|
|
143
|
+
let triggeredCount = 0;
|
|
144
|
+
|
|
145
|
+
for (const issue of allIssues) {
|
|
146
|
+
processedCount++;
|
|
147
|
+
console.log(
|
|
148
|
+
`[DEBUG] Processing issue #${issue.number} (${processedCount}/${allIssues.length}): ${issue.title}`
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
console.log(`[DEBUG] Fetching comments for issue #${issue.number}...`);
|
|
152
|
+
const comments: GitHubComment[] = await githubRequest(
|
|
153
|
+
`/repos/${owner}/${repo}/issues/${issue.number}/comments`,
|
|
154
|
+
token
|
|
155
|
+
);
|
|
156
|
+
console.log(
|
|
157
|
+
`[DEBUG] Issue #${issue.number} has ${comments.length} comments`
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Look for existing duplicate detection comments (from the dedupe bot)
|
|
161
|
+
const dupeDetectionComments = comments.filter(
|
|
162
|
+
(comment) =>
|
|
163
|
+
comment.body.includes("Found") &&
|
|
164
|
+
comment.body.includes("possible duplicate") &&
|
|
165
|
+
comment.user.type === "Bot"
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
console.log(
|
|
169
|
+
`[DEBUG] Issue #${issue.number} has ${dupeDetectionComments.length} duplicate detection comments`
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// Skip if there's already a duplicate detection comment
|
|
173
|
+
if (dupeDetectionComments.length > 0) {
|
|
174
|
+
console.log(
|
|
175
|
+
`[DEBUG] Issue #${issue.number} already has duplicate detection comment, skipping`
|
|
176
|
+
);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
candidateCount++;
|
|
181
|
+
const issueUrl = `https://github.com/${owner}/${repo}/issues/${issue.number}`;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
console.log(
|
|
185
|
+
`[INFO] ${dryRun ? '[DRY RUN] ' : ''}Triggering dedupe workflow for issue #${issue.number}: ${issueUrl}`
|
|
186
|
+
);
|
|
187
|
+
await triggerDedupeWorkflow(owner, repo, issue.number, token, dryRun);
|
|
188
|
+
|
|
189
|
+
if (!dryRun) {
|
|
190
|
+
console.log(
|
|
191
|
+
`[SUCCESS] Successfully triggered dedupe workflow for issue #${issue.number}`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
triggeredCount++;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error(
|
|
197
|
+
`[ERROR] Failed to trigger workflow for issue #${issue.number}: ${error}`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Add a delay between workflow triggers to avoid overwhelming the system
|
|
202
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
console.log(
|
|
206
|
+
`[DEBUG] Script completed. Processed ${processedCount} issues, found ${candidateCount} candidates without duplicate comments, ${dryRun ? 'would trigger' : 'triggered'} ${triggeredCount} workflows`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
backfillDuplicateComments().catch(console.error);
|
|
211
|
+
|
|
212
|
+
// Make it a module
|
|
213
|
+
export {};
|