Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 57 additions & 12 deletions src/bors/handlers/help.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
use std::sync::Arc;

use crate::bors::command::{Approver, BorsCommand};
use crate::bors::Comment;
use crate::bors::RepositoryState;
use crate::github::PullRequest;

const HELP_MESSAGE: &str = r#"
- try: Execute the `try` CI workflow on this PR (without approving it for a merge).
- try cancel: Stop try builds on current PR.
- ping: pong
- help: Print this help message
"#;
use std::sync::Arc;

pub(super) async fn command_help(
repo: Arc<RepositoryState>,
pr: &PullRequest,
) -> anyhow::Result<()> {
let help = [
BorsCommand::Approve(Approver::Myself),
BorsCommand::Approve(Approver::Specified("".to_string())),
BorsCommand::Unapprove,
BorsCommand::Try {
parent: None,
jobs: vec![],
},
BorsCommand::TryCancel,
BorsCommand::Ping,
BorsCommand::Help,
]
.into_iter()
.map(|help| format!("- {}", get_command_help(help)))
.collect::<Vec<_>>()
.join("\n");

repo.client
.post_comment(pr.number, Comment::new(HELP_MESSAGE.to_string()))
.post_comment(pr.number, Comment::new(help))
.await?;
Ok(())
}

fn get_command_help(command: BorsCommand) -> String {
// !!! When modifying this match, also update the command list above (in [`command_help`]) !!!
let help = match command {
BorsCommand::Approve(Approver::Myself) => {
"`r+`: Approve this PR"
}
BorsCommand::Approve(Approver::Specified(_)) => {
"`r=<user>`: Approve this PR on behalf of `<user>`"
}
BorsCommand::Unapprove => {
"`r-`: Unapprove this PR"
}
BorsCommand::Help => {
"`help`: Print this help message"
}
BorsCommand::Ping => {
"`ping`: Check if the bot is alive"
}
BorsCommand::Try { .. } => {
"`try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run"
}
BorsCommand::TryCancel => {
"`try cancel`: Cancel a running try build"
}
};
help.to_string()
}

#[cfg(test)]
mod tests {
use crate::bors::handlers::help::HELP_MESSAGE;
use crate::tests::mocks::run_test;

#[sqlx::test]
async fn help_command(pool: sqlx::PgPool) {
run_test(pool, |mut tester| async {
tester.post_comment("@bors help").await?;
assert_eq!(tester.get_comment().await?, HELP_MESSAGE);
insta::assert_snapshot!(tester.get_comment().await?, @r"
- `r+`: Approve this PR
- `r=<user>`: Approve this PR on behalf of `<user>`
- `r-`: Unapprove this PR
- `try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run
- `try cancel`: Cancel a running try build
- `ping`: Check if the bot is alive
- `help`: Print this help message
");
Ok(tester)
})
.await;
Expand Down
Loading