Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions shared/utils/git-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ export function normalizeGitUrl(input: string): string | null {
.replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
.replace(/^git:\/\//, 'https://')
.replace(/^ssh:\/\//, 'https://')
// Bare GitHub shorthand (e.g. "repository": "owner/repo"), following npm's convention
const hostAndPath = url.split('/')
if (!url.includes('://') && hostAndPath.length === 2 && !hostAndPath[0]!.includes('.')) {
Comment thread
taskylizard marked this conversation as resolved.
Outdated
return `https://github.com/${url}`
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if (!url) return null
return url.includes('://') ? url : `https://${url}`
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/shared/utils/git-providers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ describe('normalizeGitUrl', () => {
.soft(normalizeGitUrl('github:user/repo.git#readme'))
.toBe('https://github.com/user/repo#readme')
})

it('should expand bare owner/repo GitHub shorthand', () => {
expect.soft(normalizeGitUrl('wevm/ox')).toBe('https://github.com/wevm/ox')
expect.soft(normalizeGitUrl('user/repo.git')).toBe('https://github.com/user/repo')
expect.soft(normalizeGitUrl(' user/repo ')).toBe('https://github.com/user/repo')
})

it('should not treat host-prefixed paths as owner/repo shorthand', () => {
expect.soft(normalizeGitUrl('git.sr.ht/~user/repo')).toBe('https://git.sr.ht/~user/repo')
expect.soft(normalizeGitUrl('example.com/user/repo')).toBe('https://example.com/user/repo')
})

it('should parse bare shorthand repository fields', () => {
const info = parseRepositoryInfo('wevm/ox')
expect.soft(info?.provider).toBe('github')
expect.soft(info?.owner).toBe('wevm')
expect.soft(info?.repo).toBe('ox')
expect.soft(info?.rawBaseUrl).toBe('https://raw.githubusercontent.com/wevm/ox/HEAD')
expect.soft(info?.blobBaseUrl).toBe('https://github.com/wevm/ox/blob/HEAD')
})
})

describe('parseRepositoryInfo', () => {
Expand Down
Loading