|
1 |
| -use std::sync::Arc; |
2 |
| - |
| 1 | +use crate::bors::command::{Approver, BorsCommand}; |
3 | 2 | use crate::bors::Comment;
|
4 | 3 | use crate::bors::RepositoryState;
|
5 | 4 | use crate::github::PullRequest;
|
6 |
| - |
7 |
| -const HELP_MESSAGE: &str = r#" |
8 |
| -- try: Execute the `try` CI workflow on this PR (without approving it for a merge). |
9 |
| -- try cancel: Stop try builds on current PR. |
10 |
| -- ping: pong |
11 |
| -- help: Print this help message |
12 |
| -"#; |
| 5 | +use std::sync::Arc; |
13 | 6 |
|
14 | 7 | pub(super) async fn command_help(
|
15 | 8 | repo: Arc<RepositoryState>,
|
16 | 9 | pr: &PullRequest,
|
17 | 10 | ) -> anyhow::Result<()> {
|
| 11 | + let help = [ |
| 12 | + BorsCommand::Approve(Approver::Myself), |
| 13 | + BorsCommand::Approve(Approver::Specified("".to_string())), |
| 14 | + BorsCommand::Unapprove, |
| 15 | + BorsCommand::Try { |
| 16 | + parent: None, |
| 17 | + jobs: vec![], |
| 18 | + }, |
| 19 | + BorsCommand::TryCancel, |
| 20 | + BorsCommand::Ping, |
| 21 | + BorsCommand::Help, |
| 22 | + ] |
| 23 | + .into_iter() |
| 24 | + .map(|help| format!("- {}", get_command_help(help))) |
| 25 | + .collect::<Vec<_>>() |
| 26 | + .join("\n"); |
| 27 | + |
18 | 28 | repo.client
|
19 |
| - .post_comment(pr.number, Comment::new(HELP_MESSAGE.to_string())) |
| 29 | + .post_comment(pr.number, Comment::new(help)) |
20 | 30 | .await?;
|
21 | 31 | Ok(())
|
22 | 32 | }
|
23 | 33 |
|
| 34 | +fn get_command_help(command: BorsCommand) -> String { |
| 35 | + // !!! When modifying this match, also update the command list above (in [`command_help`]) !!! |
| 36 | + let help = match command { |
| 37 | + BorsCommand::Approve(Approver::Myself) => { |
| 38 | + "`r+`: Approve this PR" |
| 39 | + } |
| 40 | + BorsCommand::Approve(Approver::Specified(_)) => { |
| 41 | + "`r=<user>`: Approve this PR on behalf of `<user>`" |
| 42 | + } |
| 43 | + BorsCommand::Unapprove => { |
| 44 | + "`r-`: Unapprove this PR" |
| 45 | + } |
| 46 | + BorsCommand::Help => { |
| 47 | + "`help`: Print this help message" |
| 48 | + } |
| 49 | + BorsCommand::Ping => { |
| 50 | + "`ping`: Check if the bot is alive" |
| 51 | + } |
| 52 | + BorsCommand::Try { .. } => { |
| 53 | + "`try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run" |
| 54 | + } |
| 55 | + BorsCommand::TryCancel => { |
| 56 | + "`try cancel`: Cancel a running try build" |
| 57 | + } |
| 58 | + }; |
| 59 | + help.to_string() |
| 60 | +} |
| 61 | + |
24 | 62 | #[cfg(test)]
|
25 | 63 | mod tests {
|
26 |
| - use crate::bors::handlers::help::HELP_MESSAGE; |
27 | 64 | use crate::tests::mocks::run_test;
|
28 | 65 |
|
29 | 66 | #[sqlx::test]
|
30 | 67 | async fn help_command(pool: sqlx::PgPool) {
|
31 | 68 | run_test(pool, |mut tester| async {
|
32 | 69 | tester.post_comment("@bors help").await?;
|
33 |
| - assert_eq!(tester.get_comment().await?, HELP_MESSAGE); |
| 70 | + insta::assert_snapshot!(tester.get_comment().await?, @r" |
| 71 | + - `r+`: Approve this PR |
| 72 | + - `r=<user>`: Approve this PR on behalf of `<user>` |
| 73 | + - `r-`: Unapprove this PR |
| 74 | + - `try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run |
| 75 | + - `try cancel`: Cancel a running try build |
| 76 | + - `ping`: Check if the bot is alive |
| 77 | + - `help`: Print this help message |
| 78 | + "); |
34 | 79 | Ok(tester)
|
35 | 80 | })
|
36 | 81 | .await;
|
|
0 commit comments