(gitUrl: string, gitlabInstanceUrl?: string)
| 84 | * `repo` set to the final path segment. |
| 85 | */ |
| 86 | export function parseGitUrl(gitUrl: string, gitlabInstanceUrl?: string): RepoCoordinates | null { |
| 87 | // Normalize: strip trailing .git and embedded credentials (e.g. https://token@github.com/...) |
| 88 | const withoutGitSuffix = gitUrl.endsWith('.git') ? gitUrl.slice(0, -4) : gitUrl; |
| 89 | const url = stripEmbeddedCredentials(withoutGitSuffix); |
| 90 | |
| 91 | const httpsMatch = url.match(/^https?:\/\/([^/]+)\/(.+)/); |
| 92 | if (httpsMatch) { |
| 93 | return coordinatesFromHostAndPath(httpsMatch[1], httpsMatch[2], gitlabInstanceUrl); |
| 94 | } |
| 95 | |
| 96 | const sshMatch = url.match(/^git@([^:]+):(.+)/); |
| 97 | if (sshMatch) { |
| 98 | return coordinatesFromHostAndPath(sshMatch[1], sshMatch[2], gitlabInstanceUrl); |
| 99 | } |
| 100 | |
| 101 | return null; |
| 102 | } |
| 103 | |
| 104 | function stripEmbeddedCredentials(url: string): string { |
| 105 | const authorityMarker = '//'; |
no test coverage detected