Skip to content

Commit f7decab

Browse files
committed
fix: improve normalizeGitUrl
1 parent c5202d0 commit f7decab

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

app/composables/useRepositoryUrl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function useRepositoryUrl(
1717
}
1818

1919
let url = normalizeGitUrl(repo.url)
20+
if (!url) {
21+
return null
22+
}
2023

2124
// append `repository.directory` for monorepo packages
2225
if (repo.directory) {

shared/utils/git-providers.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -293,33 +293,15 @@ const providers: ProviderConfig[] = [
293293
* Handles: git+https://, git://, git@host:path, ssh://git@host/path
294294
*/
295295
export function normalizeGitUrl(input: string): string | null {
296-
const raw = input.trim()
297-
if (!raw) return null
298-
299-
const normalized = raw.replace(/^git\+/, '')
300-
301-
// Handle ssh:// and git:// URLs by converting to https://
302-
if (/^(?:ssh|git):\/\//i.test(normalized)) {
303-
try {
304-
const url = new URL(normalized)
305-
const path = url.pathname.replace(/^\/*/, '')
306-
return `https://${url.hostname}/${path}`
307-
} catch {
308-
// Fall through to SCP handling
309-
}
310-
}
311-
312-
if (!/^https?:\/\//i.test(normalized)) {
313-
// Handle SCP-style URLs: git@host:path
314-
const scp = normalized.match(/^(?:git@)?([^:/]+):(.+)$/i)
315-
if (scp?.[1] && scp?.[2]) {
316-
const host = scp[1]
317-
const path = scp[2].replace(/^\/*/, '')
318-
return `https://${host}/${path}`
319-
}
320-
}
321-
322-
return normalized
296+
const normalized = input
297+
.trim()
298+
.replace(/^git\+/, '')
299+
.replace(/\.git$/, '')
300+
.replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..."
301+
.replace(/(\.[^.]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
302+
.replace(/^git:\/\//, 'https://')
303+
.replace(/^ssh:\/\//, 'https://')
304+
return normalized || null
323305
}
324306

325307
export function parseRepoUrl(input: string): RepoRef | null {

0 commit comments

Comments
 (0)