@@ -55,24 +55,36 @@ export async function convertIssueReferencesToLinks(text: string, pullInfo: Pull
5555 return text ;
5656 }
5757
58- // Use a simple approach to find and replace issue references
59- return text . replace ( ISSUE_OR_URL_EXPRESSION , ( match ) => {
60- const parsed = parseIssueExpressionOutput ( match . match ( ISSUE_OR_URL_EXPRESSION ) ) ;
61- if ( ! parsed ) {
62- return match ;
63- }
64-
65- // If no owner/name specified, use the current repository context
66- if ( ! parsed . owner || ! parsed . name ) {
67- parsed . owner = pullInfo . owner ;
68- parsed . name = pullInfo . repo ;
69- }
58+ // Use a more sophisticated approach similar to findAndModifyString in markdownUtils.ts
59+ let searchResult = text . search ( ISSUE_OR_URL_EXPRESSION ) ;
60+ let position = 0 ;
61+ while ( searchResult >= 0 && searchResult < text . length ) {
62+ let newBodyFirstPart : string | undefined ;
63+ if ( searchResult === 0 || text . charAt ( searchResult - 1 ) !== '&' ) {
64+ const match = text . substring ( searchResult ) . match ( ISSUE_OR_URL_EXPRESSION ) ;
65+ if ( match ) {
66+ const parsed = parseIssueExpressionOutput ( match ) ;
67+ if ( parsed ) {
68+ // If no owner/name specified, use the current repository context
69+ if ( ! parsed . owner || ! parsed . name ) {
70+ parsed . owner = pullInfo . owner ;
71+ parsed . name = pullInfo . repo ;
72+ }
7073
71- const issueNumberLabel = getIssueNumberLabelFromParsed ( parsed ) ;
74+ const issueNumberLabel = getIssueNumberLabelFromParsed ( parsed ) ;
7275
73- // Create GitHub URL for the issue/PR
74- const githubUrl = `https://${ pullInfo . host || 'github.com' } /${ parsed . owner } /${ parsed . name } /issues/${ parsed . issueNumber } ` ;
76+ // Create GitHub URL for the issue/PR
77+ const githubUrl = `https://${ pullInfo . host || 'github.com' } /${ parsed . owner } /${ parsed . name } /issues/${ parsed . issueNumber } ` ;
7578
76- return `[${ issueNumberLabel } ](${ githubUrl } )` ;
77- } ) ;
79+ const transformed = `[${ issueNumberLabel } ](${ githubUrl } )` ;
80+ newBodyFirstPart = text . slice ( 0 , searchResult ) + transformed ;
81+ text = newBodyFirstPart + text . slice ( searchResult + match [ 0 ] . length ) ;
82+ }
83+ }
84+ }
85+ position = newBodyFirstPart ? newBodyFirstPart . length : searchResult + 1 ;
86+ const newSearchResult = text . substring ( position ) . search ( ISSUE_OR_URL_EXPRESSION ) ;
87+ searchResult = newSearchResult > 0 ? position + newSearchResult : newSearchResult ;
88+ }
89+ return text ;
7890}
0 commit comments