@@ -19,7 +19,7 @@ import { Resource } from '../common/resources';
1919import { GITHUB_ENTERPRISE , OVERRIDE_DEFAULT_BRANCH , PR_SETTINGS_NAMESPACE , URI } from '../common/settingKeys' ;
2020import * as Common from '../common/timelineEvent' ;
2121import { DataUri , toOpenIssueWebviewUri , toOpenPullRequestWebviewUri } from '../common/uri' ;
22- import { gitHubLabelColor , uniqBy } from '../common/utils' ;
22+ import { gitHubLabelColor , stringReplaceAsync , uniqBy } from '../common/utils' ;
2323import { OctokitCommon } from './common' ;
2424import { FolderRepositoryManager , PullRequestDefaults } from './folderRepositoryManager' ;
2525import { GitHubRepository , ViewerPermission } from './githubRepository' ;
@@ -307,6 +307,18 @@ export function convertRESTHeadToIGitHubRef(head: OctokitCommon.PullsListRespons
307307 } ;
308308}
309309
310+ async function transformHtmlUrlsToExtensionUrls ( body : string , githubRepository : GitHubRepository ) : Promise < string > {
311+ const issueRegex = new RegExp (
312+ `href="https?:\/\/${ githubRepository . remote . gitProtocol . url . authority } \\/${ githubRepository . remote . owner } \\/${ githubRepository . remote . repositoryName } \\/(issues|pull)\\/([0-9]+)"` ) ;
313+ return stringReplaceAsync ( body , issueRegex , async ( match : string , issuesOrPull : string , number : string ) => {
314+ if ( issuesOrPull === 'issues' ) {
315+ return `href="${ ( await toOpenIssueWebviewUri ( { owner : githubRepository . remote . owner , repo : githubRepository . remote . repositoryName , issueNumber : Number ( number ) } ) ) . toString ( ) } ""` ;
316+ } else {
317+ return `href="${ ( await toOpenPullRequestWebviewUri ( { owner : githubRepository . remote . owner , repo : githubRepository . remote . repositoryName , pullRequestNumber : Number ( number ) } ) ) . toString ( ) } "` ;
318+ }
319+ } ) ;
320+ }
321+
310322export function convertRESTPullRequestToRawPullRequest (
311323 pullRequest :
312324 | OctokitCommon . PullsGetResponseData
@@ -765,18 +777,18 @@ export function parseMergeability(mergeability: 'UNKNOWN' | 'MERGEABLE' | 'CONFL
765777 return parsed ;
766778}
767779
768- export function parseGraphQLPullRequest (
780+ export async function parseGraphQLPullRequest (
769781 graphQLPullRequest : GraphQL . PullRequest ,
770782 githubRepository : GitHubRepository ,
771- ) : PullRequest {
783+ ) : Promise < PullRequest > {
772784 const pr : PullRequest = {
773785 id : graphQLPullRequest . databaseId ,
774786 graphNodeId : graphQLPullRequest . id ,
775787 url : graphQLPullRequest . url ,
776788 number : graphQLPullRequest . number ,
777789 state : graphQLPullRequest . state ,
778790 body : graphQLPullRequest . body ,
779- bodyHTML : graphQLPullRequest . bodyHTML ,
791+ bodyHTML : await transformHtmlUrlsToExtensionUrls ( graphQLPullRequest . bodyHTML , githubRepository ) ,
780792 title : graphQLPullRequest . title ,
781793 titleHTML : graphQLPullRequest . titleHTML ,
782794 createdAt : graphQLPullRequest . createdAt ,
@@ -892,15 +904,15 @@ function parseComments(comments: GraphQL.AbbreviatedIssueComment[] | undefined,
892904 return parsedComments ;
893905}
894906
895- export function parseGraphQLIssue ( issue : GraphQL . Issue , githubRepository : GitHubRepository ) : Issue {
907+ export async function parseGraphQLIssue ( issue : GraphQL . Issue , githubRepository : GitHubRepository ) : Promise < Issue > {
896908 return {
897909 id : issue . databaseId ,
898910 graphNodeId : issue . id ,
899911 url : issue . url ,
900912 number : issue . number ,
901913 state : issue . state ,
902914 body : issue . body ,
903- bodyHTML : issue . bodyHTML ,
915+ bodyHTML : await transformHtmlUrlsToExtensionUrls ( issue . bodyHTML , githubRepository ) ,
904916 title : issue . title ,
905917 titleHTML : issue . titleHTML ,
906918 createdAt : issue . createdAt ,
0 commit comments