fix(templates): resolve GitHub API host from env in ralph-triage.js#1438
Draft
omercangumus wants to merge 1 commit into
Draft
fix(templates): resolve GitHub API host from env in ralph-triage.js#1438omercangumus wants to merge 1 commit into
omercangumus wants to merge 1 commit into
Conversation
ralph-triage.js hardcoded hostname: 'api.github.com' in its https.request() call, so Squad Heartbeat (Ralph) failed with a 401 on GitHub Enterprise — the GITHUB_TOKEN there is only valid against the enterprise API host, not github.com. Added resolveGithubApiBase(), which picks the API base in order: GITHUB_API_URL (set by Actions on both github.com and GHE runners), then GITHUB_SERVER_URL + /api/v3, then https://api.github.com as a last-resort fallback. The request is now built from a URL object instead of a hardcoded hostname/path pair. No behavior change on github.com-hosted repos. Fixed in the canonical .squad-templates/ralph-triage.js and synced to the 3 mirror targets. Added unit tests covering all three resolution branches. Closes bradygaster#1142 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
🟠 Impact Analysis — PR #1438Risk tier: 🟠 HIGH 📊 Summary
🎯 Risk Factors
📦 Modules Affectedroot (2 files)
squad-cli (1 file)
squad-sdk (1 file)
templates (1 file)
tests (1 file)
This report is generated automatically for every PR. See #733 for details. |
Contributor
🛫 PR Readiness Check
PR Scope: 🔧 Infrastructure
|
| Status | Check | Details |
|---|---|---|
| ✅ | Single commit | 1 commit — clean history |
| ❌ | Not in draft | PR is still in draft — mark as ready for review when done |
| ✅ | Branch up to date | Up to date with dev |
| ❌ | Copilot review | No Copilot review yet — it may still be processing |
| ✅ | Changeset present | Changeset file found |
| ✅ | Scope clean | No .squad/ or docs/proposals/ files |
| ✅ | No merge conflicts | No merge conflicts |
| ✅ | Copilot threads resolved | No Copilot review threads |
| ❌ | CI passing | 3 check(s) still running |
Files Changed (6 files, +162 −25)
| File | +/− |
|---|---|
.changeset/fix-1142-ralph-triage-ghe-api-host.md |
+10 −0 |
.squad-templates/ralph-triage.js |
+28 −6 |
packages/squad-cli/templates/ralph-triage.js |
+28 −6 |
packages/squad-sdk/templates/ralph-triage.js |
+28 −6 |
templates/ralph-triage.js |
+28 −6 |
test/ralph-triage.test.ts |
+40 −1 |
Total: +162 −25
This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ralph-triage.jsnow resolves the GitHub REST API host from the environment instead of hardcodingapi.github.com.Why
Squad Heartbeat (Ralph)fails with a 401 on GitHub Enterprise.githubRequestJson()in.squad-templates/ralph-triage.jssent every request tohostname: 'api.github.com', but on GHE theGITHUB_TOKENis only valid against the enterprise API host (https://<ghe-host>/api/v3), so calls to github.com are rejected withBad credentials.Closes #1142
How
Added a
resolveGithubApiBase()helper that picks the API base in order:GITHUB_API_URL— set automatically by Actions on both github.com and GHE runners.GITHUB_SERVER_URL+/api/v3— fallback for GHE ifGITHUB_API_URLisn't set.https://api.github.com— fallback for local/non-Actions runs.githubRequestJson()now builds the request from aURLobject (${resolveGithubApiBase()}${pathname}) instead of a hardcodedhostname/pathpair, sohttps.request()picks up the correct protocol, host, and base path automatically. No behavior change on github.com-hosted repos, sinceGITHUB_API_URLthere already resolves tohttps://api.github.com.Fixed in the canonical
.squad-templates/ralph-triage.jsand propagated vianode scripts/sync-templates.mjs --syncto the 3 mirror targets (templates/,packages/squad-cli/templates/,packages/squad-sdk/templates/), matching the parity checks intest/template-sync.test.ts.Also added a
require.main === moduleguard around the script'smain()call and exportedresolveGithubApiBaseviamodule.exports, purely so the new unit tests can import and exercise the helper without invokingmain()(which needsGITHUB_TOKENand network access). No change to the script's behavior when run directly vianode ralph-triage.js.Testing
test/ralph-triage.test.tscovering all three resolution branches plus trailing-slash normalization. Verified they fail withresolveGithubApiBase is not a functionagainst the pre-fix code and pass against the fix.npx vitest run test/ralph-triage.test.ts test/template-sync.test.ts— 284 passed.npm run build— passes.npm run lint(tsc --noEmit) — passes.npm run lint:eslint— 0 errors (pre-existing warnings only, unrelated to this change).npm test(full suite) — no regressions from this change. A number of unrelated tests fail on this Windows dev machine (EBUSY temp-dir races, timing-sensitive timeouts, a locale-dependent number-formatting assertion) — confirmed identical failures on a cleanupstream/devcheckout before my changes, so they're pre-existing local-environment flakiness, not something this PR introduces.npx changeset add-equivalent manual file:.changeset/fix-1142-ralph-triage-ghe-api-host.md(patch bump for@bradygaster/squad-cliand@bradygaster/squad-sdk, since this touches governed template paths under both packages'templates/)PR Readiness Checklist
Branch & Commit
devdevgit diff --cached --stat)Build & Test
npm run buildpassesnpm testpasses (all tests relevant to this change; see testing notes above for pre-existing unrelated local failures)npm run lintpasses (type check clean)npm run lint:eslintpasses (0 errors)Changeset
Docs
Exports
Breaking Changes
None.
Waivers
None.