Skip to content

Commit

Permalink
fix: add protocol to url starting with git@ (#31)
Browse files Browse the repository at this point in the history
* test: git@ repro

* fix: add protocol to url starting with git@
  • Loading branch information
AndrewLeedham authored and juliuscc committed Dec 30, 2019
1 parent 83d430b commit 8baf727
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/getRepoInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const url = require('url')

module.exports = repositoryUrl => {
if (repositoryUrl.startsWith('git@')) {
repositoryUrl = 'ssh://' + repositoryUrl
}
const parsedUrl = new url.URL(
// without these replacements we will get a TypeError [ERR_INVALID_URL]
repositoryUrl.replace('.com:', '.com/').replace('.org:', '.org/')
Expand Down
7 changes: 7 additions & 0 deletions test/test_getRepoInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ describe('test getRepoInfo', () => {
const expectedUrl = 'https://github.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
})

it('should work for repo url with git@', () => {
const repositoryUrl = 'git@github.com:hello/world.git'
const expectedPath = 'hello/world'
const expectedUrl = 'https://github.com/hello/world'
runAssert(repositoryUrl, expectedPath, expectedUrl)
})
})

0 comments on commit 8baf727

Please sign in to comment.