Skip to content

Commit 34d3e26

Browse files
authored
Merge pull request waderyan#28 from dimitarnestorov/master
View button on a BitBucket repo doesn't work waderyan#26
2 parents 7c3e42c + 6a74715 commit 34d3e26

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"minimum": 7,
9494
"maximum": 40
9595
},
96+
"gitblame.isWebPathPlural": {
97+
"type": "boolean",
98+
"default": false,
99+
"description": "BitBucket uses commits instead of commit in their web interface. Turn this on if you want the View button to work for BitBucket."
100+
},
96101
"gitblame.logLevel": {
97102
"type": "array",
98103
"default": [

src/git/blame.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,14 @@ export class GitBlame {
113113
}
114114
}
115115

116-
public defaultWebPath(url: string, hash: string): string {
116+
public defaultWebPath(
117+
url: string,
118+
hash: string,
119+
isPlural: boolean,
120+
): string {
117121
return url.replace(
118122
/^(git@|https:\/\/)([^:\/]+)[:\/](.*)\.git$/,
119-
`https://$2/$3/commit/${hash}`,
123+
`https://$2/$3/${isPlural ? "commit" : "commits"}/${hash}`,
120124
);
121125
}
122126

@@ -239,12 +243,18 @@ export class GitBlame {
239243
},
240244
);
241245

246+
const isWebPathPlural = Property.get(Properties.IsWebPathPlural, false);
247+
242248
if (isWebUri(parsedUrl)) {
243249
return Uri.parse(parsedUrl);
244250
} else if (parsedUrl === "guess") {
245251
const origin = await this.getOriginOfActiveFile();
246252
if (origin) {
247-
const uri = this.defaultWebPath(origin, commitInfo.hash);
253+
const uri = this.defaultWebPath(
254+
origin,
255+
commitInfo.hash,
256+
isWebPathPlural,
257+
);
248258
return Uri.parse(uri);
249259
} else {
250260
return;

src/util/property.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export enum Properties {
55
IgnoreWhitespace = "ignoreWhitespace",
66
InfoMessageFormat = "infoMessageFormat",
77
InternalHashLength = "internalHashLength",
8+
IsWebPathPlural = "isWebPathPlural",
89
LogLevel = "logLevel",
910
ProgressSpinner = "progressSpinner",
1011
StatusBarMessageFormat = "statusBarMessageFormat",
@@ -78,6 +79,9 @@ export class Property {
7879
internalHashLength: this.getPropertyFromConfiguration(
7980
Properties.InternalHashLength,
8081
),
82+
isWebPathPlural: this.getPropertyFromConfiguration(
83+
Properties.IsWebPathPlural,
84+
),
8185
logLevel: this.getPropertyFromConfiguration(
8286
Properties.LogLevel,
8387
),

0 commit comments

Comments
 (0)