@@ -120,8 +120,13 @@ async fn handle_rust_timer(
120
120
let msg = match queue {
121
121
Ok ( cmd) => {
122
122
let conn = ctxt. conn ( ) . await ;
123
- conn. queue_pr ( issue. number , cmd. include , cmd. exclude , cmd. runs )
124
- . await ;
123
+ conn. queue_pr (
124
+ issue. number ,
125
+ cmd. params . include ,
126
+ cmd. params . exclude ,
127
+ cmd. params . runs ,
128
+ )
129
+ . await ;
125
130
format ! (
126
131
"Awaiting bors try build completion.
127
132
@@ -160,40 +165,59 @@ async fn handle_rust_timer(
160
165
Ok ( github:: Response )
161
166
}
162
167
163
- /// Parses the first occurrence of a `@rust-timer queue <... >` command
168
+ /// Parses the first occurrence of a `@rust-timer queue <shared-args >` command
164
169
/// in the input string.
165
170
fn parse_queue_command ( body : & str ) -> Option < Result < QueueCommand , String > > {
166
- let prefix = "@rust-timer" ;
167
- let bot_line = body. lines ( ) . find_map ( |line| {
168
- line. find ( prefix)
169
- . map ( |index| line[ index + prefix. len ( ) ..] . trim ( ) )
170
- } ) ?;
171
-
172
- let args = bot_line. strip_prefix ( "queue" ) . map ( |l| l. trim ( ) ) ?;
173
- let mut args = match parse_command_arguments ( args) {
171
+ let args = get_command_lines ( body, "queue" ) . next ( ) ?;
172
+ let args = match parse_command_arguments ( args) {
174
173
Ok ( args) => args,
175
174
Err ( error) => return Some ( Err ( error) ) ,
176
175
} ;
177
- let mut cmd = QueueCommand {
176
+ let params = match parse_benchmark_parameters ( args) {
177
+ Ok ( params) => params,
178
+ Err ( error) => return Some ( Err ( error) ) ,
179
+ } ;
180
+
181
+ Some ( Ok ( QueueCommand { params } ) )
182
+ }
183
+
184
+ fn get_command_lines < ' a : ' b , ' b > (
185
+ body : & ' a str ,
186
+ command : & ' b str ,
187
+ ) -> impl Iterator < Item = & ' a str > + ' b {
188
+ let prefix = "@rust-timer" ;
189
+ body. lines ( )
190
+ . filter_map ( move |line| {
191
+ line. find ( prefix)
192
+ . map ( |index| line[ index + prefix. len ( ) ..] . trim ( ) )
193
+ } )
194
+ . filter_map ( move |line| line. strip_prefix ( command) )
195
+ . map ( move |l| l. trim ( ) )
196
+ }
197
+
198
+ fn parse_benchmark_parameters < ' a > (
199
+ mut args : HashMap < & ' a str , & ' a str > ,
200
+ ) -> Result < BenchmarkParameters < ' a > , String > {
201
+ let mut params = BenchmarkParameters {
178
202
include : args. remove ( "include" ) ,
179
203
exclude : args. remove ( "exclude" ) ,
180
204
runs : None ,
181
205
} ;
182
206
if let Some ( runs) = args. remove ( "runs" ) {
183
207
let Ok ( runs) = runs. parse :: < u32 > ( ) else {
184
- return Some ( Err ( format ! ( "Cannot parse runs {runs} as a number" ) ) ) ;
208
+ return Err ( format ! ( "Cannot parse runs {runs} as a number" ) ) ;
185
209
} ;
186
- cmd . runs = Some ( runs as i32 ) ;
210
+ params . runs = Some ( runs as i32 ) ;
187
211
}
188
212
189
213
if !args. is_empty ( ) {
190
- return Some ( Err ( format ! (
214
+ Err ( format ! (
191
215
"Unknown command argument(s) `{}`" ,
192
216
args. into_keys( ) . collect:: <Vec <_>>( ) . join( "," )
193
- ) ) ) ;
217
+ ) )
218
+ } else {
219
+ Ok ( params)
194
220
}
195
-
196
- Some ( Ok ( cmd) )
197
221
}
198
222
199
223
/// Parses command arguments from a single line of text.
@@ -219,6 +243,11 @@ fn parse_command_arguments(args: &str) -> Result<HashMap<&str, &str>, String> {
219
243
220
244
#[ derive( Debug ) ]
221
245
struct QueueCommand < ' a > {
246
+ params : BenchmarkParameters < ' a > ,
247
+ }
248
+
249
+ #[ derive( Debug ) ]
250
+ struct BenchmarkParameters < ' a > {
222
251
include : Option < & ' a str > ,
223
252
exclude : Option < & ' a str > ,
224
253
runs : Option < i32 > ,
@@ -291,7 +320,7 @@ Going to do perf runs for a few of these:
291
320
#[ test]
292
321
fn queue_command ( ) {
293
322
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue" ) ,
294
- @"Some(Ok(QueueCommand { include: None, exclude: None, runs: None }))" ) ;
323
+ @"Some(Ok(QueueCommand { params: BenchmarkParameters { include: None, exclude: None, runs: None } }))" ) ;
295
324
}
296
325
297
326
#[ test]
@@ -309,19 +338,19 @@ Going to do perf runs for a few of these:
309
338
#[ test]
310
339
fn queue_command_include ( ) {
311
340
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue include=abcd,feih" ) ,
312
- @r###"Some(Ok(QueueCommand { include: Some("abcd,feih"), exclude: None, runs: None }))"### ) ;
341
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: Some("abcd,feih"), exclude: None, runs: None } }))"### ) ;
313
342
}
314
343
315
344
#[ test]
316
345
fn queue_command_exclude ( ) {
317
346
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue exclude=foo134,barzbaz41baf" ) ,
318
- @r###"Some(Ok(QueueCommand { include: None, exclude: Some("foo134,barzbaz41baf"), runs: None }))"### ) ;
347
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: None, exclude: Some("foo134,barzbaz41baf"), runs: None } }))"### ) ;
319
348
}
320
349
321
350
#[ test]
322
351
fn queue_command_runs ( ) {
323
352
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue runs=5" ) ,
324
- @"Some(Ok(QueueCommand { include: None, exclude: None, runs: Some(5) }))" ) ;
353
+ @"Some(Ok(QueueCommand { params: BenchmarkParameters { include: None, exclude: None, runs: Some(5) } }))" ) ;
325
354
}
326
355
327
356
#[ test]
@@ -333,7 +362,7 @@ Going to do perf runs for a few of these:
333
362
#[ test]
334
363
fn queue_command_combination ( ) {
335
364
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue include=acda,13asd exclude=c13,DA runs=5" ) ,
336
- @r###"Some(Ok(QueueCommand { include: Some("acda,13asd"), exclude: Some("c13,DA"), runs: Some(5) }))"### ) ;
365
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: Some("acda,13asd"), exclude: Some("c13,DA"), runs: Some(5) } }))"### ) ;
337
366
}
338
367
339
368
#[ test]
@@ -345,18 +374,18 @@ Going to do perf runs for a few of these:
345
374
#[ test]
346
375
fn queue_command_spaces ( ) {
347
376
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@rust-timer queue include=abcd,das " ) ,
348
- @r###"Some(Ok(QueueCommand { include: Some("abcd,das"), exclude: None, runs: None }))"### ) ;
377
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: Some("abcd,das"), exclude: None, runs: None } }))"### ) ;
349
378
}
350
379
351
380
#[ test]
352
381
fn queue_command_with_bors ( ) {
353
382
insta:: assert_compact_debug_snapshot!( parse_queue_command( "@bors try @rust-timer queue include=foo,bar" ) ,
354
- @r###"Some(Ok(QueueCommand { include: Some("foo,bar"), exclude: None, runs: None }))"### ) ;
383
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: Some("foo,bar"), exclude: None, runs: None } }))"### ) ;
355
384
}
356
385
357
386
#[ test]
358
387
fn queue_command_parameter_order ( ) {
359
388
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) }))"### ) ;
389
+ @r###"Some(Ok(QueueCommand { params: BenchmarkParameters { include: Some("b"), exclude: Some("c,a"), runs: Some(3) } }))"### ) ;
361
390
}
362
391
}
0 commit comments