Skip to content

[architect] Converge ESM GitHub fetch sites onto lib/gh.js (#1232) - #1236

Open
kylerankin wants to merge 1 commit into
projectbluefin:mainfrom
kylerankin:fix/github-api-plumbing
Open

[architect] Converge ESM GitHub fetch sites onto lib/gh.js (#1232)#1236
kylerankin wants to merge 1 commit into
projectbluefin:mainfrom
kylerankin:fix/github-api-plumbing

Conversation

@kylerankin

Copy link
Copy Markdown
Contributor

Resolves architect issue #1232 (first incremental step): the GitHub API plumbing was forked three ways — lib/request-queue.js (CJS), lib/gh.js (ESM), and hand-rolled token+header sites across the fetch layer. This converges the ESM half onto lib/gh.js.

What changed

lib/gh.js gains two exports so every ESM fetch site routes through one client instead of restating plumbing:

  • githubHeaders(token, { accept, apiVersion, userAgent }) — the single header contract (accept, pinned x-github-api-version, project user-agent, Bearer auth). Callers override only accept where an endpoint needs a different representation (e.g. the Contents API .raw).
  • githubFetch(path, { headers, signal, fetchImpl, throwOnError }) — one request through the shared client; throws on non-2xx unless throwOnError: false, so fail-soft sites still get a null fallback.

Migrated the two ESM hand-rolled sites:

  • lib/factory-monthly-metrics.mjs — token via githubToken(), headers via githubHeaders(), lane runs via githubFetch().
  • lib/tap-promotions.mjs — PR files and package descriptions now build headers and fetch through the shared client, keeping their per-endpoint accept overrides (v3+json, v3.raw) and throw/return semantics.

Behaviour

Neutral. Token acquisition, header shape, timeout signal, fetchImpl injection, and throw-vs-return semantics are preserved per site. All 1000 existing tests still pass; the new githubHeaders/githubFetch contracts are covered by new cases in gh-lib.test.js (1008 tests total). Prettier + eslint clean.

Follow-up

The CJS hand-rolled sites (fetch-feeds, fetch-pin-state, fetch-hive-live-data, fetch-hive-history, fetch-factory-stats, lib/sbom/api) remain on lib/request-queue.js for a separate incremental migration of the CJS half.

— hive: backend=pi model=lemonade/Ornith-1.5-35B-A3B-GGUF-Q6_K

🐝 Hive Agent: contributor | SHA: a032a053

The GitHub API plumbing was forked three ways: lib/request-queue.js (CJS),
lib/gh.js (ESM), and hand-rolled token+header sites in the fetch layer
(architect issue projectbluefin#1232). This converges the ESM half onto lib/gh.js.

lib/gh.js gains two exports so every ESM fetch site routes through one
client instead of restating plumbing:

  * githubHeaders(token, {accept, apiVersion, userAgent}) — the single
    header contract (accept, pinned x-github-api-version, project
    user-agent, Bearer auth). Callers override only accept where an
    endpoint needs a different representation (Contents API .raw).
  * githubFetch(path, {headers, signal, fetchImpl, throwOnError}) — one
    request through the shared client; throws on non-2xx unless
    throwOnError:false, so fail-soft sites still get a null fallback.

Migrated the two ESM hand-rolled sites:

  * lib/factory-monthly-metrics.mjs — token via githubToken(), headers via
    githubHeaders(), lane runs via githubFetch().
  * lib/tap-promotions.mjs — PR files and package descriptions now build
    headers and fetch through the shared client, keeping their per-endpoint
    accept overrides (v3+json, v3.raw) and throw/return semantics.

Behaviour is unchanged: all 1000 existing tests still pass, and the new
githubHeaders/githubFetch contracts are covered by gh-lib.test.js. The CJS
hand-rolled sites (fetch-feeds, fetch-pin-state, fetch-hive-*,
fetch-factory-stats, lib/sbom/api) remain on lib/request-queue.js for a
separate incremental migration.

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>
@castrojo
castrojo enabled auto-merge September 13, 2026 07:58
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.

2 participants