Skip to content

Fix gh pr checkout failing with GH_HOST mismatch in issue_comment workflows#26037

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-gh-host-issue
Draft

Fix gh pr checkout failing with GH_HOST mismatch in issue_comment workflows#26037
Copilot wants to merge 3 commits intomainfrom
copilot/fix-gh-host-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

When the DIFC proxy is active, start_difc_proxy.sh sets GH_HOST=localhost:18443 in GITHUB_ENV. The Checkout PR branch step runs before stop_difc_proxy.sh, so gh pr checkout fails because GH_HOST=localhost:18443 doesn't match any git remote (origin points to github.com or a GHE host).

Changes

  • checkout_pr_branch.cjs: Derive GH_HOST from GITHUB_SERVER_URL and pass it as an explicit env override when invoking gh pr checkout, bypassing any stale or proxy-overridden value:

    const serverUrl = process.env.GITHUB_SERVER_URL || "https://github.com";
    const ghHost = serverUrl.replace(/^https?:\/\/|\/+$/g, "");
    await exec.exec("gh", ["pr", "checkout", prNumber.toString()], {
      env: { ...process.env, GH_HOST: ghHost },
    });

    Covers all cases: github.com, GHES (myorg.ghe.com), and DIFC proxy active (overrides localhost:18443).

  • checkout_pr_branch.test.cjs: Updated all gh pr checkout call expectations to assert the env override is present; added GITHUB_SERVER_URL to beforeEach/afterEach; added 4 new tests covering DIFC proxy override, GHES host, protocol stripping, and missing-env fallback.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid.example.invalid
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git conf�� user.name lure tions/setup/js/node_modules/.bin/git -M main /usr/sbin/git git init�� --bare --initial-branch=main k/gh-aw/gh-aw/actions/setup/js/node_modules/.bin/git '/tmp/bare-incregit '/tmp/bare-increadd cal/bin/git git (dns block)
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git comm�� -m lure test commit k/node_modules/.bin/git -b main ode-gyp-bin/git git conf�� user.email test@test.com /git -b feature-branch it git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits April 13, 2026 13:56
…ERVER_URL

When the DIFC proxy is active, start_difc_proxy.sh sets GH_HOST=localhost:18443
in GITHUB_ENV. This causes `gh pr checkout` to fail because GH_HOST doesn't
match any git remote (origin points to github.com or a GHE host).

Fix: derive the correct GH_HOST from GITHUB_SERVER_URL and pass it as an env
override when calling `exec.exec("gh", ["pr", "checkout", ...])`. This ensures:
- DIFC proxy's localhost:18443 GH_HOST is overridden with the real GitHub host
- GHES hosts correctly use their actual hostname
- github.com uses github.com

Also adds new tests for the GH_HOST override behavior and updates existing
test expectations to match the new 3-argument exec.exec call.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/55bc2334-76f1-49a8-9009-1219a7a6cf87

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with gh pr checkout for forked PRs Fix gh pr checkout failing with GH_HOST mismatch in issue_comment workflows Apr 13, 2026
Copilot AI requested a review from dsyme April 13, 2026 14:00
@github-actions github-actions bot added the lgtm label Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey @Copilot 👋 — great work fixing the gh pr checkout GH_HOST mismatch with the DIFC proxy! This is a well-crafted bug fix that follows all the right patterns.

The change is tightly scoped to checkout_pr_branch.cjs and its test counterpart, the root cause is clearly explained in both the PR body and inline comments, and the fix is correct: deriving GH_HOST from the reliable GITHUB_SERVER_URL env var rather than letting a stale proxy-set value leak through. The test suite is thorough — 4 new dedicated test cases plus updated expectations across existing tests covering issue_comment, pull_request_target, GHES, DIFC proxy override, and missing-env fallback.

This PR looks ready for maintainer review. 🚀

Generated by Contribution Check · ● 2.6M ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants