Skip to content

fix(switch): use a GitHub PR URL's host for gh api - #4722

Merged
max-sixty merged 2 commits into
max-sixty:mainfrom
anqorithm:abdallah/pr-url-host
Nov 7, 2026
Merged

max-sixty merged 2 commits into
max-sixty:mainfrom
anqorithm:abdallah/pr-url-host

Conversation

@anqorithm

Copy link
Copy Markdown
Contributor

wt switch https://host/owner/repo/pull/N asked gh api with no --hostname, so the lookup went to gh's default host. An Enterprise URL then 404'd when the git remote was github.com, even though gh was logged in on the URL's host.

When forge.hostname is unset, the /pull/N URL's host is now passed as --hostname if gh auth token succeeds for it. pr:N still follows the remote, and the 404 hint is unchanged.

Checked with the new switch cases (logged in and not), the existing enterprise-remote regression, the URL-host unit test, cargo test --doc, and cargo clippy --all-targets --all-features -- -D warnings.

Refs #4709

wt switch on a GitHub /pull/N URL asked gh's default host. An
Enterprise URL against a github.com remote then 404'd even when gh
was logged into the URL's host.

A configured forge.hostname still wins. Otherwise that URL host is
passed as gh api --hostname when gh has a login there, then the
GitHub remote's host. pr:N is unchanged.

Refs max-sixty#4709

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new integration test copies test_switch_pr_enterprise_remote_passes_hostname almost line for line, and its github.com-remote setup isn't the case where the URL host matters most. Details are inline, along with a small fix where a code comment overstates the precedence.

Comment thread tests/integration_tests/switch.rs Resolved
Comment thread src/git/remote_ref/github.rs Resolved
…mote

The URL-host test repeated the enterprise-remote test; both are now
cases of one test. The URL cases use an SSH-alias origin
(git@github-work:…) so the authed case passes only when the URL host
is tried before the remote host.

Only a GitHub /pull/N URL carries a host; mr:N now passes None. The
precedence comment says the URL host wins only when it isn't
github.com.
@max-sixty
max-sixty merged commit c45a2f6 into max-sixty:main Nov 7, 2026
39 checks passed
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants