@@ -17,7 +17,7 @@ var findParentDir = require('find-parent-dir');
1717
1818const gitProvider = require ( './gitProvider' ) ;
1919
20- function getGitProviderLink ( cb , fileFsPath , line ) {
20+ function getGitProviderLink ( cb , fileFsPath , line , pr ) {
2121 var cwd = workspace . rootPath ;
2222 var repoDir = findParentDir . sync ( workspace . rootPath , '.git' ) || cwd ;
2323
@@ -44,11 +44,19 @@ function getGitProviderLink(cb, fileFsPath, line) {
4444 subdir = repoRelativePath + subdir ;
4545 }
4646
47- cb ( provider . webUrl ( branch , subdir , line ) ) ;
47+ if ( pr ) {
48+ cb ( provider . prUrl ( branch ) ) ;
49+ }
50+ else {
51+ cb ( provider . webUrl ( branch , subdir , line ) ) ;
52+ }
53+
4854 } ) ;
4955 } ) ;
5056}
5157
58+
59+
5260function getGitProviderLinkForFile ( fileFsPath , cb ) {
5361 getGitProviderLink ( cb , fileFsPath ) ;
5462}
@@ -66,8 +74,16 @@ function getGitProviderLinkForRepo(cb) {
6674 getGitProviderLink ( cb ) ;
6775}
6876
69- function branchOnCallingContext ( args , cb ) {
70- if ( args && args . fsPath ) {
77+ function getGitProviderPullRequest ( cb ) {
78+ getGitProviderLink ( cb , undefined , undefined , true ) ;
79+ }
80+
81+
82+ function branchOnCallingContext ( args , cb , pr ) {
83+ if ( pr ) {
84+ getGitProviderPullRequest ( cb ) ;
85+ }
86+ else if ( args && args . fsPath ) {
7187 getGitProviderLinkForFile ( args . fsPath , cb ) ;
7288 }
7389 else if ( Window . activeTextEditor ) {
@@ -78,6 +94,7 @@ function branchOnCallingContext(args, cb) {
7894 }
7995}
8096
97+
8198function openInGitProvider ( args ) {
8299 branchOnCallingContext ( args , open ) ;
83100}
@@ -86,10 +103,15 @@ function copyGitProviderLinkToClipboard(args) {
86103 branchOnCallingContext ( args , copy ) ;
87104}
88105
106+ function openPrGitProvider ( args ) {
107+ branchOnCallingContext ( args , open , true ) ;
108+ }
109+
89110//TODO: rename openInGitHub to openInGitProvider
90111function activate ( context ) {
91112 context . subscriptions . push ( commands . registerCommand ( 'extension.openInGitHub' , openInGitProvider ) ) ;
92113 context . subscriptions . push ( commands . registerCommand ( 'extension.copyGitHubLinkToClipboard' , copyGitProviderLinkToClipboard ) ) ;
114+ context . subscriptions . push ( commands . registerCommand ( 'extension.openPrGitProvider' , openPrGitProvider ) ) ;
93115}
94116
95117exports . activate = activate ;
0 commit comments