Skip to content

Simplify forge detection with [forge] config section - #1826

Merged
max-sixty merged 8 commits into
mainfrom
fix/ci-hostname-config
Mar 31, 2026
Merged

max-sixty merged 8 commits into
mainfrom
fix/ci-hostname-config

Conversation

@max-sixty

@max-sixty max-sixty commented Mar 31, 2026 •

Copy link
Copy Markdown
Owner

SSH host aliases (git@work-ssh:owner/repo) corrupt the hostname in remote URLs but never the path. The previous forge detection code tried to work around this by searching all remotes, auto-detecting GHE hostnames, and maintaining multiple resolution strategies. This PR replaces all of that with a simpler design: derive owner/repo from URL paths, and let users set forge.platform / forge.hostname for corner cases.

Key changes

New [forge] config section with platform and hostname fields. ci.platform is deprecated with migration support. Example configs and inline help examples updated.

fetch_pr_info now builds literal API paths from the primary remote's raw URL instead of relying on gh's placeholder resolution. --hostname only passed when explicitly configured.

platform_for_repo checks config > branch's remote > primary remote. No longer searches all remotes. Loads config internally instead of taking a platform_override parameter.

find_remote matches by owner/repo only (no host required), handling SSH aliases where the local hostname differs from the API hostname.

CiBranchName::from_branch_ref uses split_once('/') instead of iterating all_remote_urls(), removing a git call per branch during wt list.

Deleted

  • resolve_gh_hostname (GHE auto-detection heuristic)
  • find_forge_remote (search all remotes by predicate)
  • all_remote_urls() loop in branch name parsing
  • platform_override parameter threading through callers

The spec in src/git/repository/remotes.rs documents the full design.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 6 commits March 30, 2026 13:39
Replace the hostname-centric forge detection spec with a design that
derives owner/repo from URL paths instead of hostnames. This fixes
SSH host alias setups (e.g., github-personal) without requiring
url.insteadOf.

Key design changes:
- Only pass --hostname to gh/glab when forge.hostname is configured
- Match remotes by owner/repo, with host as disambiguator only
- New [forge] config section (platform + hostname), deprecating ci.platform
- Document SSH alias behavior matrix (what works vs. needs config)

Co-Authored-By: Claude <[email protected]>
Stop deriving API hostname from remote URLs — SSH host aliases corrupt
the host but never the path. Extract owner/repo from the raw remote URL
and build literal API paths. Only pass --hostname to gh when
forge.hostname is explicitly configured.

- Add [forge] config section with platform and hostname fields
- forge.platform falls back to ci.platform (deprecated) for compat
- fetch_pr_info: literal repos/{owner}/{repo}/pulls/{n} path, no
  --hostname unless forge.hostname configured
- github_owner_repo: extract directly from primary remote
- detect_github_commit_checks: config-only --hostname
- find_remote_for_repo callers: pass None for host (owner/repo match)
- resolve_same_repo_ref: match by owner/repo, not host
- [ci] → [forge] deprecation with migration support
- Fix config show duplicate warnings for deprecated section keys

Closes #1790

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/commands/worktree/switch.rs
Platform detection now checks the primary remote's effective URL instead
of searching all remotes. Users with opaque SSH aliases use
`forge.platform` config.

Co-Authored-By: Claude <[email protected]>
`platform_for_repo` now loads config internally instead of taking a
`platform_override` parameter — callers no longer pre-extract it.

`from_branch_ref` uses `split_once('/')` instead of iterating
`all_remote_urls()`, removing the `repo` parameter and a git call per
branch.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Mar 31, 2026

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

codecov/patch failed — several new lines in the deprecation module lack test coverage.

Actionable gaps (new code from this PR):

  • src/config/deprecation.rs: find_ci_section_deprecation and migrate_ci_to_forge have untested edge-case branches (parse failure, [forge] already exists, no platform value). The format_deprecation_warnings path for ci_section: true is also uncovered.
  • src/commands/list/ci_status/github.rs lines 18–22: rewritten github_owner_repo using primary remote (hard to test without gh CLI).
  • src/git/remote_ref/github.rs and github.rs: the --hostname extension paths for forge.hostname config.

The deprecation unit tests are the most straightforward to add — happy path is tested via integration snapshots, but the edge-case branches need direct unit tests. I can push a commit adding those tests if you'd like.

@worktrunk-bot
worktrunk-bot dismissed their stale review March 31, 2026 02:46

codecov/patch failed — new deprecation code needs test coverage

max-sixty and others added 2 commits March 30, 2026 19:58
The example in `wt config --help` still showed the old `[ci]` section.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit b33cc8e into main Mar 31, 2026
21 of 22 checks passed
@max-sixty
max-sixty deleted the fix/ci-hostname-config branch March 31, 2026 04:10
worktrunk-bot added a commit that referenced this pull request Apr 1, 2026
Convert intra-doc links that reference binary crate paths
(platform_for_repo, github_owner_repo) and unresolvable associated
methods (find_remote_for_repo) to plain code references. These links
were introduced in #1826 and fail `cargo doc` because the targets are
either in the binary crate or not resolvable from module-level docs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot added a commit that referenced this pull request Apr 1, 2026
The existing `cargo doc --no-deps` check missed broken links in #1826
because most items in this binary crate are `pub(crate)`. Adding
`--document-private-items` ensures all intra-doc links are validated.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
max-sixty added a commit that referenced this pull request Apr 1, 2026
SSH host aliases (`git@work-ssh:owner/repo`) corrupt the hostname in
remote URLs but never the path. The previous forge detection code tried
to work around this by searching all remotes, auto-detecting GHE
hostnames, and maintaining multiple resolution strategies. This PR
replaces all of that with a simpler design: derive owner/repo from URL
paths, and let users set `forge.platform` / `forge.hostname` for corner
cases.

## Key changes

**New `[forge]` config section** with `platform` and `hostname` fields.
`ci.platform` is deprecated with migration support. Example configs and
inline help examples updated.

**`fetch_pr_info`** now builds literal API paths from the primary
remote's raw URL instead of relying on `gh`'s placeholder resolution.
`--hostname` only passed when explicitly configured.

**`platform_for_repo`** checks config > branch's remote > primary
remote. No longer searches all remotes. Loads config internally instead
of taking a `platform_override` parameter.

**`find_remote`** matches by owner/repo only (no host required),
handling SSH aliases where the local hostname differs from the API
hostname.

**`CiBranchName::from_branch_ref`** uses `split_once('/')` instead of
iterating `all_remote_urls()`, removing a git call per branch during `wt
list`.

## Deleted

- `resolve_gh_hostname` (GHE auto-detection heuristic)
- `find_forge_remote` (search all remotes by predicate)
- `all_remote_urls()` loop in branch name parsing
- `platform_override` parameter threading through callers

The spec in `src/git/repository/remotes.rs` documents the full design.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude <[email protected]>
max-sixty added a commit to mikeyroush/worktrunk that referenced this pull request May 11, 2026
Adds Azure DevOps as a third forge alongside GitHub and GitLab:

- `wt switch pr:N` dispatches to GitHub or Azure DevOps automatically based on
  the repo's configured remotes (GitHub still wins in mixed-remote setups).
- `wt list --full` surfaces Azure DevOps PR and pipeline status via the `az` CLI.
- `forge.platform` accepts `azure-devops` as an override.
- `wt config show --full` reports `az` install/auth state when the platform is
  detected as Azure DevOps.

Implementation notes:
- New `AzureDevOpsProvider` implements `RemoteRefProvider`; auto-detects the
  organisation from any Azure DevOps remote URL so contributors don't have to
  pass `--org`.
- `GitRemoteUrl` learns `is_azure_devops()`, `azure_organization()`, and
  `azure_project()` to parse `dev.azure.com`, `ssh.dev.azure.com`, and legacy
  `*.visualstudio.com` URLs (which don't fit the standard host/owner/repo shape).
- Pipeline URLs are constructed from org/project/build ID rather than the API's
  `url` field (which is a REST endpoint, not a browser URL).
- Requires the `azure-devops` extension (`az extension add --name azure-devops`).

Originally proposed by @mikeyroush in max-sixty#1256; reimplemented against current `main`
to pick up the `[forge]` config section (max-sixty#1826), `url.insteadOf` fallback (max-sixty#1771),
and `handle_switch` consolidation (max-sixty#2597) that landed after the original branch.

Co-Authored-By: mroush <[email protected]>
Co-Authored-By: Claude <[email protected]>
max-sixty pushed a commit that referenced this pull request Nov 5, 2026
… is logged in to it (#4710)

`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

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.

2 participants