33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { URLSearchParams } from 'url' ;
6+ import { URL , URLSearchParams } from 'url' ;
77import LRUCache from 'lru-cache' ;
88import * as marked from 'marked' ;
99import * as vscode from 'vscode' ;
@@ -15,7 +15,7 @@ import { GithubItemStateEnum, User } from '../github/interface';
1515import { IssueModel } from '../github/issueModel' ;
1616import { PullRequestModel } from '../github/pullRequestModel' ;
1717import { RepositoriesManager } from '../github/repositoriesManager' ;
18- import { getRepositoryForFile } from '../github/utils' ;
18+ import { getEnterpriseUri , getRepositoryForFile } from '../github/utils' ;
1919import { ReviewManager } from '../view/reviewManager' ;
2020import { CODE_PERMALINK , findCodeLinkLocally } from './issueLinkLookup' ;
2121import { StateManager } from './stateManager' ;
@@ -508,15 +508,37 @@ export async function createGithubPermalink(
508508 }
509509 }
510510 const pathSegment = uri . path . substring ( repository . rootUri . path . length ) ;
511-
511+ const originOfFetchUrl = getUpstreamOrigin ( upstream ) . replace ( / \/ $ / , '' ) ;
512512 return {
513- permalink : `https://github.com /${ new Protocol ( upstream . fetchUrl ) . nameWithOwner } /blob/${ commitHash
513+ permalink : `${ originOfFetchUrl } /${ new Protocol ( upstream . fetchUrl ) . nameWithOwner } /blob/${ commitHash
514514 } ${ pathSegment } ${ rangeString ( range ) } `,
515515 error : undefined ,
516516 originalFile : uri
517517 } ;
518518}
519519
520+ function getUpstreamOrigin ( upstream : Remote ) {
521+ let resultHost : string = 'github.com' ;
522+ const enterpriseUri = getEnterpriseUri ( ) ;
523+ if ( enterpriseUri && upstream . fetchUrl ) {
524+ // upstream's origin by https
525+ if ( upstream . fetchUrl . startsWith ( 'https://' ) && ! upstream . fetchUrl . startsWith ( 'https://github.com/' ) ) {
526+ const host = new URL ( upstream . fetchUrl ) . host ;
527+ if ( host === enterpriseUri . authority ) {
528+ resultHost = host ;
529+ }
530+ }
531+ // upstream's origin by ssh
532+ if ( upstream . fetchUrl . startsWith ( 'git@' ) && ! upstream . fetchUrl . startsWith ( 'git@github.com' ) ) {
533+ const host = upstream . fetchUrl . split ( '@' ) [ 1 ] ?. split ( ':' ) [ 0 ] ;
534+ if ( host === enterpriseUri . authority ) {
535+ resultHost = host ;
536+ }
537+ }
538+ }
539+ return `https://${ resultHost } ` ;
540+ }
541+
520542function rangeString ( range : vscode . Range | undefined ) {
521543 if ( ! range ) {
522544 return '' ;
0 commit comments