(raw: string)
| 30 | * - HTTPS/other: passed through unchanged (with .git suffix stripped) |
| 31 | */ |
| 32 | export function normalizeRepoUrl(raw: string): string { |
| 33 | const trimmed = raw.trim(); |
| 34 | |
| 35 | // SCP-style: git@github.com:owner/repo.git |
| 36 | const scpMatch = trimmed.match(/^[\w.-]+@([^:]+):(.+)$/); |
| 37 | if (scpMatch) { |
| 38 | const host = scpMatch[1]; |
| 39 | const path = stripDotGit(scpMatch[2]); |
| 40 | return `https://${host}/${path}`; |
| 41 | } |
| 42 | |
| 43 | // SSH protocol: ssh://git@github.com/owner/repo.git |
| 44 | const sshMatch = trimmed.match(/^ssh:\/\/[\w.-]+@([^/]+)\/(.+)$/); |
| 45 | if (sshMatch) { |
| 46 | const host = sshMatch[1]; |
| 47 | const path = stripDotGit(sshMatch[2]); |
| 48 | return `https://${host}/${path}`; |
| 49 | } |
| 50 | |
| 51 | // Everything else: strip .git suffix if present, pass through |
| 52 | return stripDotGit(trimmed); |
| 53 | } |
| 54 | |
| 55 | function stripDotGit(s: string): string { |
| 56 | return s.endsWith('.git') ? s.slice(0, -4) : s; |
no test coverage detected