converge more fetchers onto shared lib/gh.js client - #1273
kylerankin wants to merge 2 commits into
Conversation
Route the last hand-rolled GitHub API plumbing onto the single adr/0003-endorsed client in scripts/lib/gh.js (projectbluefin#1232). - fetch-feeds.js: githubToken() + githubHeaders() instead of an inline token and a 3-line Authorization/Accept/X-GitHub-Api-Version object. Link pagination and the Atom fallback are unchanged. - fetch-pin-state.js: githubFetch() with the shared header contract and its own 15s AbortSignal; still throws on a non-2xx as before. - fetch-hive-history.js: ghHeaders() now builds through githubHeaders() and drops its module-level GITHUB_TOKEN/GH_TOKEN restatement. Each migration is behavior-neutral: same endpoints, same token source, same timeout/fallback. Token acquisition, the Accept/api-version/user-agent contract, and the auth scheme now live in one place. The CJS request-queue.js side and the GHCR/Contents-specialized sites (sbom/api.js) are left for follow-up PRs. Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>
There was a problem hiding this comment.
Correctness review (head 8c0c99e)
-
Missed call site of now-async
ghHeaders()—scripts/fetch-hive-history.js:457. The PR makesghHeaders()async and awaits it at lines 204 and 389, but the snapshot fetch spreads it un-awaited:...ghHeaders(). Spreading a Promise yields no properties, so this request silently loses theUser-Agent: bluefin-hive-history/1.0header it previously carried (Authorization/Accept survive because they're set explicitly after the spread). The fetch is wrapped in try/catch and warns rather than fails, so this degrades silently. Fix:...(await ghHeaders()), or leave this non-GitHub call on a plain literal since it targets the hive API, not GitHub. -
Dead code + changed error message —
scripts/fetch-pin-state.js:46-58.githubFetchdefaults tothrowOnError: trueand throws on non-2xx (lib/gh.js:70-78), so theif (!response.ok)block at lines 54-58 is now unreachable and the thrown message changes fromGitHub API error for ${repo}/${filePath}: ...toGET <url> -> <status>, losing the repo/path context. Minor, but the PR body's "still throws on a non-2xx" implies the existing handler still runs — it doesn't. Alsotoken: githubToken()passed togithubFetchat line 47 is a no-op (githubFetchhas notokenoption; auth flows via the pre-built headers) — harmless but worth removing.
fetch-feeds.js changes look behavior-equivalent (Atom fallback and pagination untouched).
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.78
…tch-pin-state - fetch-hive-history.js: spread an awaited ghHeaders() so the snapshot request keeps its User-Agent header (was spreading an un-awaited Promise). - fetch-pin-state.js: githubFetch throws on non-2xx (throwOnError defaults true), so the !response.ok guard was unreachable dead code; also drop the no-op token option githubFetch does not accept.
|
Addressed both findings:
|
There was a problem hiding this comment.
HUMAN DECISION NEEDED — @kylerankin the migrated snapshot fetch now sends the repo's GITHUB_TOKEN to the third-party hive host and likely breaks snapshot auth; needs a decision on fixing vs. reverting that hunk before merge.
High — GitHub token leaked to non-GitHub host + snapshot auth regression (scripts/fetch-hive-history.js:455-460)
The snapshot call to https://hosted-projectbluefin-knuckle-gjvq.hive.hivecommons.dev/api/status spreads await ghHeaders() and then overrides with Authorization: Bearer <HIVE_API_TOKEN>. The old ghHeaders() used the exact-case key Authorization, so the spread-then-override cleanly replaced the GitHub token. The new githubHeaders() (scripts/lib/gh.js:41-50) emits lowercase authorization, so the override no longer replaces it — both keys survive and undici's Headers joins them:
authorization => Bearer <GITHUB_TOKEN>, Bearer <HIVE_API_TOKEN>
accept => application/vnd.github+json, application/json
(verified with Node fetch Headers). Two consequences:
- The
GITHUB_TOKENis now transmitted to the hive host — directly contrary togh.js's own contract comment "Nothing here emits a token, a host address" (scripts/lib/gh.js:12). - The mangled joined bearer value will almost certainly 401; the fail-soft catch at
scripts/fetch-hive-history.js:465-471just warns and skips, so snapshot metrics silently stop being recorded.
Since this endpoint isn't the GitHub API at all, the fix is to not use ghHeaders() here — build { "User-Agent", Authorization, Accept } inline for the snapshot call (or add an option to omit the token). This contradicts the PR body's "Behavior-neutral" claim for this file.
Low (scripts/fetch-pin-state.js:52-60): error text on non-2xx changes from GitHub API error for <repo>/<path>: <status> <statusText> to githubFetch's GET <url> -> <status> — URL is retained so context survives; noting only because the PR body says the throw behavior is "kept".
Everything else checks out: githubToken() returns null so the fetch-feeds.js:69-72 no-token Atom fallback still triggers; fetch-pin-state.js keeps its v3+json accept override and 15s abort signal; all three ghHeaders() call sites in fetch-hive-history.js were updated to await; importing lib/gh.js (which imports fetch-factory-stats.js) is side-effect-free due to the main-module guard at fetch-factory-stats.js:366.
Reviewed at head 2ea2fb1.
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.78
Migrates three more hand-rolled GitHub API fetchers onto the single adr/0003-endorsed client in
scripts/lib/gh.js(#1232), continuing the convergence started forfetch-hive-live-data.jsandfetch-factory-stats.js.What changed — token acquisition, the Accept/api-version/user-agent contract, and the Bearer auth scheme now flow through
githubToken()/githubHeaders()instead of being restated per file:scripts/fetch-feeds.js— replaces its inlineGITHUB_TOKEN||GH_TOKENread and the 3-lineAuthorization/Accept/X-GitHub-Api-Versionobject withgithubToken()+githubHeaders(). Link-header pagination and the Atom fallback are untouched.scripts/fetch-pin-state.js— goes throughgithubFetch()with the shared header contract (kept itsaccept: v3+jsonoverride for the Contents API) and its own 15sAbortSignal; still throws on a non-2xx.scripts/fetch-hive-history.js—ghHeaders()now builds throughgithubHeaders()and drops its module-levelGITHUB_TOKEN/GH_TOKENrestatement.Behavior-neutral. Same endpoints, same token source, same timeout/fallback per file — only the auth/header construction is deduplicated. This closes most of the "8 hand-rolled token+header sites" the issue names; the remaining
githubHeaders/sequentialFetchWithDelayCJS side (lib/request-queue.js) and the GHCR-specializedlib/sbom/api.js(Basicx-access-token, a genuinely different auth target) are left for follow-up PRs.Commits are DCO-signed so the signoff email matches the author email.
— hive: backend=pi model=lemonade/Ornith-1.5-35B-A3B-GGUF-Q6_K
🐝 Hive Agent:
contributor| SHA:8c0c99ea