Skip to content

Commit 6ea65cd

Browse files
committed
feat: add priority option
1 parent c84d981 commit 6ea65cd

16 files changed

+165
-78
lines changed

.sqlx/query-32c1cd799f8a1e8c451493959419570892d76e7adbc3e5c7b50e97e1bfee27bd.json

-14
This file was deleted.

.sqlx/query-3f7f3b1f86aaa6acdf76f4d597aff4b4c7ac77b9498f77617086b2c12582b971.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-6410d5ac20c9b301fc7b9e639eabc7b82a2a1d01cde48ba01fdc5cd8ce2ce128.json renamed to .sqlx/query-491dd6278535e1015a8071f416a56112a153713a71af8d62917e2ff9873ecec1.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-9531efa35aabadfb04c06f23375eafe1c8f10444e706940fa0f20a50b824044d.json renamed to .sqlx/query-67511f5f15c07537d3d4f2d011abedd2173ab301e8a06c740b587738b140795a.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-7a9718cb973d09f68a6854a4fb08871f29d60b8617caf94dfa439f9ef8453caa.json

-15
This file was deleted.

.sqlx/query-cf60a06c7355a3c94a9728af149a708b0a9c29b8f183d332eab720a53989a598.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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 priority;
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 priority INT;

src/bors/command/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ pub enum Approver {
2323
#[derive(Debug, PartialEq)]
2424
pub enum BorsCommand {
2525
/// Approve a commit.
26-
Approve(Approver),
26+
Approve {
27+
/// Who is approving the commit.
28+
approver: Approver,
29+
/// Priority of the commit.
30+
priority: Option<u32>,
31+
},
2732
/// Unapprove a commit.
2833
Unapprove,
29-
/// Print help
34+
/// Print help.
3035
Help,
3136
/// Ping the bot.
3237
Ping,

src/bors/command/parser.rs

+57-19
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,17 @@ fn parse_parts(input: &str) -> Result<Vec<CommandPart>, CommandParseError> {
119119
/// Parsers
120120
121121
/// Parses "@bors r+"
122-
fn parse_self_approve<'a>(command: &'a str, _parts: &[CommandPart<'a>]) -> ParseResult<'a> {
123-
if command == "r+" {
124-
Some(Ok(BorsCommand::Approve(Approver::Myself)))
125-
} else {
126-
None
122+
fn parse_self_approve<'a>(command: &'a str, parts: &[CommandPart<'a>]) -> ParseResult<'a> {
123+
if command != "r+" {
124+
return None;
125+
}
126+
127+
match parse_priority(parts) {
128+
Ok(priority) => Some(Ok(BorsCommand::Approve {
129+
approver: Approver::Myself,
130+
priority,
131+
})),
132+
Err(e) => Some(Err(e)),
127133
}
128134
}
129135

@@ -135,9 +141,13 @@ fn parse_approve_on_behalf<'a>(parts: &[CommandPart<'a>]) -> ParseResult<'a> {
135141
} else if value.is_empty() {
136142
return Some(Err(CommandParseError::MissingArgValue { arg: "r" }));
137143
} else {
138-
Some(Ok(BorsCommand::Approve(Approver::Specified(
139-
value.to_string(),
140-
))))
144+
match parse_priority(parts) {
145+
Ok(priority) => Some(Ok(BorsCommand::Approve {
146+
approver: Approver::Specified(value.to_string()),
147+
priority,
148+
})),
149+
Err(e) => Some(Err(e)),
150+
}
141151
}
142152
} else {
143153
Some(Err(CommandParseError::MissingArgValue { arg: "r" }))
@@ -241,6 +251,29 @@ fn parser_try_cancel<'a>(command: &'a str, parts: &[CommandPart<'a>]) -> ParseRe
241251
}
242252
}
243253

254+
/// Parses "p=<priority>"
255+
fn parse_priority<'a>(parts: &[CommandPart<'a>]) -> Result<Option<u32>, CommandParseError<'a>> {
256+
for part in parts {
257+
match part {
258+
CommandPart::Bare(key) => {
259+
return Err(CommandParseError::UnknownArg(key));
260+
}
261+
CommandPart::KeyValue { key, value } => {
262+
if *key == "p" {
263+
return match value.parse::<u32>() {
264+
Ok(p) => Ok(Some(p)),
265+
Err(_) => Err(CommandParseError::ValidationError(
266+
"Priority must be a valid number".to_string(),
267+
)),
268+
};
269+
}
270+
}
271+
}
272+
}
273+
274+
Ok(None)
275+
}
276+
244277
#[cfg(test)]
245278
mod tests {
246279
use crate::bors::command::parser::{CommandParseError, CommandParser};
@@ -293,38 +326,43 @@ mod tests {
293326
assert_eq!(cmds.len(), 1);
294327
assert!(matches!(
295328
cmds[0],
296-
Ok(BorsCommand::Approve(Approver::Myself))
329+
Ok(BorsCommand::Approve {
330+
approver: Approver::Myself,
331+
priority: None,
332+
})
297333
));
298334
}
299335

300336
#[test]
301337
fn parse_approve_on_behalf() {
302338
let cmds = parse_commands("@bors r=user1");
303339
assert_eq!(cmds.len(), 1);
304-
insta::assert_debug_snapshot!(cmds[0], @r###"
340+
insta::assert_debug_snapshot!(cmds[0], @r#"
305341
Ok(
306-
Approve(
307-
Specified(
342+
Approve {
343+
approver: Specified(
308344
"user1",
309345
),
310-
),
346+
priority: None,
347+
},
311348
)
312-
"###);
349+
"#);
313350
}
314351

315352
#[test]
316353
fn parse_approve_on_behalf_of_only_one_approver() {
317354
let cmds = parse_commands("@bors r=user1,user2");
318355
assert_eq!(cmds.len(), 1);
319-
insta::assert_debug_snapshot!(cmds[0], @r###"
356+
insta::assert_debug_snapshot!(cmds[0], @r#"
320357
Ok(
321-
Approve(
322-
Specified(
358+
Approve {
359+
approver: Specified(
323360
"user1,user2",
324361
),
325-
),
362+
priority: None,
363+
},
326364
)
327-
"###);
365+
"#);
328366
}
329367

330368
#[test]

src/bors/handlers/help.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ pub(super) async fn command_help(
99
pr: &PullRequest,
1010
) -> anyhow::Result<()> {
1111
let help = [
12-
BorsCommand::Approve(Approver::Myself),
13-
BorsCommand::Approve(Approver::Specified("".to_string())),
12+
BorsCommand::Approve {
13+
approver: Approver::Myself,
14+
priority: None,
15+
},
16+
BorsCommand::Approve {
17+
approver: Approver::Specified("".to_string()),
18+
priority: None,
19+
},
1420
BorsCommand::Unapprove,
1521
BorsCommand::Try {
1622
parent: None,
@@ -34,11 +40,11 @@ pub(super) async fn command_help(
3440
fn get_command_help(command: BorsCommand) -> String {
3541
// !!! When modifying this match, also update the command list above (in [`command_help`]) !!!
3642
let help = match command {
37-
BorsCommand::Approve(Approver::Myself) => {
38-
"`r+`: Approve this PR"
43+
BorsCommand::Approve { approver: Approver::Myself, .. } => {
44+
"`r+ [p=<priority>]`: Approve this PR. Optionally, you can specify a `<priority>`."
3945
}
40-
BorsCommand::Approve(Approver::Specified(_)) => {
41-
"`r=<user>`: Approve this PR on behalf of `<user>`"
46+
BorsCommand::Approve {approver: Approver::Specified(_), ..} => {
47+
"`r=<user> [p=<priority>]`: Approve this PR on behalf of `<user>`. Optionally, you can specify a `<priority>`."
4248
}
4349
BorsCommand::Unapprove => {
4450
"`r-`: Unapprove this PR"
@@ -68,8 +74,8 @@ mod tests {
6874
run_test(pool, |mut tester| async {
6975
tester.post_comment("@bors help").await?;
7076
insta::assert_snapshot!(tester.get_comment().await?, @r"
71-
- `r+`: Approve this PR
72-
- `r=<user>`: Approve this PR on behalf of `<user>`
77+
- `r+ [p=<priority>]`: Approve this PR. Optionally, you can specify a `<priority>`.
78+
- `r=<user> [p=<priority>]`: Approve this PR on behalf of `<user>`. Optionally, you can specify a `<priority>`.
7379
- `r-`: Unapprove this PR
7480
- `try [parent=<parent>] [jobs=<jobs>]`: Start a try build. Optionally, you can specify a `<parent>` SHA or a list of `<jobs>` to run
7581
- `try cancel`: Cancel a running try build

src/bors/handlers/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,18 @@ async fn handle_comment(
205205
let repo = Arc::clone(&repo);
206206
let database = Arc::clone(&database);
207207
let result = match command {
208-
BorsCommand::Approve(approver) => {
208+
BorsCommand::Approve { approver, priority } => {
209209
let span = tracing::info_span!("Approve");
210-
command_approve(repo, database, &pull_request, &comment.author, &approver)
211-
.instrument(span)
212-
.await
210+
command_approve(
211+
repo,
212+
database,
213+
&pull_request,
214+
&comment.author,
215+
&approver,
216+
priority,
217+
)
218+
.instrument(span)
219+
.await
213220
}
214221
BorsCommand::Unapprove => {
215222
let span = tracing::info_span!("Unapprove");

0 commit comments

Comments
 (0)