|
3 | 3 | const workspace = require('vscode').workspace |
4 | 4 | const querystring = require('querystring'); |
5 | 5 | const gitUrlParse = require('git-url-parse'); |
| 6 | +const path = require('path'); |
6 | 7 |
|
7 | 8 | class BaseProvider { |
8 | | - constructor(gitUrl) { |
| 9 | + constructor(gitUrl, sha) { |
9 | 10 | this.gitUrl = gitUrl; |
| 11 | + this.sha = sha; |
10 | 12 | } |
11 | 13 |
|
12 | 14 | get baseUrl() { |
@@ -44,7 +46,8 @@ class GitHub extends BaseProvider { |
44 | 46 |
|
45 | 47 | class Bitbucket extends BaseProvider { |
46 | 48 | 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}` : ''); |
48 | 51 | } |
49 | 52 | prUrl(branch){ |
50 | 53 | return `${this.baseUrl}/pull-requests/new?source=${branch}`; |
@@ -105,13 +108,13 @@ const providers = { |
105 | 108 | * @param {string} remoteUrl |
106 | 109 | * @return {BaseProvider|null} |
107 | 110 | */ |
108 | | -function gitProvider(remoteUrl) { |
| 111 | +function gitProvider(remoteUrl, sha) { |
109 | 112 | const gitUrl = gitUrlParse(remoteUrl); |
110 | 113 | for (const domain of Object.keys(providers)) { |
111 | 114 | if (domain === gitUrl.resource || domain === gitUrl.source) { |
112 | | - return new providers[domain](gitUrl); |
| 115 | + return new providers[domain](gitUrl, sha); |
113 | 116 | }else if( domain.indexOf(providerType) > -1 ){ |
114 | | - return new providers[domain](gitUrl); |
| 117 | + return new providers[domain](gitUrl, sha); |
115 | 118 | } |
116 | 119 | } |
117 | 120 | throw new Error('unknown Provider'); |
|
0 commit comments