Skip to content

Commit 4400c8f

Browse files
jwulfbugthesystem
authored andcommitted
Fix BitBucket links (#86)
1 parent 1b3ce17 commit 4400c8f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
5656
}
5757

5858
try {
59-
provider = gitProvider(rawUri);
59+
provider = gitProvider(rawUri, sha);
6060
} catch (e) {
6161
let errmsg = e.toString();
6262
Window.showWarningMessage(`Unknown Git provider. ${errmsg}`);

src/gitProvider.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
const workspace = require('vscode').workspace
44
const querystring = require('querystring');
55
const gitUrlParse = require('git-url-parse');
6+
const path = require('path');
67

78
class BaseProvider {
8-
constructor(gitUrl) {
9+
constructor(gitUrl, sha) {
910
this.gitUrl = gitUrl;
11+
this.sha = sha;
1012
}
1113

1214
get baseUrl() {
@@ -44,7 +46,8 @@ class GitHub extends BaseProvider {
4446

4547
class Bitbucket extends BaseProvider {
4648
webUrl(branch, filePath, line, endLine) {
47-
return `${this.baseUrl}/src/${branch}` + (filePath ? `${filePath}` : '') + (line ? `#cl-${line}` : '');
49+
const fileName = path.basename(filePath)
50+
return `${this.baseUrl}/src/${this.sha}` + (filePath ? `${filePath}` : '') + (line ? `#${fileName}-${line}` : '');
4851
}
4952
prUrl(branch){
5053
return `${this.baseUrl}/pull-requests/new?source=${branch}`;
@@ -105,13 +108,13 @@ const providers = {
105108
* @param {string} remoteUrl
106109
* @return {BaseProvider|null}
107110
*/
108-
function gitProvider(remoteUrl) {
111+
function gitProvider(remoteUrl, sha) {
109112
const gitUrl = gitUrlParse(remoteUrl);
110113
for (const domain of Object.keys(providers)) {
111114
if (domain === gitUrl.resource || domain === gitUrl.source) {
112-
return new providers[domain](gitUrl);
115+
return new providers[domain](gitUrl, sha);
113116
}else if( domain.indexOf(providerType) > -1 ){
114-
return new providers[domain](gitUrl);
117+
return new providers[domain](gitUrl, sha);
115118
}
116119
}
117120
throw new Error('unknown Provider');

0 commit comments

Comments
 (0)