Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/bors/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ pub struct DelegateCommand {
pub permission: DelegatedPermission,
}

#[derive(Debug, PartialEq)]
pub enum SquashCommitMessage {
/// Automatically generate a commit message based on the messages of the squashed commits.
AutoGenerate,
/// Set the commit message to the PR body.
PullRequestDescription,
/// Set an explicit commit message.
Explicit(String),
}

/// Bors command specified by a user.
///
/// When modifying commands, remember to also update:
Expand Down Expand Up @@ -162,5 +172,5 @@ pub enum BorsCommand {
/// Cancel an auto build currently running on a given PR (without removing it from the queue).
Cancel,
/// Squash all commits of a pull request into a single commit.
Squash { commit_message: Option<String> },
Squash { commit_message: SquashCommitMessage },
}
60 changes: 42 additions & 18 deletions src/bors/command/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines parsers for bors commands.

use crate::bors::command::{
Approver, BorsCommand, CommandPrefix, DelegateCommand, Delegatee, Parent,
Approver, BorsCommand, CommandPrefix, DelegateCommand, Delegatee, Parent, SquashCommitMessage,
};
use crate::database::DelegatedPermission;
use crate::github::CommitSha;
Expand Down Expand Up @@ -630,20 +630,28 @@ fn parser_squash(command: &CommandPart<'_>, parts: &[CommandPart<'_>]) -> ParseR
match command {
CommandPart::Bare("squash") => match parts {
&[] => Some(Ok(BorsCommand::Squash {
commit_message: None,
commit_message: SquashCommitMessage::AutoGenerate,
})),
&[
CommandPart::KeyValue {
key: "msg" | "message",
value,
},
..,
] => Some(Ok(BorsCommand::Squash {
commit_message: Some(value.to_owned()),
})),
] => {
if value == "description" {
Some(Ok(BorsCommand::Squash {
commit_message: SquashCommitMessage::PullRequestDescription,
}))
} else {
Some(Ok(BorsCommand::Squash {
commit_message: SquashCommitMessage::Explicit(value.to_owned()),
}))
}
}
[part, ..] => Some(Err(CommandParseError::UnknownArg {
arg: part.as_key().to_owned(),
did_you_mean: "squash [msg|message=\"<commit-msg>\"]".to_string(),
did_you_mean: "squash [msg|message=\"<commit-msg>\"|description]".to_string(),
})),
},
_ => None,
Expand Down Expand Up @@ -1896,13 +1904,15 @@ for the crater",
#[test]
fn parse_squash() {
let cmds = parse_commands("@bors squash");
assert_eq!(cmds.len(), 1);
assert_eq!(
cmds[0],
Ok(BorsCommand::Squash {
commit_message: None
})
);
insta::assert_debug_snapshot!(cmds, @"
[
Ok(
Squash {
commit_message: AutoGenerate,
},
),
]
");
}

#[test]
Expand All @@ -1912,7 +1922,7 @@ for the crater",
[
Ok(
Squash {
commit_message: Some(
commit_message: Explicit(
"foo",
),
},
Expand All @@ -1928,7 +1938,7 @@ for the crater",
[
Ok(
Squash {
commit_message: Some(
commit_message: Explicit(
"foo",
),
},
Expand All @@ -1944,7 +1954,7 @@ for the crater",
[
Ok(
Squash {
commit_message: Some(
commit_message: Explicit(
"foo bar baz",
),
},
Expand All @@ -1953,6 +1963,20 @@ for the crater",
"#);
}

#[test]
fn parse_squash_msg_description() {
let cmds = parse_commands("@bors squash msg=description");
insta::assert_debug_snapshot!(cmds, @"
[
Ok(
Squash {
commit_message: PullRequestDescription,
},
),
]
");
}

#[test]
fn parse_squash_unknown_arg() {
let cmds = parse_commands("@bors squash commit=foo");
Expand All @@ -1961,7 +1985,7 @@ for the crater",
Err(
UnknownArg {
arg: "commit",
did_you_mean: "squash [msg|message=\"<commit-msg>\"]",
did_you_mean: "squash [msg|message=\"<commit-msg>\"|description]",
},
),
]
Expand All @@ -1975,7 +1999,7 @@ for the crater",
[
Ok(
Squash {
commit_message: Some(
commit_message: Explicit(
"foo",
),
},
Expand Down
3 changes: 2 additions & 1 deletion src/bors/handlers/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ mod tests {
- `try cancel`: Cancel a running try build on the current PR.
- `retry`: Clear a failed auto build status from an approved PR. This will cause the merge queue to eventually attempt to merge the PR again.
- `cancel` | `yield`: Cancel a running auto build on the current PR.
- `squash [msg|message=<commit-message>]`: Squash the commits of a PR into a single commit.
- `squash [msg|message=<commit-message>|description]`: Squash the commits of a PR into a single commit.
- Optionally, you can specify a `<commit-message>` for the created commit. If not specified, the commit messages of all squashed commits will be combined.
- If you specify `msg=description`, then the PR body will be used as the squashed commit message.
- `info`: Get information about the current PR

## Repository management
Expand Down
12 changes: 9 additions & 3 deletions src/bors/handlers/squash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::PgDbClient;
use crate::bors::command::SquashCommitMessage;
use crate::bors::comment::CommentTag;
use crate::bors::gitops_queue::{
GitOpsCommand, GitOpsQueueSender, PullRequestId, PushCallback, PushCommand,
Expand Down Expand Up @@ -27,7 +28,7 @@ pub(super) async fn command_squash(
db: Arc<PgDbClient>,
pr: PullRequestData<'_>,
author: &GithubUser,
commit_message: Option<String>,
commit_message: SquashCommitMessage,
bot_prefix: &CommandPrefix,
gitops_queue: &GitOpsQueueSender,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -142,8 +143,13 @@ pub(super) async fn command_squash(
// Create the squashed commit on the source repository.
// We take the parents of the first commit, and the tree of the last commit, to create the
// squashed commit.
let commit_msg =
commit_message.unwrap_or_else(|| generate_squashed_commit_msg(&pr.github.title, &commits));
let commit_msg = match commit_message {
SquashCommitMessage::AutoGenerate => {
generate_squashed_commit_msg(&pr.github.title, &commits)
}
SquashCommitMessage::PullRequestDescription => pr.github.message.clone(),
SquashCommitMessage::Explicit(msg) => msg,
};
let commit_msg = add_coauthored_authors(commit_msg, &commits, &commit_author);
let commit = match repo_state
.client
Expand Down
3 changes: 2 additions & 1 deletion src/bors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ You can use the following commands:
- `try cancel`: Cancel a running try build on the current PR.
- `retry`: Clear a failed auto build status from an approved PR. This will cause the merge queue to eventually attempt to merge the PR again.
- `cancel` | `yield`: Cancel a running auto build on the current PR.
- `squash [msg|message=<commit-message>]`: Squash the commits of a PR into a single commit.
- `squash [msg|message=<commit-message>|description]`: Squash the commits of a PR into a single commit.
- Optionally, you can specify a `<commit-message>` for the created commit. If not specified, the commit messages of all squashed commits will be combined.
- If you specify `msg=description`, then the PR body will be used as the squashed commit message.
- `info`: Get information about the current PR

## Repository management
Expand Down