From 22d83dbe0b7cb95ca7a61867045a962776262533 Mon Sep 17 00:00:00 2001 From: zhadrian Date: Thu, 16 Jan 2020 20:59:46 +0100 Subject: [PATCH] fix(getrepoinfo): fix for other TLD checking in repo url (#33) Now plugin should work properly with private/internal repositories with other TLD than .com --- lib/getRepoInfo.js | 5 ++++- test/test_getRepoInfo.js | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/getRepoInfo.js b/lib/getRepoInfo.js index 4815d1a..d91ea0a 100644 --- a/lib/getRepoInfo.js +++ b/lib/getRepoInfo.js @@ -6,7 +6,10 @@ module.exports = repositoryUrl => { } const parsedUrl = new url.URL( // without these replacements we will get a TypeError [ERR_INVALID_URL] - repositoryUrl.replace('.com:', '.com/').replace('.org:', '.org/') + repositoryUrl.replace( + /\.([a-z])*:/i, + rep => rep.substring(0, rep.length - 1) + '/' + ) ) const path = parsedUrl.pathname .substring(1) // remove leading "/" diff --git a/test/test_getRepoInfo.js b/test/test_getRepoInfo.js index 22fea1e..70dfa3c 100644 --- a/test/test_getRepoInfo.js +++ b/test/test_getRepoInfo.js @@ -43,4 +43,11 @@ describe('test getRepoInfo', () => { const expectedUrl = 'https://github.com/hello/world' runAssert(repositoryUrl, expectedPath, expectedUrl) }) + + it('should work for repo url with other TLD', () => { + const repositoryUrl = 'git@github.pl:hello/world.git' + const expectedPath = 'hello/world' + const expectedUrl = 'https://github.pl/hello/world' + runAssert(repositoryUrl, expectedPath, expectedUrl) + }) })