Skip to content

fix: auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used#1453

Merged
lpcox merged 2 commits intomainfrom
copilot/fix-gh-host-auto-injection
Mar 26, 2026
Merged

fix: auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used#1453
lpcox merged 2 commits intomainfrom
copilot/fix-gh-host-auto-injection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

GH_HOST auto-injection from GITHUB_SERVER_URL was skipped when --env-all was active because the logic lived inside the else branch. Since gh-aw always passes --env-all, GH_HOST was never derived, causing gh CLI inside the container to default to github.com on GHES/GHEC runners.

Changes

  • src/docker-manager.ts: Moved GH_HOST auto-injection after the if/else block so it runs in both the envAll and selective pass-through paths. Added a !environment.GH_HOST guard so an explicit GH_HOST already forwarded via --env-all is not overwritten.
// Before: inside the else branch — never ran with --env-all
} else {
  // ...
  const ghHost = extractGhHostFromServerUrl(process.env.GITHUB_SERVER_URL);
  if (ghHost) {
    environment.GH_HOST = ghHost;
  }
}

// After: runs unconditionally, preserves explicit value
const ghHost = extractGhHostFromServerUrl(process.env.GITHUB_SERVER_URL);
if (ghHost && !environment.GH_HOST) {
  environment.GH_HOST = ghHost;
}
  • src/docker-manager.test.ts: Added two unit tests covering the new behaviour:
    • envAll: true + GITHUB_SERVER_URL set (no GH_HOST) → auto-injects correctly
    • envAll: true + both GITHUB_SERVER_URL and explicit GH_HOST set → explicit value is preserved

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] Fix auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used fix: auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used Mar 26, 2026
Copilot AI requested a review from lpcox March 26, 2026 16:06
@github-actions
Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 82.66% 82.83% 📈 +0.17%
Statements 82.32% 82.49% 📈 +0.17%
Functions 81.44% 81.44% ➡️ +0.00%
Branches 75.97% 76.11% 📈 +0.14%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 85.4% → 86.1% (+0.72%) 84.9% → 85.6% (+0.70%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Copy Markdown
Contributor

🔮 Oracle smoke report
Merged PR titles: fix: allow host service ports for GitHub Actions services containers | fix: allow host gateway traffic for localhost/Playwright
CLI query PR titles: fix: auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used | fix: add picomatch overrides for GHSA-c2c7-rcm5-vvqj
GitHub MCP merged PR review ✅ | safeinputs-gh PR query ❌ | Playwright title check ✅ | Tavily search ❌
File write/read ✅ | Bash cat verify ✅ | Discussion query/comment ❌ | npm ci && npm run build ✅
Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "registry.npmjs.org"

See Network Configuration for more information.

@lpcox lpcox marked this pull request as ready for review March 26, 2026 17:25
@lpcox lpcox requested a review from Mossaka as a code owner March 26, 2026 17:25
Copilot AI review requested due to automatic review settings March 26, 2026 17:25
@lpcox lpcox merged commit 159dc5e into main Mar 26, 2026
60 checks passed
@lpcox lpcox deleted the copilot/fix-gh-host-auto-injection branch March 26, 2026 17:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes missing GH_HOST derivation when --env-all is enabled so the gh CLI inside the agent container targets the correct GitHub host on GHES/GHEC runners.

Changes:

  • Move GH_HOST auto-injection logic to run after the envAll/selective env pass-through split, so it executes in both paths.
  • Add a guard to avoid overwriting an explicitly provided GH_HOST when it is already present.
  • Add unit tests to cover envAll: true behavior for both injection and non-overwrite cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/docker-manager.ts Ensures GH_HOST is derived from GITHUB_SERVER_URL even when --env-all is used, without clobbering an explicit GH_HOST.
src/docker-manager.test.ts Adds tests validating auto-injection under envAll: true and preservation of an explicit GH_HOST.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

fix: auto-inject GH_HOST from GITHUB_SERVER_URL when --env-all is used

3 participants