Fall back to gh auth token when GITHUB_TOKEN is not set - #210
Conversation
|
Coverage after merging feat/gh-cli-token-fallback into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6e01afe to
d25c0fb
Compare
|
Coverage after merging feat/gh-cli-token-fallback into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Preserve the existing error message and align the affected user-facing documentation with the new upgrade behavior.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Adds gh auth token as a fallback when GITHUB_TOKEN is unset, covering search and upgrade flows.
Changes:
- Adds tested GitHub CLI token resolution.
- Integrates fallback authentication.
- Updates authentication and setup documentation.
| File | Description |
|---|---|
src/gh-cli.ts |
Implements gh auth token resolution. |
src/gh-cli.test.ts |
Tests fallback behavior. |
README.md |
Documents authentication fallback. |
github-code-search.ts |
Integrates fallback into search and upgrade commands. |
docs/reference/environment.md |
Documents authentication behavior. |
docs/getting-started/index.md |
Updates prerequisites. |
docs/getting-started/first-search.md |
Updates search prerequisites. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🔦 Lighthouse Report
|
Add src/gh-cli.ts: resolveGhAuthToken is a pure, dependency-injected resolution function (unit tested); getGhAuthToken is the sole call site for Bun.which/Bun.spawnSync. Wired into both searchAction and the upgrade subcommand's token lookup, falling back only when GITHUB_TOKEN is unset. Closes #208
Fixes CI coverage-threshold failure: gh-cli.ts was below the 75%/80% lines/functions threshold with only resolveGhAuthToken tested.
d25c0fb to
0d0eeda
Compare
|
Coverage after merging feat/gh-cli-token-fallback into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Prerequisites | ||
|
|
||
| The only runtime prerequisite is a **GitHub personal access token**. The pre-compiled binary is self-contained and has no runtime dependency — you do not need Bun to run it. | ||
| The only runtime prerequisite is a **GitHub personal access token** (or the [GitHub CLI](https://cli.github.com/), see below). The pre-compiled binary is self-contained and has no runtime dependency — you do not need Bun to run it. |
- Restore the exact original 'Error: GITHUB_TOKEN environment variable is not set.' message (unchanged acceptance-criteria contract) instead of replacing it; add the gh CLI hint as a separate dim line. - environment.md: clarify the GITHUB_TOKEN footnote applies to the search commands, and that upgrade never requires a token (uses one only opportunistically for rate limits). - docs/usage/upgrade.md: document the gh auth token fallback for upgrade. - Re-add the 'Already using the GitHub CLI?' tip to docs/getting-started/index.md, silently dropped by an earlier rebase onto main after #211 merged — this is what the prerequisite sentence's 'see below' was supposed to point to.
|
Coverage after merging feat/gh-cli-token-fallback into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


What does this PR do?
Closes #208.
src/gh-cli.ts:resolveGhAuthTokenis a pure, dependency-injected resolution function (which/exec injected — unit tested, no real subprocess spawned);getGhAuthTokenis the sole call site forBun.which/Bun.spawnSync, following the same "sole call site for a given API" convention asrender/terminal.ts.github-code-search.ts: bothsearchActionand theupgradesubcommand now resolve the token asprocess.env.GITHUB_TOKEN ?? getGhAuthToken()— zero behavior change whenGITHUB_TOKENis already set, and the same clear error message when neither resolves to a token.docs/reference/environment.md,docs/getting-started/index.md/first-search.md,README.md.How did you verify your code works?
src/gh-cli.test.ts: covers not-installed, success (trims token), non-zero exit, and blank-output cases, plus a purity check.ghinstalled & authenticated): unsettingGITHUB_TOKENand running a search successfully authenticates viagh auth token.bun test(1021 passing),bun run lint,bun run format:check,bun run knip,bun run build.tsall green.bun run docs:buildsucceeds.