Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
let 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://')
url = url.includes('://') ? url : `https://${url}`
return url || null
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

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