Skip to content

Commit 8e94f85

Browse files
jwulfbugthesystem
authored andcommitted
Add Bitbucket PR support (#88)
1 parent 32ae270 commit 8e94f85

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Open in GitHub / Bitbucket / Gitlab / VisualStudio.com !",
44
"description": "Jump to a source code line in Github / Bitbucket / Gitlab / VisualStudio.com !",
55
"icon": "images/icon_200.png",
6-
"version": "1.3.1",
6+
"version": "1.3.2",
77
"publisher": "ziyasal",
88
"license": "SEE LICENSE IN LICENSE.md",
99
"galleryBanner": {
@@ -84,6 +84,12 @@
8484
"http"
8585
],
8686
"description": "Specify the provider protocol for custom sites or Github enterprise"
87+
},
88+
"openInGitHub.defaultPullRequestBranch": {
89+
"type": "string",
90+
"default": "integration",
91+
"description": "Specify the default destination branch for pull requests"
92+
8793
}
8894
}
8995
},

src/extension.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,58 +34,58 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
3434
provider = null,
3535
remoteName;
3636

37-
var branch = 'master';
38-
39-
// Check to see if the branch has a configured remote
40-
configuredBranch = config[`branch "${branch}"`];
41-
42-
if (configuredBranch) {
43-
// Use the current branch's configured remote
44-
remoteName = configuredBranch.remote;
45-
rawUri = config[`remote "${remoteName}"`].url;
46-
} else {
47-
const remotes = Object.keys(config).filter(k => k.startsWith('remote '));
48-
if (remotes.length > 0) {
49-
rawUri = config[remotes[0]].url;
37+
gitRev.branch(repoDir, function (branchErr, branch) {
38+
// Check to see if the branch has a configured remote
39+
configuredBranch = config[`branch "${branch}"`];
40+
41+
if (configuredBranch) {
42+
// Use the current branch's configured remote
43+
remoteName = configuredBranch.remote;
44+
rawUri = config[`remote "${remoteName}"`].url;
45+
} else {
46+
const remotes = Object.keys(config).filter(k => k.startsWith('remote '));
47+
if (remotes.length > 0) {
48+
rawUri = config[remotes[0]].url;
49+
}
5050
}
51-
}
52-
53-
if (!rawUri) {
54-
Window.showWarningMessage(`No remote found on branch.`);
55-
return;
56-
}
57-
58-
try {
59-
provider = gitProvider(rawUri, sha);
60-
} catch (e) {
61-
let errmsg = e.toString();
62-
Window.showWarningMessage(`Unknown Git provider. ${errmsg}`);
63-
return;
64-
}
6551

66-
let formattedFilePath = path.relative(repoDir, fileFsPath).replace(/\\/g, '/');
67-
formattedFilePath = formattedFilePath.replace(/\s{1}/g, '%20');
68-
69-
let subdir = repoDir !== fileFsPath ? '/' + formattedFilePath : '';
52+
if (!rawUri) {
53+
Window.showWarningMessage(`No remote found on branch.`);
54+
return;
55+
}
7056

71-
if (pr) {
7257
try {
73-
cb(provider.prUrl(branch));
58+
provider = gitProvider(rawUri, sha);
7459
} catch (e) {
75-
Window.showWarningMessage(e.toString());
60+
let errmsg = e.toString();
61+
Window.showWarningMessage(`Unknown Git provider. ${errmsg}`);
7662
return;
7763
}
78-
} else {
79-
if (lines) {
80-
if (lines[0] == lines[1]) {
81-
cb(provider.webUrl(sha, subdir, lines[0]));
82-
} else {
83-
cb(provider.webUrl(sha, subdir, lines[0], lines[1]));
64+
65+
let formattedFilePath = path.relative(repoDir, fileFsPath).replace(/\\/g, '/');
66+
formattedFilePath = formattedFilePath.replace(/\s{1}/g, '%20');
67+
68+
let subdir = repoDir !== fileFsPath ? '/' + formattedFilePath : '';
69+
70+
if (pr) {
71+
try {
72+
cb(provider.prUrl(branch));
73+
} catch (e) {
74+
Window.showWarningMessage(e.toString());
75+
return;
8476
}
8577
} else {
86-
cb(provider.webUrl(sha, subdir));
78+
if (lines) {
79+
if (lines[0] == lines[1]) {
80+
cb(provider.webUrl(sha, subdir, lines[0]));
81+
} else {
82+
cb(provider.webUrl(sha, subdir, lines[0], lines[1]));
83+
}
84+
} else {
85+
cb(provider.webUrl(sha, subdir));
86+
}
8787
}
88-
}
88+
});
8989
});
9090
});
9191
}

src/gitProvider.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class Bitbucket extends BaseProvider {
5555
return `${this.baseUrl}/src/${this.sha}` + (filePath ? `${filePath}` : '') + (line ? `#${fileName}-${line}` : '');
5656
}
5757
prUrl(branch) {
58-
return `${this.baseUrl}/pull-requests/new?source=${branch}`;
58+
const repo = this.baseUrl.replace(`${providerProtocol}://bitbucket.org/`, '')
59+
return `${this.baseUrl}/pull-requests/new?source=${repo}%3A%3A${branch}&dest=${repo}%3A%3Aintegration`;
60+
// looks like this:
61+
// https://bitbucket.org/${org/repo}/pull-requests/new?source=${org/repo}%3A%3A${branch}&dest=${org/repo}%3A%3A${destBranch}
5962
}
6063
}
6164

@@ -68,7 +71,7 @@ class GitLab extends BaseProvider {
6871
}
6972
prUrl(branch) {
7073
//https://docs.gitlab.com/ee/api/merge_requests.html#create-mr
71-
//`${this.baseUrl}/merge-requests/new?source_branch=${branch}&target_branch=${????}&title=${????}`
74+
//`${this.baseUrl}/pull-requests/new?source_branch=${branch}&target_branch=${????}&title=${????}`
7275
throw new Error(`Doesn't support Merge Request from URL in GitLab yet`);
7376
}
7477
}
@@ -99,6 +102,7 @@ class VisualStudio extends BaseProvider {
99102
const gitHubDomain = workspace.getConfiguration('openInGitHub').get('gitHubDomain', 'github.com');
100103
const providerType = workspace.getConfiguration('openInGitHub').get('providerType', 'unknown');
101104
const providerProtocol = workspace.getConfiguration('openInGitHub').get('providerProtocol', 'https');
105+
const defaultPrBranch = workspace.getConfiguration('openInGitHub').get('defaultPullRequestBranch', 'integration')
102106

103107
const providers = {
104108
[gitHubDomain]: GitHub,

0 commit comments

Comments
 (0)