From 8baf727b5f84cb803b8e78bd6ccd014e4d6b1f98 Mon Sep 17 00:00:00 2001 From: Andrew Leedham Date: Mon, 30 Dec 2019 20:30:26 +0000 Subject: [PATCH] fix: add protocol to url starting with git@ (#31) * test: git@ repro * fix: add protocol to url starting with git@ --- lib/getRepoInfo.js | 3 +++ test/test_getRepoInfo.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/getRepoInfo.js b/lib/getRepoInfo.js index 609d3cf..e92fd17 100644 --- a/lib/getRepoInfo.js +++ b/lib/getRepoInfo.js @@ -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/') diff --git a/test/test_getRepoInfo.js b/test/test_getRepoInfo.js index f5a4461..641b767 100644 --- a/test/test_getRepoInfo.js +++ b/test/test_getRepoInfo.js @@ -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) + }) })