1
1
use crate :: db:: notifications:: add_metadata;
2
2
use crate :: db:: notifications:: { self , delete_ping, move_indices, record_ping, Identifier } ;
3
- use crate :: db:: review_prefs:: { get_review_prefs, upsert_review_prefs} ;
3
+ use crate :: db:: review_prefs:: { get_review_prefs, upsert_review_prefs, RotationMode } ;
4
4
use crate :: github:: { get_id_for_username, GithubClient , User } ;
5
5
use crate :: handlers:: docs_update:: docs_update;
6
6
use crate :: handlers:: pr_tracking:: get_assigned_prs;
@@ -270,6 +270,15 @@ async fn workqueue_commands(
270
270
271
271
let db_client = ctx. db . get ( ) . await ;
272
272
273
+ let gh_username = username_from_gh_id ( & ctx. github , gh_id)
274
+ . await ?
275
+ . ok_or_else ( || anyhow:: anyhow!( "Cannot find your GitHub username in the team database" ) ) ?;
276
+ let user = User {
277
+ login : gh_username. clone ( ) ,
278
+ id : gh_id,
279
+ } ;
280
+ let review_prefs = get_review_prefs ( & db_client, gh_id) . await ?;
281
+
273
282
let response = match subcommand {
274
283
"show" => {
275
284
let mut assigned_prs = get_assigned_prs ( ctx, gh_id)
@@ -287,17 +296,26 @@ async fn workqueue_commands(
287
296
let review_prefs = get_review_prefs ( & db_client, gh_id)
288
297
. await
289
298
. context ( "cannot get review preferences" ) ?;
290
- let capacity = match review_prefs. and_then ( |p| p. max_assigned_prs ) {
299
+ let capacity = match review_prefs. as_ref ( ) . and_then ( |p| p. max_assigned_prs ) {
291
300
Some ( max) => max. to_string ( ) ,
292
301
None => String :: from ( "Not set (i.e. unlimited)" ) ,
293
302
} ;
303
+ let rotation_mode = review_prefs
304
+ . as_ref ( )
305
+ . map ( |p| p. rotation_mode )
306
+ . unwrap_or_default ( ) ;
307
+ let rotation_mode = match rotation_mode {
308
+ RotationMode :: OnRotation => "on rotation" ,
309
+ RotationMode :: OffRotation => "off rotation" ,
310
+ } ;
294
311
295
312
let mut response = format ! (
296
313
"`rust-lang/rust` PRs in your review queue: {prs} ({} {})\n " ,
297
314
assigned_prs. len( ) ,
298
315
pluralize( "PR" , assigned_prs. len( ) )
299
316
) ;
300
317
writeln ! ( response, "Review capacity: {capacity}\n " ) ?;
318
+ writeln ! ( response, "Rotation mode: *{rotation_mode}*\n " ) ?;
301
319
writeln ! ( response, "*Note that only certain PRs that are assigned to you are included in your review queue.*" ) ?;
302
320
response
303
321
}
@@ -315,21 +333,16 @@ async fn workqueue_commands(
315
333
) ?)
316
334
}
317
335
}
318
- None => anyhow:: bail!( "Missing parameter." ) ,
319
- } ;
320
- let gh_username = username_from_gh_id ( & ctx. github , gh_id)
321
- . await ?
322
- . ok_or_else ( || {
323
- anyhow:: anyhow!( "Cannot find your GitHub username in the team database" )
324
- } ) ?;
325
-
326
- let user = User {
327
- login : gh_username. clone ( ) ,
328
- id : gh_id,
336
+ None => anyhow:: bail!( "Missing parameter. See `work help` for more information." ) ,
329
337
} ;
330
- upsert_review_prefs ( & db_client, user, max_assigned_prs)
331
- . await
332
- . context ( "Error occurred while setting review preferences." ) ?;
338
+ upsert_review_prefs (
339
+ & db_client,
340
+ user,
341
+ max_assigned_prs,
342
+ review_prefs. map ( |p| p. rotation_mode ) . unwrap_or_default ( ) ,
343
+ )
344
+ . await
345
+ . context ( "Error occurred while setting review preferences." ) ?;
333
346
tracing:: info!( "Setting max assignment PRs of `{gh_username}` to {max_assigned_prs:?}" ) ;
334
347
format ! (
335
348
"Review capacity set to {}" ,
@@ -339,8 +352,37 @@ async fn workqueue_commands(
339
352
}
340
353
)
341
354
}
342
- "help" => r"work show => show your assigned PRs
343
- work set-pr-limit <number>|unlimited => set the maximum number of PRs you can be assigned to"
355
+ "set-rotation-mode" => {
356
+ let rotation_mode = match words. next ( ) {
357
+ Some ( value) => {
358
+ if words. next ( ) . is_some ( ) {
359
+ anyhow:: bail!( "Too many parameters." ) ;
360
+ }
361
+ match value {
362
+ "on" => RotationMode :: OnRotation ,
363
+ "off" => RotationMode :: OffRotation ,
364
+ _ => anyhow:: bail!( "Unknown rotation mode {value}. Use `on` or `off`." )
365
+ }
366
+ }
367
+ None => anyhow:: bail!( "Missing parameter. See `work help` for more information." ) ,
368
+ } ;
369
+ upsert_review_prefs (
370
+ & db_client,
371
+ user,
372
+ review_prefs. and_then ( |p| p. max_assigned_prs . map ( |v| v as u32 ) ) ,
373
+ rotation_mode,
374
+ )
375
+ . await
376
+ . context ( "Error occurred while setting review preferences." ) ?;
377
+ tracing:: info!( "Setting rotation mode `{gh_username}` to {rotation_mode:?}" ) ;
378
+ format ! (
379
+ "Rotation mode set to {rotation_mode:?}"
380
+ )
381
+ }
382
+ "help" => r"`work show`: show your assigned PRs
383
+ `work set-pr-limit <number>|unlimited`: set the maximum number of PRs you can be assigned to
384
+ `work set-rotation-mode <off|on>`: configure if you are *on* rotation or *off* rotation (e.g. when you are on a vacation)
385
+ "
344
386
. to_string ( ) ,
345
387
_ => anyhow:: bail!( "Invalid subcommand." ) ,
346
388
} ;
0 commit comments