(url: string)
| 281 | * - http://local_proxy@127.0.0.1:16583/git/owner/repo -> github.com/owner/repo |
| 282 | */ |
| 283 | export function normalizeGitRemoteUrl(url: string): string | null { |
| 284 | const trimmed = url.trim() |
| 285 | if (!trimmed) return null |
| 286 | |
| 287 | // Handle SSH format: git@host:owner/repo.git |
| 288 | const sshMatch = trimmed.match(/^git@([^:]+):(.+?)(?:\.git)?$/) |
| 289 | if (sshMatch && sshMatch[1] && sshMatch[2]) { |
| 290 | return `${sshMatch[1]}/${sshMatch[2]}`.toLowerCase() |
| 291 | } |
| 292 | |
| 293 | // Handle HTTPS/SSH URL format: https://host/owner/repo.git or ssh://git@host/owner/repo |
| 294 | const urlMatch = trimmed.match( |
| 295 | /^(?:https?|ssh):\/\/(?:[^@]+@)?([^/]+)\/(.+?)(?:\.git)?$/, |
| 296 | ) |
| 297 | if (urlMatch && urlMatch[1] && urlMatch[2]) { |
| 298 | const host = urlMatch[1] |
| 299 | const path = urlMatch[2] |
| 300 | |
| 301 | // CCR git proxy URLs use format: |
| 302 | // Legacy: http://...@127.0.0.1:PORT/git/owner/repo (github.com assumed) |
| 303 | // GHE: http://...@127.0.0.1:PORT/git/ghe.host/owner/repo (host encoded in path) |
| 304 | // Strip the /git/ prefix. If the first segment contains a dot, it's a |
| 305 | // hostname (GitHub org names cannot contain dots). Otherwise assume github.com. |
| 306 | if (isLocalHost(host) && path.startsWith('git/')) { |
| 307 | const proxyPath = path.slice(4) // Remove "git/" prefix |
| 308 | const segments = proxyPath.split('/') |
| 309 | // 3+ segments where first contains a dot → host/owner/repo (GHE format) |
| 310 | if (segments.length >= 3 && segments[0]!.includes('.')) { |
| 311 | return proxyPath.toLowerCase() |
| 312 | } |
| 313 | // 2 segments → owner/repo (legacy format, assume github.com) |
| 314 | return `github.com/${proxyPath}`.toLowerCase() |
| 315 | } |
| 316 | |
| 317 | return `${host}/${path}`.toLowerCase() |
| 318 | } |
| 319 | |
| 320 | return null |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Returns a SHA256 hash (first 16 chars) of the normalized git remote URL. |
no test coverage detected