Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions scripts/auto-close-duplicates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bun

import { githubRequest } from "./github-request.ts";

declare global {
var process: {
env: Record<string, string | undefined>;
Expand All @@ -25,27 +27,6 @@ interface GitHubReaction {
content: string;
}

async function githubRequest<T>(endpoint: string, token: string, method: string = 'GET', body?: any): Promise<T> {
const response = await fetch(`https://api.github.com${endpoint}`, {
method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/vnd.github.v3+json",
"User-Agent": "auto-close-duplicates-script",
...(body && { "Content-Type": "application/json" }),
},
...(body && { body: JSON.stringify(body) }),
});

if (!response.ok) {
throw new Error(
`GitHub API request failed: ${response.status} ${response.statusText}`
);
}

return response.json();
}

function extractDuplicateIssueNumber(commentBody: string): number | null {
// Try to match #123 format first
let match = commentBody.match(/#(\d+)/);
Expand Down Expand Up @@ -73,24 +54,28 @@ async function closeIssueAsDuplicate(
await githubRequest(
`/repos/${owner}/${repo}/issues/${issueNumber}`,
token,
'PATCH',
{
state: 'closed',
state_reason: 'duplicate',
labels: ['duplicate']
method: 'PATCH',
body: {
state: 'closed',
state_reason: 'duplicate',
labels: ['duplicate']
},
}
);

await githubRequest(
`/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
token,
'POST',
{
body: `This issue has been automatically closed as a duplicate of #${duplicateOfNumber}.
method: 'POST',
body: {
body: `This issue has been automatically closed as a duplicate of #${duplicateOfNumber}.

If this is incorrect, please re-open this issue or create a new one.

🤖 Generated with [Claude Code](https://claude.ai/code)`
},
}
);

Expand Down Expand Up @@ -272,6 +257,3 @@ async function autoCloseDuplicates(): Promise<void> {
}

autoCloseDuplicates().catch(console.error);

// Make it a module
export {};
38 changes: 9 additions & 29 deletions scripts/backfill-duplicate-comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bun

import { githubRequest } from "./github-request.ts";

declare global {
var process: {
env: Record<string, string | undefined>;
Expand All @@ -23,27 +25,6 @@ interface GitHubComment {
user: { type: string; id: number };
}

async function githubRequest<T>(endpoint: string, token: string, method: string = 'GET', body?: any): Promise<T> {
const response = await fetch(`https://api.github.com${endpoint}`, {
method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/vnd.github.v3+json",
"User-Agent": "backfill-duplicate-comments-script",
...(body && { "Content-Type": "application/json" }),
},
...(body && { body: JSON.stringify(body) }),
});

if (!response.ok) {
throw new Error(
`GitHub API request failed: ${response.status} ${response.statusText}`
);
}

return response.json();
}

async function triggerDedupeWorkflow(
owner: string,
repo: string,
Expand All @@ -59,12 +40,14 @@ async function triggerDedupeWorkflow(
await githubRequest(
`/repos/${owner}/${repo}/actions/workflows/claude-dedupe-issues.yml/dispatches`,
token,
'POST',
{
ref: 'main',
inputs: {
issue_number: issueNumber.toString()
}
method: 'POST',
body: {
ref: 'main',
inputs: {
issue_number: issueNumber.toString()
}
},
}
);
}
Expand Down Expand Up @@ -208,6 +191,3 @@ Environment Variables:
}

backfillDuplicateComments().catch(console.error);

// Make it a module
export {};
Loading