Skip to content

fix(cli): authenticate self-update with GITHUB_TOKEN/GH_TOKEN and hint on rate limit - #127

Merged
sunerpy merged 1 commit into
mainfrom
fix/self-update-github-token
Jul 9, 2026
Merged

sunerpy merged 1 commit into
mainfrom
fix/self-update-github-token

Conversation

@sunerpy

@sunerpy sunerpy commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

codegraph self-update never passed an auth token to the self_update crate — its builder defaults auth_token: None and does not read the environment — so there was no way to lift the anonymous GitHub API rate limit, and self-update failed with an opaque HTTP 403.

This PR fixes two defects in crates/codegraph-cli/src/main.rs (CLI-only, additive):

  • Token support: resolve a token from GITHUB_TOKEN then GH_TOKEN (gh CLI convention) via an injectable env-getter, rejecting empty/whitespace values, and apply .auth_token() inside the shared configure closure so all three Update builders (--check, no---tag probe, and the final update()) authenticate uniformly. Behavior is unchanged when no token is set (anonymous, exactly as before).
  • Actionable error: the three GitHub-hitting call sites switched from .context(...) to .with_context(|| ...), preserving the underlying self_update error and appending a hint with the exact reauth command GITHUB_TOKEN=$(gh auth token) codegraph self-update. main prints errors with {err:#} (full anyhow chain), so the hint is user-visible.

New unit tests in mod self_update_tests cover token precedence, GH_TOKEN fallback, empty/whitespace rejection, none-set, trimming, and the hint string (injectable getter — no unsafe set_var).

Verification

  • make ci green locally (fmt + clippy + test + guardrail) via pre-push hook
  • self_update_tests: 12 passed (5 pre-existing + 7 new)
  • golden byte-stability oracle (equivalence.rs): 10 passed — extraction untouched
  • no new dependencies; no version bump (release-please owns bumps)

…t on rate limit

self-update never passed an auth token to the self_update crate (its builder
defaults to None and does not read the environment), so codegraph self-update
had no way to lift the anonymous GitHub API rate limit and failed with an
opaque HTTP 403.

Resolve a token from GITHUB_TOKEN then GH_TOKEN (gh CLI convention) via an
injectable env-getter, rejecting empty/whitespace values, and apply it to every
Update builder. On any GitHub-API call failure, surface the underlying error
and append an actionable hint showing the exact reauth command. Behavior is
unchanged when no token is set (anonymous). CLI-only and additive; extraction
and golden byte-stability are untouched.
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.80645% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-cli/src/main.rs 75.80% 15 Missing ⚠️

❌ Your patch check has failed because the patch coverage (75.80%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
- Coverage   95.65%   95.64%   -0.02%     
==========================================
  Files         115      115              
  Lines       55279    55334      +55     
==========================================
+ Hits        52876    52923      +47     
- Misses       2403     2411       +8     
Files with missing lines Coverage Δ
crates/codegraph-cli/src/main.rs 89.07% <75.80%> (-0.06%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit e62dc5c into main Jul 9, 2026
7 checks passed
@sunerpy
sunerpy deleted the fix/self-update-github-token branch July 9, 2026 04:35
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.

1 participant