@@ -522,6 +522,13 @@ const commands = (/** @type {Map<RegExp, CommentAction>} */(new Map()))
522522 await triggerGHActionWithComment ( request , "run-twoslash-repros" , { number : issueNumber || prNumber || undefined } , `run the code sample repros` ) ;
523523 } , undefined , false ) ) ;
524524
525+
526+ const botCall = "@typescript-bot" ;
527+ for ( const [ key , value ] of [ ...commands . entries ( ) ] ) {
528+ commands . delete ( key ) ;
529+ commands . set ( new RegExp ( `${ botCall } ${ key . source } ` , "i" ) , value ) ;
530+ }
531+
525532/**
526533 * @param {* } context
527534 * @param {* } data
@@ -565,6 +572,11 @@ function matchesCommand(context, body, isPr, authorAssociation) {
565572 if ( ! body ) {
566573 return undefined ;
567574 }
575+
576+ if ( ! body . includes ( botCall ) ) {
577+ return undefined ;
578+ }
579+
568580 const applicableActions = Array . from ( commands . entries ( ) ) . filter ( e => {
569581 if ( ! isPr && e [ 1 ] . prOnly ) {
570582 return false ;
@@ -574,20 +586,22 @@ function matchesCommand(context, body, isPr, authorAssociation) {
574586 if ( ! applicableActions . length ) {
575587 return undefined ;
576588 }
577- const botCall = "@typescript-bot" ;
578- if ( body . indexOf ( botCall ) !== - 1 ) {
579- context . log ( `Bot reference detected in '${ body } '` ) ;
580- }
589+
581590 /** @type {((req: any) => Promise<void>)[] } */
582591 let results = [ ] ;
583- for ( const [ key , action ] of applicableActions ) {
584- const fullRe = new RegExp ( `${ botCall } ${ key . source } ` , "i" ) ;
585- if ( fullRe . test ( body ) ) {
586- const match = fullRe . exec ( body ) ;
587- assert ( match ) ;
588- results . push ( r => action . task ( r , s => context . log ( s ) , match ) ) ;
592+
593+ const lines = new Set ( body . split ( "\n" ) . map ( s => s . trim ( ) ) . filter ( s => s ) ) ;
594+ for ( const line of lines ) {
595+ for ( const [ key , action ] of applicableActions ) {
596+ if ( key . test ( line ) ) {
597+ const match = key . exec ( line ) ;
598+ assert ( match ) ;
599+ results . push ( r => action . task ( r , s => context . log ( s ) , match ) ) ;
600+ break ;
601+ }
589602 }
590603 }
604+
591605 if ( ! results . length ) {
592606 return undefined ;
593607 }
0 commit comments