Skip to content

Commit ab5d8a7

Browse files
committed
feat: add delegation commands
1 parent 3b95f4d commit ab5d8a7

16 files changed

+508
-61
lines changed

.sqlx/query-71942069bc62e1dbedca845779de5f3d0a6878caf78ee0d600bb2c8fe30036fd.json

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

.sqlx/query-491dd6278535e1015a8071f416a56112a153713a71af8d62917e2ff9873ecec1.json renamed to .sqlx/query-c4b0d4ed216c6b8efceb1b65ae0ad9d830e8870cfdf37542a408b99c961318f7.json

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

.sqlx/query-c9d86eebfcadcae17f8a5e7e31f0e7c14ea0eabe866a27fbdedbddcc0166af43.json

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

.sqlx/query-67511f5f15c07537d3d4f2d011abedd2173ab301e8a06c740b587738b140795a.json renamed to .sqlx/query-f223617621c400f216ecfe415f0bf54a0f8cfb8aecace69b5d53cb888e5c9fa4.json

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

docs/commands.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ which is by default set to `@bors`.
88
| `try` | `try` | Start a try build based on the most recent commit from the main branch. |
99
| `try parent=<sha>` | `try` | Start a try build based on the specified parent commit `sha`. |
1010
| `try cancel` | `try` | Cancel a running try build. |
11-
| `p=<priority>` | `try` | Set the priority of a PR. |
11+
| `p=<priority>` | `review` | Set the priority of a PR. |
12+
| `delegate+` | `review` | Delegate approval authority to the PR author. |
13+
| `delegate-` | `review` | Remove any previously granted delegation. |
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+
ALTER TABLE pull_request DROP COLUMN delegated;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Add up migration script here
2+
ALTER TABLE pull_request ADD COLUMN delegated BOOLEAN NOT NULL DEFAULT FALSE;

src/bors/command/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ pub enum BorsCommand {
4949
TryCancel,
5050
/// Set the priority of a commit.
5151
SetPriority(Priority),
52+
/// Delegate approval authority to the pull request author.
53+
Delegate,
54+
/// Revoke any previously granted delegation.
55+
Undelegate,
5256
}

src/bors/command/parser.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ impl CommandParser {
5151
parser_ping,
5252
parser_try_cancel,
5353
parser_try,
54+
parse_delegate_author,
55+
parse_undelegate,
5456
];
5557

5658
text.lines()
@@ -152,6 +154,7 @@ fn parse_approve_on_behalf<'a>(parts: &[CommandPart<'a>]) -> ParseResult<'a> {
152154
if value.is_empty() {
153155
return Some(Err(CommandParseError::MissingArgValue { arg: "r" }));
154156
}
157+
155158
match parse_priority_arg(&parts[1..]) {
156159
Ok(priority) => Some(Ok(BorsCommand::Approve {
157160
approver: Approver::Specified(value.to_string()),
@@ -270,6 +273,24 @@ fn parser_try_cancel<'a>(command: &'a str, parts: &[CommandPart<'a>]) -> ParseRe
270273
}
271274
}
272275

276+
/// Parses "@bors delegate+"
277+
fn parse_delegate_author<'a>(command: &'a str, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
278+
if command == "delegate+" {
279+
Some(Ok(BorsCommand::Delegate))
280+
} else {
281+
None
282+
}
283+
}
284+
285+
/// Parses "@bors delegate-"
286+
fn parse_undelegate<'a>(command: &'a str, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
287+
if command == "delegate-" {
288+
Some(Ok(BorsCommand::Undelegate))
289+
} else {
290+
None
291+
}
292+
}
293+
273294
/// Parses "@bors p=<priority>"
274295
fn parse_priority<'a>(parts: &[CommandPart<'a>]) -> ParseResult<'a> {
275296
// If we have more than one part, check for duplicate priority arguments
@@ -821,6 +842,27 @@ line two
821842
assert!(matches!(cmds[0], Ok(BorsCommand::TryCancel)));
822843
}
823844

845+
#[test]
846+
fn parse_delegate_author() {
847+
let cmds = parse_commands("@bors delegate+");
848+
assert_eq!(cmds.len(), 1);
849+
assert!(matches!(cmds[0], Ok(BorsCommand::Delegate)));
850+
}
851+
852+
#[test]
853+
fn parse_undelegate() {
854+
let cmds = parse_commands("@bors delegate-");
855+
assert_eq!(cmds.len(), 1);
856+
assert_eq!(cmds[0], Ok(BorsCommand::Undelegate));
857+
}
858+
859+
#[test]
860+
fn parse_delegate_author_unknown_arg() {
861+
let cmds = parse_commands("@bors delegate+ a");
862+
assert_eq!(cmds.len(), 1);
863+
assert_eq!(cmds[0], Ok(BorsCommand::Delegate));
864+
}
865+
824866
fn parse_commands(text: &str) -> Vec<Result<BorsCommand, CommandParseError>> {
825867
CommandParser::new("@bors".to_string()).parse_commands(text)
826868
}

src/bors/handlers/help.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub(super) async fn command_help(
1919
},
2020
BorsCommand::Unapprove,
2121
BorsCommand::SetPriority(0),
22+
BorsCommand::Delegate,
23+
BorsCommand::Undelegate,
2224
BorsCommand::Try {
2325
parent: None,
2426
jobs: vec![],
@@ -53,6 +55,12 @@ fn get_command_help(command: BorsCommand) -> String {
5355
BorsCommand::SetPriority(_) => {
5456
"`p=<priority>`: Set the priority of this PR"
5557
}
58+
BorsCommand::Delegate => {
59+
"`delegate+`: Delegate approval authority to the PR author"
60+
}
61+
BorsCommand::Undelegate => {
62+
"`delegate-`: Remove any previously granted delegation"
63+
}
5664
BorsCommand::Help => {
5765
"`help`: Print this help message"
5866
}
@@ -82,6 +90,8 @@ mod tests {
8290
- `r=<user> [p=<priority>]`: Approve this PR on behalf of `<user>`. Optionally, you can specify a `<priority>`.
8391
- `r-`: Unapprove this PR
8492
- `p=<priority>`: Set the priority of this PR
93+
- `delegate+`: Delegate approval authority to the PR author
94+
- `delegate-`: Remove any previously granted delegation
8595
- `try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run
8696
- `try cancel`: Cancel a running try build
8797
- `ping`: Check if the bot is alive

0 commit comments

Comments
 (0)