mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
fix(repos): parse and preserve custom-user SSH remotes (#337)
* fix(repos): parse and preserve custom-user SSH remotes SSH remotes with a non-git user (e.g. company@company.ghe.com:orga/repo.git) were misparsed as GitHub shorthand and stored as https://github.com/company@company.ghe.com:orga/repo. The scp-style matcher hardcoded the git@ user, so custom-user remotes fell through to the owner/repo shorthand branch. SSH URL parsing is now unified in shared/utils/repo.ts and applied across backend and frontend: any user@host:path remote is detected, preserved, and deduplicated correctly. The compare key also converges the scp-with-port and ssh:// spellings, strips embedded credentials, and fails closed on malformed host segments. * fix: apply CodeRabbit auto-fixes Fixed 1 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit <noreply@coderabbit.ai> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
This commit is contained in:
8 files changed
+257
-67
No files matched your search
@@ -24,45 +24,6 @@ function normalizeGitCredentialUrl(host: string): URL | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function isSSHUrl(url: string): boolean {
|
||||
return url.startsWith('git@') || url.startsWith('ssh://')
|
||||
}
|
||||
|
||||
export function normalizeSSHUrl(url: string): string {
|
||||
if (url.startsWith('ssh://')) {
|
||||
return url
|
||||
}
|
||||
|
||||
const match = url.match(/^git@([^:]+):(\d{1,5})\/(.+)$/)
|
||||
if (match) {
|
||||
const [, host, port, path] = match
|
||||
const portNum = parseInt(port!, 10)
|
||||
if (portNum > 0 && portNum <= 65535) {
|
||||
return `ssh://git@${host}:${port}/${path}`
|
||||
}
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
export function extractHostFromSSHUrl(url: string): string | null {
|
||||
if (url.startsWith('git@')) {
|
||||
const match = url.match(/^git@([^:]+):/)
|
||||
const host = match?.[1]
|
||||
return host || null
|
||||
}
|
||||
if (url.startsWith('ssh://')) {
|
||||
try {
|
||||
const parsed = new URL(url)
|
||||
const hostname = parsed.hostname ?? ''
|
||||
const port = parsed.port ?? ''
|
||||
return port ? `${hostname}:${port}` : parsed.hostname || null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function normalizeHost(host: string): string | null {
|
||||
const url = normalizeGitCredentialUrl(host)
|
||||
return url ? `${url.protocol}//${url.host}/` : null
|
||||
|
||||
Reference in new issue
Block a user