Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/composables/useRepositoryUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export function useRepositoryUrl(
}

let url = normalizeGitUrl(repo.url)
if (!url) {
return null
}

// append `repository.directory` for monorepo packages
if (repo.directory) {
Expand Down
37 changes: 10 additions & 27 deletions shared/utils/git-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,33 +293,16 @@ const providers: ProviderConfig[] = [
* Handles: git+https://, git://, git@host:path, ssh://git@host/path
*/
export function normalizeGitUrl(input: string): string | null {
const raw = input.trim()
if (!raw) return null

const normalized = raw.replace(/^git\+/, '')

// Handle ssh:// and git:// URLs by converting to https://
if (/^(?:ssh|git):\/\//i.test(normalized)) {
try {
const url = new URL(normalized)
const path = url.pathname.replace(/^\/*/, '')
return `https://${url.hostname}/${path}`
} catch {
// Fall through to SCP handling
}
}

if (!/^https?:\/\//i.test(normalized)) {
// Handle SCP-style URLs: git@host:path
const scp = normalized.match(/^(?:git@)?([^:/]+):(.+)$/i)
if (scp?.[1] && scp?.[2]) {
const host = scp[1]
const path = scp[2].replace(/^\/*/, '')
return `https://${host}/${path}`
}
}

return normalized
const url = input
.trim()
.replace(/^git\+/, '')
.replace(/\.git$/, '')
.replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..."
.replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
.replace(/^git:\/\//, 'https://')
.replace(/^ssh:\/\//, 'https://')
if (!url) return null
return url.includes('://') ? url : `https://${url}`
}

export function parseRepoUrl(input: string): RepoRef | null {
Expand Down
Loading