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

Lines changed: 0 additions & 14 deletions
This file was deleted.

.sqlx/query-3f7f3b1f86aaa6acdf76f4d597aff4b4c7ac77b9498f77617086b2c12582b971.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-6410d5ac20c9b301fc7b9e639eabc7b82a2a1d01cde48ba01fdc5cd8ce2ce128.json renamed to .sqlx/query-491dd6278535e1015a8071f416a56112a153713a71af8d62917e2ff9873ecec1.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-9531efa35aabadfb04c06f23375eafe1c8f10444e706940fa0f20a50b824044d.json renamed to .sqlx/query-67511f5f15c07537d3d4f2d011abedd2173ab301e8a06c740b587738b140795a.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-7a9718cb973d09f68a6854a4fb08871f29d60b8617caf94dfa439f9ef8453caa.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

.sqlx/query-cf60a06c7355a3c94a9728af149a708b0a9c29b8f183d332eab720a53989a598.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.
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 priority;
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 priority INT;

src/bors/command/mod.rs

Lines changed: 7 additions & 2 deletions
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

Lines changed: 57 additions & 19 deletions
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]

0 commit comments

Comments
 (0)