From ef1324d6f13f1243a4d3a0bc9e477806fba49988 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 13:25:48 -0700 Subject: [PATCH] Detect GitHub URL-style SSH remotes (#3605) --- src/main/github/gh-utils.test.ts | 8 +++++++ src/main/github/gh-utils.ts | 38 +++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/main/github/gh-utils.test.ts b/src/main/github/gh-utils.test.ts index 54646ffbe..bbe98deec 100644 --- a/src/main/github/gh-utils.test.ts +++ b/src/main/github/gh-utils.test.ts @@ -47,6 +47,14 @@ describe('github owner/repo resolution', () => { owner: 'TheBoredTeam', repo: 'boring.notch' }) + expect(parseGitHubOwnerRepo('ssh://git@github.com/stablyai/orca.git')).toEqual({ + owner: 'stablyai', + repo: 'orca' + }) + expect(parseGitHubOwnerRepo('ssh://git@ssh.github.com:443/stablyai/orca.git')).toEqual({ + owner: 'stablyai', + repo: 'orca' + }) expect(parseGitHubOwnerRepo('git@example.com:stablyai/orca.git')).toBeNull() }) diff --git a/src/main/github/gh-utils.ts b/src/main/github/gh-utils.ts index 1105f9006..d92536696 100644 --- a/src/main/github/gh-utils.ts +++ b/src/main/github/gh-utils.ts @@ -159,17 +159,49 @@ export function parseGitHubOwnerRepo(remoteUrl: string): OwnerRepo | null { return { owner: identity.owner, repo: identity.repo } } +function normalizeGitHubRemoteHost(host: string): string { + // Why: GitHub documents ssh.github.com:443 as SSH-over-HTTPS for github.com repos. + return host.toLowerCase() === 'ssh.github.com' ? 'github.com' : host +} + +function parseGitHubRemotePath(path: string): Pick | null { + const parts = path.replace(/^\/+/, '').replace(/\/+$/, '').split('/') + if (parts.length !== 2) { + return null + } + const [owner, repoWithSuffix] = parts + const repo = repoWithSuffix.replace(/\.git$/i, '') + if (!owner || !repo) { + return null + } + return { owner, repo } +} + export function parseGitHubRemoteIdentity(remoteUrl: string): GitHubRemoteIdentity | null { const trimmed = remoteUrl.trim() const httpsMatch = trimmed.match(/^https?:\/\/([^/]+)\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i) if (httpsMatch) { - return { host: httpsMatch[1], owner: httpsMatch[2], repo: httpsMatch[3] } + return { + host: normalizeGitHubRemoteHost(httpsMatch[1]), + owner: httpsMatch[2], + repo: httpsMatch[3] + } } const sshMatch = trimmed.match(/^git@([^:]+):([^/]+)\/([^/]+?)(?:\.git)?$/i) if (sshMatch) { - return { host: sshMatch[1], owner: sshMatch[2], repo: sshMatch[3] } + return { host: normalizeGitHubRemoteHost(sshMatch[1]), owner: sshMatch[2], repo: sshMatch[3] } + } + + try { + const url = new URL(trimmed) + if (!['git:', 'git+ssh:', 'ssh:'].includes(url.protocol.toLowerCase())) { + return null + } + const path = parseGitHubRemotePath(url.pathname) + return path ? { host: normalizeGitHubRemoteHost(url.hostname), ...path } : null + } catch { + return null } - return null } export async function getRemoteUrlForRepo(