Skip to content

Commit ccd5d45

Browse files
committed
Add suggestion to run help command when command parsing fails
1 parent 2763e33 commit ccd5d45

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/bors/handlers/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ async fn handle_comment(
349349
ctx: Arc<BorsContext>,
350350
comment: PullRequestComment,
351351
) -> anyhow::Result<()> {
352+
use std::fmt::Write;
353+
352354
let pr_number = comment.pr_number;
353355
let commands = ctx.parser.parse_commands(&comment.text);
354356

@@ -488,7 +490,7 @@ async fn handle_comment(
488490
}
489491
}
490492
Err(error) => {
491-
let message = match error {
493+
let mut message = match error {
492494
CommandParseError::MissingCommand => "Missing command.".to_string(),
493495
CommandParseError::UnknownCommand(command) => {
494496
format!(r#"Unknown command "{command}"."#)
@@ -503,9 +505,14 @@ async fn handle_comment(
503505
format!(r#"Argument "{arg}" found multiple times."#)
504506
}
505507
CommandParseError::ValidationError(error) => {
506-
format!("Invalid command: {error}")
508+
format!("Invalid command: {error}.")
507509
}
508510
};
511+
writeln!(
512+
message,
513+
" Run `{} help` to see available commands.",
514+
ctx.parser.prefix()
515+
)?;
509516
tracing::warn!("{}", message);
510517
repo.client
511518
.post_comment(pr_github.number, Comment::new(message))
@@ -631,4 +638,14 @@ mod tests {
631638
})
632639
.await;
633640
}
641+
642+
#[sqlx::test]
643+
async fn unknown_command(pool: sqlx::PgPool) {
644+
run_test(pool, |mut tester| async {
645+
tester.post_comment(Comment::from("@bors foo")).await?;
646+
insta::assert_snapshot!(tester.get_comment().await?, @r#"Unknown command "foo". Run `@bors help` to see available commands."#);
647+
Ok(tester)
648+
})
649+
.await;
650+
}
634651
}

0 commit comments

Comments
 (0)