Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support self-hosted GitHub #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}"`);
}
Expand Down