@@ -70,9 +70,13 @@ Use `r?` to explicitly pick a reviewer";
70
70
const RETURNING_USER_WELCOME_MESSAGE_NO_REVIEWER : & str =
71
71
"@{author}: no appropriate reviewer found, use `r?` to override" ;
72
72
73
- const ON_VACATION_WARNING : & str = "{username} is on vacation.
73
+ fn on_vacation_warning ( username : & str ) -> String {
74
+ format ! (
75
+ r"{username} is on vacation.
74
76
75
- Please choose another assignee." ;
77
+ Please choose another assignee."
78
+ )
79
+ }
76
80
77
81
pub const SELF_ASSIGN_HAS_NO_CAPACITY : & str = "
78
82
You have insufficient capacity to be assigned the pull request at this time. PR assignment has been reverted.
@@ -215,7 +219,7 @@ pub(super) async fn handle_input(
215
219
fn find_assign_command ( ctx : & Context , event : & IssuesEvent ) -> Option < String > {
216
220
let mut input = Input :: new ( & event. issue . body , vec ! [ & ctx. username] ) ;
217
221
input. find_map ( |command| match command {
218
- Command :: Assign ( Ok ( AssignCommand :: ReviewName { name } ) ) => Some ( name) ,
222
+ Command :: Assign ( Ok ( AssignCommand :: RequestReview { name } ) ) => Some ( name) ,
219
223
_ => None ,
220
224
} )
221
225
}
@@ -458,68 +462,49 @@ pub(super) async fn handle_command(
458
462
. await ?;
459
463
return Ok ( ( ) ) ;
460
464
}
461
- let username = match cmd {
462
- AssignCommand :: Own => event. user ( ) . login . clone ( ) ,
463
- AssignCommand :: User { username } => {
465
+ if matches ! (
466
+ event,
467
+ Event :: Issue ( IssuesEvent {
468
+ action: IssuesAction :: Opened ,
469
+ ..
470
+ } )
471
+ ) {
472
+ // Don't handle review request comments on new PRs. Those will be
473
+ // handled by the new PR trigger (which also handles the
474
+ // welcome message).
475
+ return Ok ( ( ) ) ;
476
+ }
477
+
478
+ let requested_name = match cmd {
479
+ AssignCommand :: Claim => event. user ( ) . login . clone ( ) ,
480
+ AssignCommand :: AssignUser { username } => {
464
481
// Allow users on vacation to assign themselves to a PR, but not anyone else.
465
482
if config. is_on_vacation ( & username)
466
483
&& event. user ( ) . login . to_lowercase ( ) != username. to_lowercase ( )
467
484
{
468
485
// This is a comment, so there must already be a reviewer assigned. No need to assign anyone else.
469
486
issue
470
- . post_comment (
471
- & ctx. github ,
472
- & ON_VACATION_WARNING . replace ( "{username}" , & username) ,
473
- )
487
+ . post_comment ( & ctx. github , & on_vacation_warning ( & username) )
474
488
. await ?;
475
489
return Ok ( ( ) ) ;
476
490
}
477
491
username
478
492
}
479
- AssignCommand :: Release => {
493
+ AssignCommand :: ReleaseAssignment => {
480
494
log:: trace!(
481
495
"ignoring release on PR {:?}, must always have assignee" ,
482
496
issue. global_id( )
483
497
) ;
484
498
return Ok ( ( ) ) ;
485
499
}
486
- AssignCommand :: ReviewName { name } => {
500
+ AssignCommand :: RequestReview { name } => {
487
501
if config. owners . is_empty ( ) {
488
502
// To avoid conflicts with the highfive bot while transitioning,
489
503
// r? is ignored if `owners` is not configured in triagebot.toml.
490
504
return Ok ( ( ) ) ;
491
505
}
492
- if matches ! (
493
- event,
494
- Event :: Issue ( IssuesEvent {
495
- action: IssuesAction :: Opened ,
496
- ..
497
- } )
498
- ) {
499
- // Don't handle r? comments on new PRs. Those will be
500
- // handled by the new PR trigger (which also handles the
501
- // welcome message).
502
- return Ok ( ( ) ) ;
503
- }
504
506
let db_client = ctx. db . get ( ) . await ;
505
507
if is_self_assign ( & name, & event. user ( ) . login ) {
506
- // let work_queue = has_user_capacity(&db_client, &name).await;
507
- // if work_queue.is_err() {
508
- // // NOTE: disabled for now, just log
509
- // log::warn!(
510
- // "[#{}] PR self-assign failed, DB reported that user {} has no review capacity. Ignoring.",
511
- // issue.number,
512
- // name
513
- // );
514
- // // issue
515
- // // .post_comment(
516
- // // &ctx.github,
517
- // // &REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name),
518
- // // )
519
- // // .await?;
520
- // // return Ok(());
521
- // }
522
-
523
508
name. to_string ( )
524
509
} else {
525
510
let teams = crate :: team_data:: teams ( & ctx. github ) . await ?;
@@ -560,7 +545,7 @@ pub(super) async fn handle_command(
560
545
} ;
561
546
562
547
// This user is validated and can accept the PR
563
- set_assignee ( issue, & ctx. github , & username ) . await ;
548
+ set_assignee ( issue, & ctx. github , & requested_name ) . await ;
564
549
// This PR will now be registered in the reviewer's work queue
565
550
// by the `pr_tracking` handler
566
551
return Ok ( ( ) ) ;
@@ -569,14 +554,14 @@ pub(super) async fn handle_command(
569
554
let e = EditIssueBody :: new ( & issue, "ASSIGN" ) ;
570
555
571
556
let to_assign = match cmd {
572
- AssignCommand :: Own => event. user ( ) . login . clone ( ) ,
573
- AssignCommand :: User { username } => {
557
+ AssignCommand :: Claim => event. user ( ) . login . clone ( ) ,
558
+ AssignCommand :: AssignUser { username } => {
574
559
if !is_team_member && username != event. user ( ) . login {
575
560
bail ! ( "Only Rust team members can assign other users" ) ;
576
561
}
577
562
username. clone ( )
578
563
}
579
- AssignCommand :: Release => {
564
+ AssignCommand :: ReleaseAssignment => {
580
565
if let Some ( AssignData {
581
566
user : Some ( current) ,
582
567
} ) = e. current_data ( )
@@ -603,7 +588,7 @@ pub(super) async fn handle_command(
603
588
}
604
589
} ;
605
590
}
606
- AssignCommand :: ReviewName { .. } => bail ! ( "r? is only allowed on PRs." ) ,
591
+ AssignCommand :: RequestReview { .. } => bail ! ( "r? is only allowed on PRs." ) ,
607
592
} ;
608
593
// Don't re-assign if aleady assigned, e.g. on comment edit
609
594
if issue. contain_assignee ( & to_assign) {
@@ -620,7 +605,6 @@ pub(super) async fn handle_command(
620
605
621
606
e. apply ( & ctx. github , String :: new ( ) , & data) . await ?;
622
607
623
- // Assign the PR: user's work queue has been checked and can accept this PR
624
608
match issue. set_assignee ( & ctx. github , & to_assign) . await {
625
609
Ok ( ( ) ) => return Ok ( ( ) ) , // we are done
626
610
Err ( github:: AssignmentError :: InvalidAssignee ) => {
@@ -718,7 +702,7 @@ impl fmt::Display for FindReviewerError {
718
702
write ! ( f, "{}" , NO_REVIEWER_HAS_CAPACITY )
719
703
}
720
704
FindReviewerError :: ReviewerOnVacation { username } => {
721
- write ! ( f, "{}" , ON_VACATION_WARNING . replace ( "{username}" , username) )
705
+ write ! ( f, "{}" , on_vacation_warning ( username) )
722
706
}
723
707
FindReviewerError :: ReviewerIsPrAuthor { username } => {
724
708
write ! (
0 commit comments