Skip to content

Replace gh pr checkout with git fetch refs/pull to avoid GH_HOST issues#26136

Merged
dsyme merged 1 commit intomainfrom
fix/replace-gh-pr-checkout-with-git-ops
Apr 14, 2026
Merged

Replace gh pr checkout with git fetch refs/pull to avoid GH_HOST issues#26136
dsyme merged 1 commit intomainfrom
fix/replace-gh-pr-checkout-with-git-ops

Conversation

@dsyme
Copy link
Copy Markdown
Collaborator

@dsyme dsyme commented Apr 14, 2026

Summary

Replaces gh pr checkout with pure git operations for PR checkout in checkout_pr_branch.cjs, eliminating the dependency on GH_HOST and avoiding DIFC proxy conflicts.

Problem

When the DIFC proxy is active, it sets GH_HOST=localhost:18443 which causes gh pr checkout to fail because the proxy address doesn't match any git remote. The previous fix (getGhEnvBypassingIntegrityFilteringForGitOps) worked around this by overriding GH_HOST per-call, but this is fragile and requires maintenance.

Solution

Use git fetch origin +refs/pull/N/head:refs/remotes/origin/pr-head followed by git checkout -B {branch} origin/pr-head instead of gh pr checkout. Git operations use remote URLs directly and are completely unaffected by GH_HOST.

GitHub exposes refs/pull/N/head for all PRs, including fork PRs, so this works universally.

Changes

  • checkout_pr_branch.cjs: Replace gh pr checkout with git fetch refs/pull/N/head + git checkout -B. Fetches the correct depth upfront via the API (no separate history-deepening step needed). Remove git_helpers.cjs import.
  • git_helpers.cjs: Remove getGitHubHost() and getGhEnvBypassingIntegrityFilteringForGitOps() — no consumers remain.
  • checkout_pr_branch.test.cjs: Update all 47 tests to validate the new git-based checkout flow rather than gh pr checkout. Remove the GH_HOST override test group.

Testing

All 47 checkout tests + 19 git_helpers tests pass.

… issues

Replace `gh pr checkout` with pure git operations (`git fetch origin
+refs/pull/N/head` + `git checkout -B`) for PR checkout in non-fork
pull_request_target, issue_comment, and other PR event handlers.

GitHub exposes refs/pull/N/head for all PRs including forks, so this
works universally. Git operations use remote URLs directly and are
unaffected by GH_HOST overrides from the DIFC proxy, eliminating the
need for the getGhEnvBypassingIntegrityFilteringForGitOps helper.

Also removes the now-unused getGitHubHost() and
getGhEnvBypassingIntegrityFilteringForGitOps() from git_helpers.cjs.
Copilot AI review requested due to automatic review settings April 14, 2026 01:19
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

This PR removes reliance on gh pr checkout for checking out pull request branches and replaces it with a pure-git flow (git fetch origin +refs/pull/N/head:... + git checkout -B ...), avoiding failures caused by GH_HOST overrides (e.g., DIFC proxy).

Changes:

  • Replace gh pr checkout with git fetch origin +refs/pull/N/head and git checkout -B in checkout_pr_branch.cjs.
  • Remove now-unused GH_HOST/host-derivation helpers from git_helpers.cjs.
  • Update the checkout test suite to assert the new git-based behavior and drop GH_HOST-override coverage.
Show a summary per file
File Description
actions/setup/js/checkout_pr_branch.cjs Switch checkout strategy from gh CLI to fetching refs/pull/N/head and checking out a local branch from the fetched ref.
actions/setup/js/git_helpers.cjs Remove GH_HOST/GHE host derivation helpers that no longer have consumers.
actions/setup/js/checkout_pr_branch.test.cjs Update tests to validate the new fetch-by-ref checkout flow and remove GH_HOST override expectations.

Copilot's findings

Tip

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

Comments suppressed due to low confidence (2)

actions/setup/js/checkout_pr_branch.cjs:180

  • The else-branch now always calls the GitHub API (fetchPRDetails) to get commitCount and headRef, even when the event payload already contains pullRequest.commits and pullRequest.head.ref (e.g. pull_request_target, pull_request fork payloads). This adds avoidable latency and increases the chance of rate-limit / transient API failures. Prefer using the payload values when present, only falling back to the API when the data is missing (like issue_comment).
      // Get PR details from API to determine head ref name and commit count
      const { commitCount, headRef } = await fetchPRDetails(prNumber);
      const fetchDepth = (commitCount || 1) + 1; // +1 to include the merge base

actions/setup/js/checkout_pr_branch.cjs:187

  • git checkout -B ${branchName} origin/pr-head force-resets/overwrites any existing local branch with the same name. On persistent workspaces (e.g. self-hosted runners or scripts re-run in the same directory) this can clobber local state unexpectedly. Consider always checking out to a unique, namespaced branch (e.g. pr-${prNumber}) and/or avoiding -B unless you explicitly want to reset an existing branch.
      const branchName = headRef || `pr-${prNumber}`;
      core.info(`Checking out branch: ${branchName}`);
      await exec.exec("git", ["checkout", "-B", branchName, "origin/pr-head"]);
  • Files reviewed: 3/3 changed files
  • Comments generated: 2

@dsyme dsyme force-pushed the fix/replace-gh-pr-checkout-with-git-ops branch from dbf0eb0 to f2b0140 Compare April 14, 2026 01:55
@dsyme dsyme merged commit 436a0b9 into main Apr 14, 2026
146 of 148 checks passed
@dsyme dsyme deleted the fix/replace-gh-pr-checkout-with-git-ops branch April 14, 2026 01:57
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