Skip to content

Commit abfea14

Browse files
fix: handle advertised github commands
Return clear responses for the explain and test commands listed by github help.
1 parent 0354ac8 commit abfea14

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

src/cortex-cli/src/github_cmd.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -410,21 +410,7 @@ async fn handle_issue_comment(
410410
client.add_reaction(comment.comment_id, "eyes").await?;
411411

412412
// Process the command
413-
let response = match command.as_str() {
414-
"help" => get_help_message(),
415-
"review" => {
416-
if comment.is_pull_request {
417-
"Starting code review... (not yet implemented)".to_string()
418-
} else {
419-
"This command is only available on pull requests.".to_string()
420-
}
421-
}
422-
"fix" => "Analyzing and suggesting fixes... (not yet implemented)".to_string(),
423-
_ => format!(
424-
"Unknown command: `{}`\n\nUse `/cortex help` to see available commands.",
425-
command
426-
),
427-
};
413+
let response = build_cortex_command_response(&command, comment.is_pull_request);
428414

429415
// Post response comment
430416
client
@@ -439,6 +425,26 @@ async fn handle_issue_comment(
439425
Ok(())
440426
}
441427

428+
fn build_cortex_command_response(command: &str, is_pull_request: bool) -> String {
429+
match command {
430+
"help" => get_help_message(),
431+
"review" => {
432+
if is_pull_request {
433+
"Starting code review... (not yet implemented)".to_string()
434+
} else {
435+
"This command is only available on pull requests.".to_string()
436+
}
437+
}
438+
"fix" => "Analyzing and suggesting fixes... (not yet implemented)".to_string(),
439+
"explain" => "Explaining code changes... (not yet implemented)".to_string(),
440+
"test" => "Suggesting tests for changes... (not yet implemented)".to_string(),
441+
_ => format!(
442+
"Unknown command: `{}`\n\nUse `/cortex help` to see available commands.",
443+
command
444+
),
445+
}
446+
}
447+
442448
/// Handle pull request events.
443449
async fn handle_pull_request(
444450
token: &str,
@@ -845,6 +851,21 @@ mod tests {
845851
let help = get_help_message();
846852
assert!(help.contains("/cortex help"));
847853
assert!(help.contains("/cortex review"));
854+
assert!(help.contains("/cortex explain"));
855+
assert!(help.contains("/cortex test"));
856+
}
857+
858+
#[test]
859+
fn test_advertised_commands_have_responses() {
860+
for command in ["explain", "test"] {
861+
let response = build_cortex_command_response(command, true);
862+
863+
assert!(
864+
!response.contains("Unknown command"),
865+
"{command} should not return unknown-command help"
866+
);
867+
assert!(response.contains("not yet implemented"));
868+
}
848869
}
849870

850871
#[tokio::test]

0 commit comments

Comments
 (0)