{"record":{"id":"1c75be03cd2efa14","repo":"oven-sh/bun","slug":"github-token-environment-variable-is-required","errorCode":null,"errorMessage":"GITHUB_TOKEN environment variable is required","messagePattern":"GITHUB_TOKEN environment variable is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/auto-close-duplicates.ts","lineNumber":221,"sourceCode":"  });\n  // Close the issue as duplicate\n  await githubRequest(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, token, \"POST\", {\n    body: `Duplicate of #${duplicateOfNumber}.\n    \nThis issue has been automatically closed as a duplicate.\n\nIf this is incorrect, please re-open this issue or create a new one.\n\n🤖 Generated with [Claude Code](https://claude.ai/code)`,\n  });\n}\n\nasync function autoCloseDuplicates(): Promise<void> {\n  console.log(\"[DEBUG] Starting auto-close duplicates script\");\n\n  const token = process.env.GITHUB_TOKEN;\n  if (!token) {\n    throw new Error(\"GITHUB_TOKEN environment variable is required\");\n  }\n  console.log(\"[DEBUG] GitHub token found\");\n\n  // Parse GITHUB_REPOSITORY (format: \"owner/repo\")\n  const repository = process.env.GITHUB_REPOSITORY || \"oven-sh/bun\";\n  const [owner, repo] = repository.split(\"/\");\n  if (!owner || !repo) {\n    throw new Error(`Invalid GITHUB_REPOSITORY format: ${repository}`);\n  }\n  console.log(`[DEBUG] Repository: ${owner}/${repo}`);\n\n  const threeDaysAgo = new Date();\n  threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);\n  console.log(`[DEBUG] Checking for duplicate comments older than: ${threeDaysAgo.toISOString()}`);\n\n  console.log(\"[DEBUG] Fetching open issues created more than 3 days ago...\");\n  const allIssues: GitHubIssue[] = [];\n  let page = 1;","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/auto-close-duplicates.ts#L203-L239","documentation":"autoCloseDuplicates() requires GITHUB_TOKEN to authenticate every GitHub call (searching stale issues, reading comments, closing duplicates). Without it the script cannot run at all and aborts before any API request.","triggerScenarios":"Running the script locally or in CI without GITHUB_TOKEN in the environment; a workflow step missing the env: mapping for the token.","commonSituations":"Local reproduction attempt without exporting a token; workflow refactored and env block dropped; token secret renamed.","solutions":["Pass the Actions token: env: GITHUB_TOKEN: ${{ github.token }} on the step","Locally, export a PAT with repo scope as GITHUB_TOKEN before running","Confirm the secret exists under repository/organization secrets"],"exampleFix":"# before\n- run: bun scripts/auto-close-duplicates.ts\n\n# after\n- run: bun scripts/auto-close-duplicates.ts\n  env:\n    GITHUB_TOKEN: ${{ github.token }}\n    GITHUB_REPOSITORY: ${{ github.repository }}","handlingStrategy":"validation","validationCode":"if (!process.env.GITHUB_TOKEN) {\n  console.error('GITHUB_TOKEN not set; export it or add env: GITHUB_TOKEN: ${{ github.token }} to the step');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map github.token onto every step that calls the GitHub API","Keep a preflight env check at the top of CI helper scripts"],"tags":["github-api","environment-variables","ci","configuration"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}