()
| 343 | } |
| 344 | |
| 345 | async function requireToken() { |
| 346 | const envToken = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN |
| 347 | if (envToken) return envToken |
| 348 | |
| 349 | const proc = Bun.spawn(["gh", "auth", "token"], { |
| 350 | stdout: "pipe", |
| 351 | stderr: "pipe", |
| 352 | }) |
| 353 | const stdout = await new Response(proc.stdout).text() |
| 354 | const stderr = await new Response(proc.stderr).text() |
| 355 | const exitCode = await proc.exited |
| 356 | if (exitCode === 0 && stdout.trim()) return stdout.trim() |
| 357 | |
| 358 | throw new Error( |
| 359 | `GitHub authentication is required. Set GITHUB_TOKEN/GH_TOKEN or run gh auth login.\n${stderr.trim()}`, |
| 360 | ) |
| 361 | } |
| 362 | |
| 363 | function requirePositiveInteger(name: string, value: string | undefined) { |
| 364 | const parsed = Number(value) |
no test coverage detected