From 04cace9ec00665c1158f97cb70da0f352fa484ae Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Mon, 11 Aug 2025 15:33:31 -0700 Subject: [PATCH 1/2] Consolidate GitHub issue closure events to prevent duplicates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate Statsig logging from auto-close-duplicates.ts - GitHub workflow now handles all issue closures uniformly - Add 'duplicate' label to ensure proper detection by workflow - Prevents double-logging when script closes issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- scripts/auto-close-duplicates.ts | 45 ++------------------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/scripts/auto-close-duplicates.ts b/scripts/auto-close-duplicates.ts index 34e2254..5720581 100644 --- a/scripts/auto-close-duplicates.ts +++ b/scripts/auto-close-duplicates.ts @@ -51,41 +51,6 @@ function extractDuplicateIssueNumber(commentBody: string): number | null { return match ? parseInt(match[1], 10) : null; } -async function logStatsigEvent(eventName: string, value: number, metadata: Record): Promise { - const statsigApiKey = process.env.STATSIG_API_KEY; - if (!statsigApiKey) { - console.log("[DEBUG] STATSIG_API_KEY not found, skipping Statsig logging"); - return; - } - - const eventPayload = { - events: [{ - eventName, - value, - metadata, - time: Math.floor(Date.now()).toString() - }] - }; - - try { - const response = await fetch('https://events.statsigapi.net/v1/log_event', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'STATSIG-API-KEY': statsigApiKey - }, - body: JSON.stringify(eventPayload) - }); - - if (response.ok) { - console.log(`[DEBUG] Successfully logged Statsig event: ${eventName}`); - } else { - console.log(`[DEBUG] Failed to log Statsig event: ${response.status} ${response.statusText}`); - } - } catch (error) { - console.log(`[DEBUG] Error logging to Statsig: ${error}`); - } -} async function closeIssueAsDuplicate( owner: string, @@ -100,7 +65,8 @@ async function closeIssueAsDuplicate( 'PATCH', { state: 'closed', - state_reason: 'not_planned' + state_reason: 'not_planned', + labels: ['duplicate'] } ); @@ -117,13 +83,6 @@ If this is incorrect, please re-open this issue or create a new one. } ); - // Log to Statsig - await logStatsigEvent('github_issue_closed_as_duplicate', 1, { - repository: `${owner}/${repo}`, - issue_number: issueNumber, - duplicate_of_issue: duplicateOfNumber, - closed_by: 'auto-close-script' - }); } async function autoCloseDuplicates(): Promise { From 4a04589002a157dc0ca8c1698c045d0bd0692fe9 Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Mon, 11 Aug 2025 15:44:08 -0700 Subject: [PATCH 2/2] Use proper 'duplicate' state_reason for issue closures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update auto-close script to use state_reason: 'duplicate' instead of 'not_planned' - Simplify workflow detection logic to only check for duplicate state_reason - Remove fallback logic for backward compatibility - use modern GitHub API 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/log-issue-events.yml | 10 +++------- scripts/auto-close-duplicates.ts | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/log-issue-events.yml b/.github/workflows/log-issue-events.yml index ae75a66..dae438f 100644 --- a/.github/workflows/log-issue-events.yml +++ b/.github/workflows/log-issue-events.yml @@ -115,14 +115,10 @@ jobs: CLOSED_AUTOMATICALLY="true" fi - # Check if closed as duplicate by looking for duplicate label or state_reason + # Check if closed as duplicate by state_reason CLOSED_AS_DUPLICATE="false" - if [ "$STATE_REASON" = "not_planned" ]; then - # Check if issue has duplicate label - LABELS=$(echo "$ISSUE_DATA" | jq -r '.labels[] | select(.name | test("duplicate"; "i")) | .name') - if [ -n "$LABELS" ]; then - CLOSED_AS_DUPLICATE="true" - fi + if [ "$STATE_REASON" = "duplicate" ]; then + CLOSED_AS_DUPLICATE="true" fi # Prepare the event payload diff --git a/scripts/auto-close-duplicates.ts b/scripts/auto-close-duplicates.ts index 5720581..0cee40a 100644 --- a/scripts/auto-close-duplicates.ts +++ b/scripts/auto-close-duplicates.ts @@ -65,7 +65,7 @@ async function closeIssueAsDuplicate( 'PATCH', { state: 'closed', - state_reason: 'not_planned', + state_reason: 'duplicate', labels: ['duplicate'] } );