MCPcopy Index your code
hub / github.com/anomalyco/opencode / requireToken

Function requireToken

script/github/close-prs.ts:345–361  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343}
344
345async 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
363function requirePositiveInteger(name: string, value: string | undefined) {
364 const parsed = Number(value)

Callers 1

close-prs.tsFile · 0.85

Calls 2

spawnMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected