Skip to content

Commit 8e279bf

Browse files
committed
tree_opening_closing
1 parent 4559447 commit 8e279bf

13 files changed

+395
-10
lines changed

.sqlx/query-6a911b59abd89bdb10e283902ea3a08c483e5a6238344c7ac969a0602674e888.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-6d68067c7121438630d77590ed644d4bc654978836fe5ceda2f0041aeba68e64.json

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add down migration script here
2+
DROP TABLE IF EXISTS repository;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Add up migration script here
2+
CREATE TABLE repository
3+
(
4+
id SERIAL PRIMARY KEY,
5+
name TEXT NOT NULL UNIQUE,
6+
tree_state INT NULL,
7+
treeclosed_src TEXT,
8+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
9+
);

src/bors/command/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ pub enum BorsCommand {
9999
Undelegate,
100100
/// Set the rollup mode of a PRstatus.
101101
SetRollupMode(RollupMode),
102+
/// Open the repository tree for merging.
103+
OpenTree,
104+
/// Set the tree closed with a priority level.
105+
TreeClosed(Priority),
102106
}

src/bors/command/parser.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum CommandParseError<'a> {
1919
}
2020

2121
/// Part of a command, either a bare string like `try` or a key value like `parent=<sha>`.
22-
#[derive(PartialEq)]
22+
#[derive(PartialEq, Copy, Clone)]
2323
enum CommandPart<'a> {
2424
Bare(&'a str),
2525
KeyValue { key: &'a str, value: &'a str },
@@ -68,6 +68,7 @@ const PARSERS: &[for<'b> fn(&CommandPart<'b>, &[CommandPart<'b>]) -> ParseResult
6868
parser_info,
6969
parser_help,
7070
parser_ping,
71+
parser_tree_ops,
7172
];
7273

7374
fn parse_command(input: &str) -> ParseResult {
@@ -313,6 +314,24 @@ fn parser_info<'a>(command: &CommandPart<'a>, _parts: &[CommandPart<'a>]) -> Par
313314
}
314315
}
315316

317+
/// Parses `@bors treeclosed-` and `@bors treeclosed=<priority>`
318+
fn parser_tree_ops<'a>(command: &CommandPart<'a>, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
319+
match command {
320+
CommandPart::Bare("treeclosed-") => Some(Ok(BorsCommand::OpenTree)),
321+
CommandPart::KeyValue {
322+
key: "treeclosed",
323+
value,
324+
} => {
325+
let priority = match parse_priority_value(value) {
326+
Ok(p) => p,
327+
Err(error) => return Some(Err(error)),
328+
};
329+
Some(Ok(BorsCommand::TreeClosed(priority)))
330+
}
331+
_ => None,
332+
}
333+
}
334+
316335
#[cfg(test)]
317336
mod tests {
318337
use crate::bors::command::parser::{CommandParseError, CommandParser};
@@ -1010,6 +1029,50 @@ line two
10101029
assert_eq!(cmds[0], Ok(BorsCommand::Delegate));
10111030
}
10121031

1032+
#[test]
1033+
fn parse_tree_closed() {
1034+
let cmds = parse_commands("@bors treeclosed=5");
1035+
assert_eq!(cmds.len(), 1);
1036+
assert_eq!(cmds[0], Ok(BorsCommand::TreeClosed(5)));
1037+
}
1038+
1039+
#[test]
1040+
fn parse_tree_closed_invalid() {
1041+
let cmds = parse_commands("@bors treeclosed=abc");
1042+
assert_eq!(cmds.len(), 1);
1043+
assert!(matches!(
1044+
cmds[0],
1045+
Err(CommandParseError::ValidationError(_))
1046+
));
1047+
}
1048+
1049+
#[test]
1050+
fn parse_tree_closed_empty() {
1051+
let cmds = parse_commands("@bors treeclosed=");
1052+
assert_eq!(cmds.len(), 1);
1053+
assert!(matches!(
1054+
cmds[0],
1055+
Err(CommandParseError::MissingArgValue { arg: "treeclosed" })
1056+
));
1057+
}
1058+
1059+
#[test]
1060+
fn parse_tree_closed_minus() {
1061+
let cmds = parse_commands("@bors treeclosed-");
1062+
assert_eq!(cmds.len(), 1);
1063+
assert_eq!(cmds[0], Ok(BorsCommand::OpenTree));
1064+
}
1065+
1066+
#[test]
1067+
fn parse_tree_closed_unknown_command() {
1068+
let cmds = parse_commands("@bors tree closed 5");
1069+
assert_eq!(cmds.len(), 1);
1070+
assert!(matches!(
1071+
cmds[0],
1072+
Err(CommandParseError::UnknownCommand("tree"))
1073+
));
1074+
}
1075+
10131076
fn parse_commands(text: &str) -> Vec<Result<BorsCommand, CommandParseError>> {
10141077
CommandParser::new("@bors".to_string()).parse_commands(text)
10151078
}

src/bors/handlers/help.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub(super) async fn command_help(
3232
BorsCommand::Info,
3333
BorsCommand::Ping,
3434
BorsCommand::Help,
35+
BorsCommand::OpenTree,
36+
BorsCommand::TreeClosed(0),
3537
]
3638
.into_iter()
3739
.map(|help| format!("- {}", get_command_help(help)))
@@ -83,7 +85,12 @@ fn get_command_help(command: BorsCommand) -> String {
8385
BorsCommand::Info => {
8486
"`info`: Get information about the current PR including delegation, priority, merge status, and try build status"
8587
}
86-
88+
BorsCommand::OpenTree => {
89+
"`treeclosed-`: Open the repository tree for merging"
90+
}
91+
BorsCommand::TreeClosed(_) => {
92+
"`treeclosed=<priority>`: Close the tree for PRs with priority less than `<priority>`"
93+
}
8794
};
8895
help.to_string()
8996
}
@@ -109,6 +116,8 @@ mod tests {
109116
- `info`: Get information about the current PR including delegation, priority, merge status, and try build status
110117
- `ping`: Check if the bot is alive
111118
- `help`: Print this help message
119+
- `treeclosed-`: Open the repository tree for merging
120+
- `treeclosed=<priority>`: Close the tree for PRs with priority less than `<priority>`
112121
");
113122
Ok(tester)
114123
})

src/bors/handlers/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::bors::handlers::help::command_help;
66
use crate::bors::handlers::info::command_info;
77
use crate::bors::handlers::ping::command_ping;
88
use crate::bors::handlers::refresh::refresh_repository;
9-
use crate::bors::handlers::review::{command_approve, command_unapprove};
9+
use crate::bors::handlers::review::{
10+
command_approve, command_close_tree, command_open_tree, command_unapprove,
11+
};
1012
use crate::bors::handlers::trybuild::{command_try_build, command_try_cancel, TRY_BRANCH_NAME};
1113
use crate::bors::handlers::workflow::{
1214
handle_check_suite_completed, handle_workflow_completed, handle_workflow_started,
@@ -86,7 +88,6 @@ pub async fn handle_bors_repository_event(
8688
return Err(error.context("Cannot perform command"));
8789
}
8890
}
89-
9091
BorsRepositoryEvent::WorkflowStarted(payload) => {
9192
let span = tracing::info_span!(
9293
"Workflow started",
@@ -227,6 +228,18 @@ async fn handle_comment(
227228
.instrument(span)
228229
.await
229230
}
231+
BorsCommand::OpenTree => {
232+
let span = tracing::info_span!("TreeOpen");
233+
command_open_tree(repo, database, &pull_request, &comment.author)
234+
.instrument(span)
235+
.await
236+
}
237+
BorsCommand::TreeClosed(priority) => {
238+
let span = tracing::info_span!("TreeClosed");
239+
command_close_tree(repo, database, &pull_request, &comment.author, priority)
240+
.instrument(span)
241+
.await
242+
}
230243
BorsCommand::Unapprove => {
231244
let span = tracing::info_span!("Unapprove");
232245
command_unapprove(repo, database, &pull_request, &comment.author)

0 commit comments

Comments
 (0)