worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

GitHub Enterprise: `wt switch <PR URL>` ignores the URL's host, and the 404 hint points at `gh repo set-default` instead of `forge.hostname`

Open pgilad-rna opened this issue 4 weeks ago • 5 comments

Problem

On a GitHub Enterprise host, wt switch pr:N and wt switch <PR URL> fail with a 404 unless forge.hostname is configured. The error hint points at gh repo set-default, which is already correct, so the cause is hard to find.

Setup

  • worktrunk 0.81.0 (Homebrew), gh 2.103.3, macOS
  • Remote: https://github.example.com/acme/app
  • gh is logged in to both github.com and github.example.com
  • gh repo set-default --view → acme/app
  • No [forge] block in the repo, no [projects."github.example.com/*"] entry in user config

What happens

$ wt switch https://github.example.com/acme/app/pull/62
◎ Fetching PR #62...
✗ PR #62 not found on acme/app (gh default). Check that `gh repo set-default` points to the correct repository.
  gh: Not Found (HTTP 404)

A gh wrapper on PATH shows the calls:

gh repo set-default --view
gh api repos/acme/app/pulls/62

There is no --hostname, so gh api sends the request to github.com. gh pr view 62 in the same checkout works, because gh pr resolves the host from the remote.

This matches the current code: fetch_pr_info in src/git/remote_ref/github.rs passes --hostname only when forge.hostname is configured. #1826 made that change on purpose to fix SSH aliases (#1790), and it removed the host detection that #1408 added.

Workaround

# ~/.config/worktrunk/config.toml
[projects."github.example.com/*"]
forge.platform = "github"
forge.hostname = "github.example.com"

With this, wt runs gh api repos/acme/app/pulls/62 --hostname github.example.com, and the same call with that host returns the PR.

Suggestions

  1. Use the PR URL's host. When the argument is a PR URL (#2896), the user has already named the host. If forge.hostname is unset, pass the URL's host as --hostname. A web URL carries the real host, not an SSH alias, so this does not bring back #1790.
  2. Point the 404 hint at forge.hostname. When forge.hostname is unset and the remote's host is not github.com, the hint could name forge.hostname (and the [projects."<host>/*"] user-config form) as a likely cause, next to the gh repo set-default hint. Here the hint sent me to gh repo set-default, which was already correct.

Opened by claude-opus-5-5 on behalf of @pgilad-rna

pgilad-rna avatar Nov 05 '26 08:11 pgilad-rna

I opened #4710 to fix the main failure. With no forge.hostname, the PR lookup now passes the GitHub remote's host as --hostname when gh auth token --hostname <host> shows gh is logged in to it. In your setup, wt switch pr:62 and the PR URL should then call gh api repos/acme/app/pulls/62 --hostname github.example.com with no config change. An SSH alias like github-personal has no gh login, so it still goes to gh's default host, and the #1790 fix stays intact. A regression test covers both cases. CI and maintainer review are still pending.

The PR leaves two parts of your report open:

  • The 404 hint. It could name forge.hostname, which would still help when gh isn't logged in to the Enterprise host. That hint is new user-facing output, so I've left it for a maintainer to decide.
  • The PR URL's host. The lookup doesn't use it yet. Your remote's host and the URL's host are the same, so #4710 already covers your case.

Until #4710 merges, your [projects."github.example.com/*"] workaround is the right setting.

worktrunk-bot avatar Nov 05 '26 08:11 worktrunk-bot

#4710 has merged as 79f19f640. With no forge.hostname set, wt switch pr:N and the PR URL form now pass the GitHub Enterprise remote's host to gh api whenever gh is logged in to that host. That covers your setup, and it ships in the next release after v0.81.0. Until that release, keep the [projects."github.example.com/*"] workaround.

The 404 hint naming forge.hostname, and using the PR URL's own host, are still open here.

worktrunk-bot avatar Nov 06 '26 06:11 worktrunk-bot

Opened https://github.com/max-sixty/worktrunk/pull/4722 for the URL-host part: a GitHub /pull/N URL now supplies gh api --hostname when gh is logged in there. The 404 hint is unchanged.

anqorithm avatar Nov 06 '26 22:11 anqorithm

Both suggestions in this issue have now merged:

  1. PR URL host — #4722 (in v0.82.0): wt switch <GitHub PR URL> passes the URL's host to gh api --hostname when gh is logged in there.
  2. 404 hint — #4734 (merged after v0.83.0, so it ships in the next release): a 404 on an Enterprise PR URL with no API host selected names the host for gh auth login and points at forge.hostname when the API host differs, instead of only gh repo set-default.

Together with #4710 (remote host passed when gh is logged in to it), that covers the setup described here. I'm leaving the issue open for a maintainer to close.

worktrunk-bot avatar Nov 27 '26 06:11 worktrunk-bot

Closing: all three parts of this report are on main — #4710 (remote host passed to gh api --hostname), #4722 (PR URL host, released in v0.82.0) and #4734 (404 hint pointing at forge.hostname, ships in the release after v0.83.0). If something in your setup still fails after upgrading, let us know and we'll reopen.

worktrunk-bot avatar Nov 29 '26 09:11 worktrunk-bot