@@ -388,10 +388,8 @@ async fn handle_issue_comment(
388388 return Ok ( ( ) ) ;
389389 }
390390
391- // Check if comment mentions cortex or starts with /cortex
392- let is_cortex_mention = comment. body . contains ( "@cortex" )
393- || comment. body . starts_with ( "/cortex" )
394- || comment. body . to_lowercase ( ) . contains ( "cortex help" ) ;
391+ // Check if comment mentions cortex or starts with /cortex.
392+ let is_cortex_mention = contains_cortex_trigger ( & comment. body ) ;
395393
396394 if !is_cortex_mention {
397395 println ! ( " Skipping: no Cortex mention detected" ) ;
@@ -523,12 +521,12 @@ async fn handle_issue(
523521 let client = GitHubClient :: new ( token, repository) ?;
524522
525523 // Check if issue mentions cortex
526- let is_cortex_related = issue. title . to_lowercase ( ) . contains ( "Cortex " )
527- || issue. body . to_lowercase ( ) . contains ( "Cortex " )
524+ let is_cortex_related = issue. title . to_lowercase ( ) . contains ( "cortex " )
525+ || issue. body . to_lowercase ( ) . contains ( "cortex " )
528526 || issue
529527 . labels
530528 . iter ( )
531- . any ( |l| l. to_lowercase ( ) . contains ( "Cortex " ) ) ;
529+ . any ( |l| l. to_lowercase ( ) . contains ( "cortex " ) ) ;
532530
533531 if is_cortex_related {
534532 let greeting = format ! (
@@ -546,21 +544,41 @@ async fn handle_issue(
546544
547545/// Parse a cortex command from comment text.
548546fn parse_cortex_command ( text : & str ) -> String {
549- // Look for /cortex <command> pattern
550- if let Some ( pos) = text. find ( "/cortex" ) {
551- let after_cortex = & text[ pos + 7 ..] ;
552- let command = after_cortex. split_whitespace ( ) . next ( ) . unwrap_or ( "help" ) ;
553- return command. to_string ( ) ;
547+ find_cortex_command_start ( text)
548+ . map ( |pos| {
549+ let after_cortex = & text[ pos + 7 ..] ;
550+ after_cortex
551+ . split_whitespace ( )
552+ . next ( )
553+ . unwrap_or ( "help" )
554+ . to_ascii_lowercase ( )
555+ } )
556+ . unwrap_or_else ( || "help" . to_string ( ) )
557+ }
558+
559+ fn contains_cortex_trigger ( text : & str ) -> bool {
560+ find_cortex_command_start ( text) . is_some ( ) || text. to_ascii_lowercase ( ) . contains ( "cortex help" )
561+ }
562+
563+ fn find_cortex_command_start ( text : & str ) -> Option < usize > {
564+ let lower = text. to_ascii_lowercase ( ) ;
565+
566+ if lower. starts_with ( "/cortex" ) {
567+ return Some ( 0 ) ;
554568 }
555569
556- // Look for @cortex <command> pattern
557- if let Some ( pos) = text. find ( "@cortex" ) {
558- let after_cortex = & text[ pos + 7 ..] ;
559- let command = after_cortex. split_whitespace ( ) . next ( ) . unwrap_or ( "help" ) ;
560- return command. to_string ( ) ;
570+ if let Some ( pos) = lower. find ( "@cortex" ) {
571+ return Some ( pos) ;
561572 }
562573
563- "help" . to_string ( )
574+ if let Some ( pos) = lower. find ( "/cortex" ) {
575+ let before = & lower[ ..pos] ;
576+ if before. ends_with ( char:: is_whitespace) {
577+ return Some ( pos) ;
578+ }
579+ }
580+
581+ None
564582}
565583
566584/// Get help message for Cortex commands.
@@ -837,9 +855,21 @@ mod tests {
837855 assert_eq ! ( parse_cortex_command( "/cortex review" ) , "review" ) ;
838856 assert_eq ! ( parse_cortex_command( "@cortex fix" ) , "fix" ) ;
839857 assert_eq ! ( parse_cortex_command( "Please @cortex help me" ) , "help" ) ;
858+ assert_eq ! ( parse_cortex_command( "/Cortex REVIEW" ) , "review" ) ;
859+ assert_eq ! ( parse_cortex_command( "Please @Cortex Fix this" ) , "fix" ) ;
840860 assert_eq ! ( parse_cortex_command( "No command here" ) , "help" ) ;
841861 }
842862
863+ #[ test]
864+ fn test_contains_cortex_trigger_case_insensitive ( ) {
865+ assert ! ( contains_cortex_trigger( "@Cortex review" ) ) ;
866+ assert ! ( contains_cortex_trigger( "/Cortex help" ) ) ;
867+ assert ! ( contains_cortex_trigger( "please /Cortex fix" ) ) ;
868+ assert ! ( contains_cortex_trigger( "Cortex Help" ) ) ;
869+ assert ! ( !contains_cortex_trigger( "cortexium help" ) ) ;
870+ assert ! ( !contains_cortex_trigger( "No command here" ) ) ;
871+ }
872+
843873 #[ test]
844874 fn test_get_help_message ( ) {
845875 let help = get_help_message ( ) ;
0 commit comments