Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen --format repo URL restrictions #1385

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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: 2 additions & 1 deletion src/lib/getRepoUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function getRepoUrl(
// It may already be a valid Repo URL
const url = new URL(gitURL)
// Some packages put a full URL in this field although it's not spec compliant. Let's detect that and use it if present
if (['github.com', 'gitlab.com', 'bitbucket.org'].includes(url.hostname) && url.protocol === 'https:') {
if (url.protocol === 'https:' || url.protocol === 'http:') {
return gitURL
}
} catch (e) {}
Expand All @@ -84,6 +84,7 @@ async function getRepoUrl(
// Remove the default branch path (/tree/HEAD) from a git url
return hostedGitURL.replace(/\/$/, '').replace(/\/tree\/HEAD$/, '')
}
return gitURL
}
return null
}
Expand Down
16 changes: 8 additions & 8 deletions test/getRepoUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ describe('getRepoUrl', () => {
it('return null repository field is unknown type', async () => {
should.equal(await getRepoUrl('package-name', { repository: true as any /* allow to compile */ }), null)
})
it('return url directly from repository field if valid github url', async () => {
it('return url directly from repository field if valid https url', async () => {
const url = await getRepoUrl('package-name', { repository: 'https://github.com/user/repo' })
url!.should.equal('https://github.com/user/repo')
})
it('return url directly from repository field if valid gitlab url', async () => {
const url = await getRepoUrl('package-name', { repository: 'https://gitlab.com/user/repo' })
url!.should.equal('https://gitlab.com/user/repo')
})
it('return url directly from repository field if valid bitbucket url', async () => {
const url = await getRepoUrl('package-name', { repository: 'https://bitbucket.org/user/repo' })
url!.should.equal('https://bitbucket.org/user/repo')
it('return url directly from repository field if valid http url', async () => {
const url = await getRepoUrl('package-name', { repository: 'http://anything.com/user/repo' })
url!.should.equal('http://anything.com/user/repo')
})
it('return url constructed from github shortcut syntax string', async () => {
const url = await getRepoUrl('package-name', { repository: 'user/repo' })
Expand All @@ -33,6 +29,10 @@ describe('getRepoUrl', () => {
const url = await getRepoUrl('package-name', { repository: 'github:user/repo' })
url!.should.equal('https://github.com/user/repo')
})
it('return url directly from url field if not a known git host', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'https://any.website.com/some/path' } })
url!.should.equal('https://any.website.com/some/path')
})
it('return url constructed from git-https protocol', async () => {
const url = await getRepoUrl('package-name', { repository: { url: 'git+https://github.com/user/repo.git' } })
url!.should.equal('https://github.com/user/repo')
Expand Down
Loading