Skip to content

feat: add github enterprise hostname parsing to wt switch logic - #1408

Merged
max-sixty merged 2 commits into
max-sixty:mainfrom
TomRomeo:feat/other-github-hosts
Mar 11, 2026
Merged

max-sixty merged 2 commits into
max-sixty:mainfrom
TomRomeo:feat/other-github-hosts

Conversation

@TomRomeo

@TomRomeo TomRomeo commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix wt switch pr:<number> for repositories hosted on GitHub Enterprise (or other non-github.com hosts) by passing --hostname to the gh CLI
  • Extract the hostname from the repository's primary remote URL using the existing GitRemoteUrl::parse() utility, falling back to github.com if the URL can't be parsed

Problem

When checking out a PR in a repository hosted on a GitHub Enterprise instance (e.g., github.example.com), the gh api call in fetch_pr_info did not specify which host to authenticate against. The gh CLI defaults to github.com, so PR checkout silently failed for any other GitHub host.
The gh api command accepts a --hostname flag to target a specific GitHub host, but it was not being used.

Solution

This PR extracts the hostname from the repository's configured remote URL and passes it to gh api --hostname. The extraction is best-effort so if the remote URL can't be parsed for any reason, it falls back to "github.com", preserving the existing behavior.
The hostname parsing reuses the existing GitRemoteUrl::parse() to support all remote URL formats (https://, ssh://, git@, git://, http://).

Notes

I'm not that experienced in Rust, so I'm happy to implement any PR feedback and add tests if necessary.

@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.

Nice fix — GHE users would silently get 404s or auth errors without --hostname. The implementation reuses existing APIs well.

One suggestion to avoid recreating a Repository that already exists at the call site, and a note about GitLab parity.

Comment thread src/git/remote_ref/github.rs Resolved
Comment thread src/git/remote_ref/github.rs Resolved
@max-sixty

Copy link
Copy Markdown
Owner

thanks @TomRomeo , looks good!

@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot :

  • can you confirm where else this should be added? presumably we also need it in CI status etc?
  • can you confirm that this doesn't happen by default? give the PR, I guess not; but it does sound like something gh should be doing itself...

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Investigated both questions:

Where else should --hostname be added?

There's one more gh api call that needs it: detect_github_commit_checks in ci_status/github.rs — this queries check-runs for a commit SHA and would fail against GHE without --hostname.

The other GitHub calls are fine:

  • gh pr list in detect_github — this is a "repo-aware" command that auto-detects the host from git remote when current_dir is set. No --hostname needed.
  • gh auth status in CiToolsStatus::detect — called without repo context for a quick availability check. Could be improved for GHE but it's a separate concern (the GitLab side already passes --hostname here).
  • gh config get git_protocol — general config, not host-specific.

So the actionable gap is detect_github_commit_checks. That could be a follow-up.

Does gh handle this by default?

No — but only for gh api. The gh CLI has two categories of commands:

  • Repo-aware commands (gh pr list, gh pr view, gh pr checks) — these read .git/config to determine the host. They work correctly on GHE without --hostname.
  • gh api — this is a raw API command that defaults to github.com. It requires --hostname (or GH_HOST env var) to target a different host.

So the PR is correct that gh api needs explicit hostname routing. The gh team considers this intentional — gh api is a low-level escape hatch where the user (or caller) is responsible for specifying the target host.


I've also pushed a commit for the refactor requested in the review thread — passing &Repository through the trait instead of recreating it from the path. Details in the review thread reply.

worktrunk-bot added a commit that referenced this pull request Mar 9, 2026
The bot pushed a branch to upstream before realizing PR #1408 was from
a fork, then had to delete it. Add guidance to check headRepositoryOwner
before pushing, and avoid referencing SHAs from deleted branches.

Closes #1411

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot please respond to the comments above

(for others: still working through why it seems to work for comments but not inline comments: #1426)

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Responded to both inline threads:

  1. Refactor (pass &Repository through trait) — Implemented the change and made it available as commit d9992a43 for @TomRomeo to cherry-pick. I don't have push access to the fork, so I couldn't push directly to the PR branch. The refactor removes the redundant Repository::at() construction by threading the existing &Repository through fetch_info.

  2. GitLab parity — Confirmed @TomRomeo's finding: glab api already auto-detects the hostname from the current git directory (unlike gh api which defaults to github.com). No change needed for the GitLab provider.

@max-sixty
max-sixty merged commit 40810fe into max-sixty:main Mar 11, 2026
23 checks passed
@max-sixty

Copy link
Copy Markdown
Owner

thanks @TomRomeo !

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