Skip to content

fix(switch): pass a GitHub Enterprise remote's host to gh api when gh is logged in to it - #4710

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-4709
Nov 5, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-4709

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

gh api doesn't take its host from the repository. Without --hostname it uses gh's default host, which is github.com once more than one host is logged in. fetch_pr_info passed --hostname only when forge.hostname was set, so on a GitHub Enterprise remote wt switch pr:N and wt switch <PR URL> asked github.com for the PR and got a 404. With no forge.hostname, the lookup now passes the GitHub remote's host as --hostname if gh auth token --hostname <host> succeeds (a local check, no network; choose_pr_forge already uses the same check). An SSH alias such as github-personal has no gh login, so it still goes to gh's default host. That keeps the #1790 fix in place, the one #1826 made by removing host detection. A configured forge.hostname still takes priority. github.com remotes skip the check, so they behave as before.

test_switch_pr_enterprise_remote_passes_hostname uses an https://github.example.com/... remote and a mock gh. When gh is logged in to that host, the test expects --hostname github.example.com on the api call; it failed before this change and passes now. When gh isn't logged in to it, the test expects no --hostname flag. The existing pr integration tests pass.

Not changed here: the issue's second suggestion, a 404 hint that names forge.hostname. That case still applies when gh has no login for the Enterprise host. Whether to add that output is up to a maintainer. A PR URL's own host is also not used yet. In the reported setup the remote's host matches the URL's, so this change fixes that case.

Refs #4709 — automated triage

… is logged in to it

Without forge.hostname, `gh api` sends the PR lookup to gh's default
host, which is github.com once several hosts are logged in, so pr:N and
PR URLs 404 on GitHub Enterprise. Use the GitHub remote's host when
`gh auth token --hostname` reports a login for it; an SSH alias has
none, so it keeps gh's default (#1790).

Refs #4709
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Nov 5, 2026
@max-sixty
max-sixty merged commit 79f19f6 into main Nov 5, 2026
36 of 45 checks passed
@max-sixty
max-sixty deleted the fix/issue-4709 branch November 5, 2026 08:57
max-sixty pushed a commit that referenced this pull request Nov 21, 2026
When a GitHub Enterprise PR lookup has no selected API hostname, a 404
only points at `gh repo set-default`. That can already be correct even
though `gh api` used its default host.

For a 404 on an explicit Enterprise PR URL, when no API host was
selected, the hint names the host for `gh auth login` and points to
`forge.hostname` if the API host differs. Short PR references keep the
ordinary 404 hint because a Git remote can use an SSH alias. Host
selection itself stays as in #4710 and #4722.

Checked with the 107 switch PR integration tests, including the new URL,
remote, and configured-host cases, and with rustfmt,
all-target/all-feature Clippy, doctests, and documentation generation.
The full pre-merge hook could not complete locally because `pre-commit`
and `cargo insta` were unavailable. The tests use a stub `gh` and do not
require an Enterprise account.

Refs #4709

AI assistance was used for the patch and tests.

Review follow-up: the SSH alias and missing-login cases reproduced
against the previous head. All 104 matching switch integration tests,
all-target/all-feature Clippy, rustfmt, documentation generation, and
doctests passed. The full local pre-merge hook still lacks `pre-commit`
and `cargo insta`.

---------

Co-authored-by: xunguangzlj-cloud <[email protected]>
Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants