diff --git a/src/lib/getRepoUrl.ts b/src/lib/getRepoUrl.ts index 9638a416..f6851985 100644 --- a/src/lib/getRepoUrl.ts +++ b/src/lib/getRepoUrl.ts @@ -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) {} @@ -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 } diff --git a/test/getRepoUrl.test.ts b/test/getRepoUrl.test.ts index 579502d3..06b80669 100644 --- a/test/getRepoUrl.test.ts +++ b/test/getRepoUrl.test.ts @@ -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' }) @@ -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')