Skip to content

[architect] Converge CJS GitHub fetchers onto shared lib/request-queue.js (#1232) - #1260

Open
mendezr wants to merge 1 commit into
projectbluefin:mainfrom
mendezr:arch/converge-cjs-github-fetchers
Open

mendezr wants to merge 1 commit into
projectbluefin:mainfrom
mendezr:arch/converge-cjs-github-fetchers

Conversation

@mendezr

@mendezr mendezr commented Sep 14, 2026

Copy link
Copy Markdown

What

Converges the remaining hand-rolled CJS GitHub REST fetchers onto a single shared client, closing the CJS half of architect issue #1232. The ESM half already routes through scripts/lib/gh.js (PRs #1236 and #1257).

scripts/lib/gh.js became the single ESM GitHub client; this PR makes scripts/lib/request-queue.js its CJS twin and migrates the hand-rolled CJS sites onto it.

scripts/lib/request-queue.js:

  • githubToken() — the one token source (GITHUB_TOKEN, then GH_TOKEN).
  • githubHeaders(token, opts) — the one header contract: Accept: application/vnd.github+json, pinned x-github-api-version: 2022-11-28, project user-agent, optional Bearer auth. Callers override accept only where an endpoint needs a different representation.
  • githubFetch(path, { headers, signal, throwOnError }) — one request through the shared client, mirroring lib/gh.js githubFetch. Resolves relative paths against the canonical origin, forwards an optional AbortSignal timeout, and throws on non-2xx unless throwOnError: false.

scripts/fetch-feeds.js and scripts/fetch-pin-state.js:

  • Drop inline GITHUB_TOKEN/GH_TOKEN reads, hand-built header objects, and raw fetch() calls; go through githubToken()/githubHeaders()/githubFetch().
  • fetch-feeds keeps its Link pagination (reads the returned Response) and its Atom-feed fallback (via throwOnError: false).
  • fetch-pin-state keeps its v3+json accept override, its user-agent, and its 15s AbortSignal timeout.

Behaviour

Neutral. Same endpoints, same pagination, same timeouts, same fail-soft wrappers — only the token acquisition and header/auth construction are deduplicated. GitHub treats application/vnd.github.v3+json and application/vnd.github+json identically, so the header convergence changes no returned data.

Verified: npm test (1147 tests) passes; eslint clean on all changed files.

Left for later

fetch-hive-history.js is intentionally not migrated in this pass: its ghHeaders() helper is also used for the non-GitHub hosted Knuckle snapshot endpoint, so it warrants a dedicated follow-up rather than a mechanical swap.

— hive: backend=goose model=deepseek/deepseek-v4-flash-0731

…tbluefin#1232)

The ESM fetch sites already route through lib/gh.js (PRs projectbluefin#1236, projectbluefin#1257).
This closes the CJS side of issue projectbluefin#1232 by making lib/request-queue.js the
CJS twin of lib/gh.js and migrating the remaining hand-rolled GitHub REST
sites onto it.

lib/request-queue.js:
- Add githubToken() as the single token source (GITHUB_TOKEN then GH_TOKEN).
- Extend githubHeaders() to the one header contract — Accept
  application/vnd.github+json, pinned x-github-api-version 2022-11-28,
  project user-agent, optional Bearer auth — with per-call overrides for
  endpoints that need a different representation.
- Add githubFetch() mirroring lib/gh.js githubFetch: resolves relative
  paths against the canonical origin, forwards an optional AbortSignal
  timeout, and throws on non-2xx unless throwOnError is false (for the
  fail-soft callers that prefer a fallback payload over an exception).

fetch-feeds.js, fetch-pin-state.js:
- Drop their inline GITHUB_TOKEN/GH_TOKEN reads, hand-built header objects,
  and raw fetch() calls; go through githubToken()/githubHeaders()/
  githubFetch(). fetch-feeds keeps its Link pagination via the returned
  Response; fetch-pin-state keeps its v3+json accept override, its
  user-agent, and its 15s AbortSignal timeout.
- fetch-feeds now fails soft through githubFetch({ throwOnError:false }),
  preserving the Atom-feed fallback on a non-2xx.

Behaviour is neutral: same endpoints, same pagination, same timeouts, same
fail-soft wrappers — only token acquisition and header/auth construction are
deduplicated. GitHub treats application/vnd.github.v3+json and
application/vnd.github+json identically.

fetch-hive-history.js is intentionally left for a follow-up: its ghHeaders()
helper is also used for the non-GitHub hosted Knuckle snapshot endpoint, so
it needs a separate pass rather than a mechanical swap.

Verified: npm test (1147 tests) passes; eslint clean on all changed files.

— hive: backend=goose model=deepseek/deepseek-v4-flash-0731

Signed-off-by: mendezr <mendezr@users.noreply.github.com>
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