Skip to content

Commit bb5711d

Browse files
committed
Add test and refactor parsing slightly
1 parent 1c0968b commit bb5711d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

site/src/request_handlers/github.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ async fn handle_rust_timer(
165165
fn parse_queue_command(body: &str) -> Option<Result<QueueCommand, String>> {
166166
let prefix = "@rust-timer";
167167
let bot_line = body.lines().find_map(|line| {
168-
let line = line.trim();
169168
line.find(prefix)
170169
.map(|index| line[index + prefix.len()..].trim())
171170
})?;
@@ -187,8 +186,11 @@ fn parse_queue_command(body: &str) -> Option<Result<QueueCommand, String>> {
187186
cmd.runs = Some(runs as i32);
188187
}
189188

190-
if let Some((key, _)) = args.into_iter().next() {
191-
return Some(Err(format!("Unknown command argument {key}")));
189+
if !args.is_empty() {
190+
return Some(Err(format!(
191+
"Unknown command argument(s) `{}`",
192+
args.into_keys().collect::<Vec<_>>().join(",")
193+
)));
192194
}
193195

194196
Some(Ok(cmd))
@@ -295,7 +297,7 @@ Going to do perf runs for a few of these:
295297
#[test]
296298
fn queue_command_unknown_arg() {
297299
insta::assert_compact_debug_snapshot!(parse_queue_command("@rust-timer queue foo=bar"),
298-
@r###"Some(Err("Unknown command argument foo"))"###);
300+
@r###"Some(Err("Unknown command argument(s) `foo`"))"###);
299301
}
300302

301303
#[test]
@@ -351,4 +353,10 @@ Going to do perf runs for a few of these:
351353
insta::assert_compact_debug_snapshot!(parse_queue_command("@bors try @rust-timer queue include=foo,bar"),
352354
@r###"Some(Ok(QueueCommand { include: Some("foo,bar"), exclude: None, runs: None }))"###);
353355
}
356+
357+
#[test]
358+
fn queue_command_parameter_order() {
359+
insta::assert_compact_debug_snapshot!(parse_queue_command("@rust-timer queue runs=3 exclude=c,a include=b"),
360+
@r###"Some(Ok(QueueCommand { include: Some("b"), exclude: Some("c,a"), runs: Some(3) }))"###);
361+
}
354362
}

0 commit comments

Comments
 (0)