diff --git a/src/extension.ts b/src/extension.ts index f03a094..ce63b7d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,11 +12,15 @@ function getGitHubRepoURL(url: string) { if (url.endsWith('.git')) { url = url.substring(0, url.length - '.git'.length); } - if (url.startsWith('https://github.com/')) { + if (url.startsWith('http://') || url.startsWith('https://')) { return url; } - if (url.startsWith('git@github.com:')) { - return 'https://github.com/' + url.substring('git@github.com:'.length); + if (url.startsWith('git@')) { + var domainList = url.match("git@(.+):.+$"); + if (domainList) { + var domain = domainList[1]; + return 'https://' + domain + '/' + url.substring(('git@' + domain + ':').length); + } } return null; } @@ -88,11 +92,15 @@ function calculateURL() { const gitConfig = ini.parse(fs.readFileSync(path.join(gitDir, 'config'), 'utf8')); const branchInfo = Object.values(gitConfig).find(val => val['merge'] === refName); + var remoteName = "origin"; if (!branchInfo) { - throw new Error('No branch info found. Cannot calculate remote'); + console.error('No branch info found. Cannot calculate remote. Will use origin by default'); + } else { + remoteName = branchInfo['remote']; } const remote = branchInfo['remote']; const remoteInfo = Object.entries(gitConfig).find((entry) => entry[0] === `remote "${remote}"`); + if (!remoteInfo) { throw new Error(`No remote found called "${remote}"`); }