Repository navigation
fix(switch): pass a GitHub Enterprise remote's host to gh api when gh is logged in to it - #4710
Merged
Merged
Conversation
… 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
This was referenced Nov 6, 2026
1 task
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]>
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.
gh apidoesn't take its host from the repository. Without--hostnameit uses gh's default host, which is github.com once more than one host is logged in.fetch_pr_infopassed--hostnameonly whenforge.hostnamewas set, so on a GitHub Enterprise remotewt switch pr:Nandwt switch <PR URL>asked github.com for the PR and got a 404. With noforge.hostname, the lookup now passes the GitHub remote's host as--hostnameifgh auth token --hostname <host>succeeds (a local check, no network;choose_pr_forgealready uses the same check). An SSH alias such asgithub-personalhas 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 configuredforge.hostnamestill takes priority. github.com remotes skip the check, so they behave as before.test_switch_pr_enterprise_remote_passes_hostnameuses anhttps://github.example.com/...remote and a mockgh. Whenghis logged in to that host, the test expects--hostname github.example.comon theapicall; it failed before this change and passes now. Whenghisn't logged in to it, the test expects no--hostnameflag. The existingprintegration tests pass.Not changed here: the issue's second suggestion, a 404 hint that names
forge.hostname. That case still applies whenghhas 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