Files
orca/src/shared/git-remote-host-alias.ts
T
780ab3d71d fix(bitbucket): canonicalize ssh.bitbucket.org remotes in review links and Gitea detection (#30808)
Fold every forge SSH host alias (ssh.github.com, altssh.gitlab.com,
ssh.bitbucket.org) through one shared normalizeForgeWebHost so main-process
provider detection and renderer manual review links agree. Remotes on
ssh.bitbucket.org now open bitbucket.org pull request forms instead of
ssh.bitbucket.org URLs, and Gitea no longer claims the host.

Co-authored-by: Eric Junker <4758+ejunker@users.noreply.github.com>
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-10-28 01:57:10 -07:00

47 lines
2.0 KiB
TypeScript

// Fold SSH-over-443/www aliases when comparing probed remotes with pasted URLs.
function normalizeRemoteHost(host: string): string {
return host.trim().toLowerCase()
}
/** Fold www only for URL/remote comparison; forge identity normalizers feed persisted project keys and would re-key them on upgrade. */
export function foldWwwHostAlias(host: string): string {
return normalizeRemoteHost(host).replace(/^www\./, '')
}
export function normalizeGitHubRemoteHost(host: string): string {
const normalizedHost = normalizeRemoteHost(host)
// Why: GitHub documents ssh.github.com as SSH-over-HTTPS for github.com repos.
return normalizedHost === 'ssh.github.com' ? 'github.com' : normalizedHost
}
export function normalizeGitLabRemoteHost(host: string): string {
const normalizedHost = normalizeRemoteHost(host)
// Why: GitLab documents altssh.gitlab.com as SSH-over-443 for gitlab.com projects.
return normalizedHost === 'altssh.gitlab.com' ? 'gitlab.com' : normalizedHost
}
export function normalizeBitbucketRemoteHost(host: string): string {
const normalizedHost = normalizeRemoteHost(host)
// Why: Bitbucket Cloud serves SSH for bitbucket.org repos from ssh.bitbucket.org.
return normalizedHost === 'ssh.bitbucket.org' ? 'bitbucket.org' : normalizedHost
}
export function normalizeForgeWebHost(host: string): string {
return normalizeBitbucketRemoteHost(normalizeGitLabRemoteHost(normalizeGitHubRemoteHost(host)))
}
/** Comparison-only host fold: the forge alias plus `www.`, for matching a remote to a pasted URL. */
export function foldComparableGitHubHost(host: string): string {
return normalizeGitHubRemoteHost(foldWwwHostAlias(host))
}
export function foldComparableGitLabHost(host: string): string {
return normalizeGitLabRemoteHost(foldWwwHostAlias(host))
}
/** Dotless hosts are unresolved OpenSSH Host aliases; remote -v cannot expand ~/.ssh/config, so mismatches remain unknown. */
export function isUnresolvedSshHostAlias(host: string): boolean {
return !normalizeRemoteHost(host).includes('.')
}