Skip to content

Fall back to gh auth token when GITHUB_TOKEN is not set - #210

Merged
shouze merged 4 commits into
mainfrom
feat/gh-cli-token-fallback
Sep 19, 2026
Merged

shouze merged 4 commits into
mainfrom
feat/gh-cli-token-fallback

Conversation

@shouze

@shouze shouze commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #208.

  • Adds src/gh-cli.ts: resolveGhAuthToken is a pure, dependency-injected resolution function (which/exec injected — unit tested, no real subprocess spawned); getGhAuthToken is the sole call site for Bun.which / Bun.spawnSync, following the same "sole call site for a given API" convention as render/terminal.ts.
  • github-code-search.ts: both searchAction and the upgrade subcommand now resolve the token as process.env.GITHUB_TOKEN ?? getGhAuthToken() — zero behavior change when GITHUB_TOKEN is already set, and the same clear error message when neither resolves to a token.
  • Docs: docs/reference/environment.md, docs/getting-started/index.md / first-search.md, README.md.

How did you verify your code works?

  • New src/gh-cli.test.ts: covers not-installed, success (trims token), non-zero exit, and blank-output cases, plus a purity check.
  • Manual smoke test on this machine (real gh installed & authenticated): unsetting GITHUB_TOKEN and running a search successfully authenticates via gh auth token.
  • bun test (1021 passing), bun run lint, bun run format:check, bun run knip, bun run build.ts all green.
  • bun run docs:build succeeds.

Copilot AI lite review requested due to automatic review settings September 19, 2026 11:18
@github-actions

Copy link
Copy Markdown
Contributor

Coverage after merging feat/gh-cli-token-fallback into main will be

96.67%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.46%100%100%99.41%282
   gh-cli.ts55.56%100%50%56.25%38–44
   group.ts98.92%100%98.33%99.03%263–265, 525, 531, 864
   output.ts99.38%100%95.83%99.66%88
   regex.ts99.42%100%100%99.38%360
   render.ts90.99%100%88.24%91.09%177, 201–206, 208–210, 212–213, 234, 427–428, 528–532, 562–569, 571–579, 581–584
   scroll-cooldown.ts100%100%100%100%
   style.ts100%100%100%100%
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   layout-constants.ts100%100%100%100%
   mouse-hit.ts100%100%100%100%
   mouse.ts100%100%100%100%
   rows.ts99.42%100%100%99.38%239
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%
   terminal.ts100%100%100%100%

@github-actions

Copy link
Copy Markdown
Contributor

Coverage after merging feat/gh-cli-token-fallback into main will be

96.67%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.46%100%100%99.41%282
   gh-cli.ts55.56%100%50%56.25%38–44
   group.ts98.92%100%98.33%99.03%263–265, 525, 531, 864
   output.ts99.38%100%95.83%99.66%88
   regex.ts99.42%100%100%99.38%360
   render.ts90.99%100%88.24%91.09%177, 201–206, 208–210, 212–213, 234, 427–428, 528–532, 562–569, 571–579, 581–584
   scroll-cooldown.ts100%100%100%100%
   style.ts100%100%100%100%
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   layout-constants.ts100%100%100%100%
   mouse-hit.ts100%100%100%100%
   mouse.ts100%100%100%100%
   rows.ts99.42%100%100%99.38%239
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%
   terminal.ts100%100%100%100%

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity · 1 Low severity

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.

Comment thread github-code-search.ts
Comment thread docs/reference/environment.md Outdated
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🔦 Lighthouse Report

Page ⚡ Perf ♿ A11y 🛡️ BP 🔍 SEO Report
/github-code-search/ 🟢 97 (≥96) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view
/github-code-search/getting-started/ 🟢 99 (≥96) 🟢 100 (≥99) 🟢 100 (≥99) 🟢 100 (≥99) 🔗 view

Thresholds: Perf ≥ 96 · A11y ≥ 99 · BP ≥ 99 · SEO ≥ 99
commit 3f47958 · full workflow run

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.
…n rebase

These were silently reverted during the rebase onto post-#211 main (never
part of this PR's own diff before), since #211 removed the same wording
that was accidentally shared with #209. Re-add them here so they're
properly attributed to this PR.
@shouze
shouze force-pushed the feat/gh-cli-token-fallback branch from d25c0fb to 0d0eeda Compare September 19, 2026 11:31
@github-actions

Copy link
Copy Markdown
Contributor

Coverage after merging feat/gh-cli-token-fallback into main will be

96.88%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.46%100%100%99.41%282
   gh-cli.ts100%100%100%100%
   group.ts98.92%100%98.33%99.03%263–265, 525, 531, 864
   output.ts99.38%100%95.83%99.66%88
   regex.ts99.42%100%100%99.38%360
   render.ts90.99%100%88.24%91.09%177, 201–206, 208–210, 212–213, 234, 427–428, 528–532, 562–569, 571–579, 581–584
   scroll-cooldown.ts100%100%100%100%
   style.ts100%100%100%100%
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   layout-constants.ts100%100%100%100%
   mouse-hit.ts100%100%100%100%
   mouse.ts100%100%100%100%
   rows.ts99.42%100%100%99.38%239
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%
   terminal.ts100%100%100%100%

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Address the unresolved token error handling and conflicting authentication documentation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)

# 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.
@github-actions

Copy link
Copy Markdown
Contributor

Coverage after merging feat/gh-cli-token-fallback into main will be

96.88%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   aggregate.ts100%100%100%100%
   api-utils.ts93.20%100%93.75%93.13%101–103, 65, 73, 86–87, 91–92
   api.ts94.74%100%100%94.07%340–344, 405, 422, 63–69
   cache.ts94.67%100%100%94.29%139–141, 39
   completions.ts99.46%100%100%99.41%282
   gh-cli.ts100%100%100%100%
   group.ts98.92%100%98.33%99.03%263–265, 525, 531, 864
   output.ts99.38%100%95.83%99.66%88
   regex.ts99.42%100%100%99.38%360
   render.ts90.99%100%88.24%91.09%177, 201–206, 208–210, 212–213, 234, 427–428, 528–532, 562–569, 571–579, 581–584
   scroll-cooldown.ts100%100%100%100%
   style.ts100%100%100%100%
   upgrade.ts88.38%100%94.44%87.89%128, 131, 133, 153, 167–168, 188–195, 198–204, 209, 214, 250–253
src/render
   filter-match.ts97.44%100%92.31%100%
   filter.ts100%100%100%100%
   highlight.ts96.63%100%90.40%99.31%284–285
   layout-constants.ts100%100%100%100%
   mouse-hit.ts100%100%100%100%
   mouse.ts100%100%100%100%
   rows.ts99.42%100%100%99.38%239
   selection.ts100%100%100%100%
   summary.ts100%100%100%100%
   team-pick.ts100%100%100%100%
   terminal.ts100%100%100%100%

@shouze
shouze merged commit 5cc4ebc into main Sep 19, 2026
8 checks passed
@shouze
shouze deleted the feat/gh-cli-token-fallback branch September 19, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fall back to gh auth token when GITHUB_TOKEN is not set

2 participants