@@ -234,14 +234,34 @@ export class Autolinks implements Disposable {
234234 continue ;
235235 }
236236
237+ if ( ref . referenceType ) {
238+ if ( ref . referenceType !== 'branchName' && options ?. isBranchName ) {
239+ continue ;
240+ }
241+ if ( ref . referenceType !== 'message' && ! options ?. isBranchName ) {
242+ continue ;
243+ }
244+ }
245+
237246 ensureCachedRegex ( ref , 'plaintext' ) ;
238247
239248 do {
240249 match = matchRef ( ref ) ;
241250 if ( ! match ?. groups ) break ;
242251
243252 num = match . groups . issueKeyNumber ;
244- const key = ref . prefix + num ;
253+ let key = num ;
254+ if ( autolinks . has ( key ) ) {
255+ const prevAutolink = autolinks . get ( key ) ! ;
256+ if ( ! ref . prefix ) {
257+ continue ;
258+ } else if ( ! prevAutolink . prefix && ref . prefix ) {
259+ /** override */
260+ } else {
261+ // add more autolinks
262+ key = ref . prefix + num ;
263+ }
264+ }
245265
246266 autolinks . set ( key , {
247267 provider : provider ,
@@ -633,24 +653,24 @@ function ensureCachedRegex(ref: CacheableAutolinkReference, outputFormat: 'html'
633653 if ( outputFormat === 'markdown' && ref . messageMarkdownRegex == null ) {
634654 // Extra `\\\\` in `\\\\\\[` is because the markdown is escaped
635655 ref . messageMarkdownRegex = new RegExp (
636- `(^|\\s|\\(|\\[|\\{)(?<issueKeyNumber>${ escapeRegex ( encodeHtmlWeak ( escapeMarkdown ( ref . prefix ) ) ) } ( ${
637- ref . alphanumeric ? '\\w' : '\\d'
638- } +))\\b`,
656+ `(^|\\s|\\(|\\[|\\{)(?<issueKeyNumber>${ escapeRegex (
657+ encodeHtmlWeak ( escapeMarkdown ( ref . prefix ) ) ,
658+ ) } (?<issueKeyNumber> ${ ref . alphanumeric ? '\\w' : '\\d' } +))\\b`,
639659 ref . ignoreCase ? 'gi' : 'g' ,
640660 ) ;
641661 } else if ( outputFormat === 'html' && ref . messageHtmlRegex == null ) {
642662 ref . messageHtmlRegex = new RegExp (
643- `(^|\\s|\\(|\\[|\\{)(?<issueKeyNumber> ${ escapeRegex ( encodeHtmlWeak ( ref . prefix ) ) } (${
663+ `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( encodeHtmlWeak ( ref . prefix ) ) } (?<issueKeyNumber> ${
644664 ref . alphanumeric ? '\\w' : '\\d'
645665 } +))\\b`,
646666 ref . ignoreCase ? 'gi' : 'g' ,
647667 ) ;
648668 } else if ( ref . messageRegex == null ) {
649669 ref . messageRegex = new RegExp (
650- `(^|\\s|\\(|\\[|\\{)(?<issueKeyNumber> ${ escapeRegex ( ref . prefix ) } (${ ref . alphanumeric ? '\\w' : '\\d' } +))\\b` ,
670+ `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( ref . prefix ) } (?<issueKeyNumber> ${ ref . alphanumeric ? '\\w' : '\\d' } +))\\b` ,
651671 ref . ignoreCase ? 'gi' : 'g' ,
652672 ) ;
653- ref . branchNameRegex = new RegExp ( `^\\D* (?<issueKeyNumber>( ${ escapeRegex ( ref . prefix ) } )? \\d*)\\D*$ ` , 'gi' ) ;
673+ ref . branchNameRegex = new RegExp ( `(^|\\-|_) (?<prefix> ${ ref . prefix } )(?<issueKeyNumber> \\d+) ` , 'gi' ) ;
654674 }
655675
656676 return true ;
0 commit comments