20
20
//! `assign.owners` config, it will auto-select an assignee based on the files
21
21
//! the PR modifies.
22
22
23
+ use crate :: handlers:: pr_tracking:: ReviewerWorkqueue ;
23
24
use crate :: {
24
25
config:: AssignConfig ,
25
26
github:: { self , Event , FileDiff , Issue , IssuesAction , Selection } ,
@@ -33,6 +34,8 @@ use rand::seq::IteratorRandom;
33
34
use rust_team_data:: v1:: Teams ;
34
35
use std:: collections:: { HashMap , HashSet } ;
35
36
use std:: fmt;
37
+ use std:: sync:: Arc ;
38
+ use tokio:: sync:: RwLock ;
36
39
use tokio_postgres:: Client as DbClient ;
37
40
use tracing as log;
38
41
@@ -299,7 +302,16 @@ async fn determine_assignee(
299
302
let teams = crate :: team_data:: teams ( & ctx. github ) . await ?;
300
303
if let Some ( name) = assign_command {
301
304
// User included `r?` in the opening PR body.
302
- match find_reviewer_from_names ( & db_client, & teams, config, & event. issue , & [ name] ) . await {
305
+ match find_reviewer_from_names (
306
+ & db_client,
307
+ ctx. workqueue . clone ( ) ,
308
+ & teams,
309
+ config,
310
+ & event. issue ,
311
+ & [ name] ,
312
+ )
313
+ . await
314
+ {
303
315
Ok ( assignee) => return Ok ( ( Some ( assignee) , true ) ) ,
304
316
Err ( e) => {
305
317
event
@@ -313,8 +325,15 @@ async fn determine_assignee(
313
325
// Errors fall-through to try fallback group.
314
326
match find_reviewers_from_diff ( config, diff) {
315
327
Ok ( candidates) if !candidates. is_empty ( ) => {
316
- match find_reviewer_from_names ( & db_client, & teams, config, & event. issue , & candidates)
317
- . await
328
+ match find_reviewer_from_names (
329
+ & db_client,
330
+ ctx. workqueue . clone ( ) ,
331
+ & teams,
332
+ config,
333
+ & event. issue ,
334
+ & candidates,
335
+ )
336
+ . await
318
337
{
319
338
Ok ( assignee) => return Ok ( ( Some ( assignee) , false ) ) ,
320
339
Err ( FindReviewerError :: TeamNotFound ( team) ) => log:: warn!(
@@ -344,7 +363,16 @@ async fn determine_assignee(
344
363
}
345
364
346
365
if let Some ( fallback) = config. adhoc_groups . get ( "fallback" ) {
347
- match find_reviewer_from_names ( & db_client, & teams, config, & event. issue , fallback) . await {
366
+ match find_reviewer_from_names (
367
+ & db_client,
368
+ ctx. workqueue . clone ( ) ,
369
+ & teams,
370
+ config,
371
+ & event. issue ,
372
+ fallback,
373
+ )
374
+ . await
375
+ {
348
376
Ok ( assignee) => return Ok ( ( Some ( assignee) , false ) ) ,
349
377
Err ( e) => {
350
378
log:: trace!(
@@ -522,6 +550,7 @@ pub(super) async fn handle_command(
522
550
let db_client = ctx. db . get ( ) . await ;
523
551
let assignee = match find_reviewer_from_names (
524
552
& db_client,
553
+ ctx. workqueue . clone ( ) ,
525
554
& teams,
526
555
config,
527
556
issue,
@@ -700,6 +729,7 @@ impl fmt::Display for FindReviewerError {
700
729
/// entry.
701
730
async fn find_reviewer_from_names (
702
731
_db : & DbClient ,
732
+ workqueue : Arc < RwLock < ReviewerWorkqueue > > ,
703
733
teams : & Teams ,
704
734
config : & AssignConfig ,
705
735
issue : & Issue ,
@@ -712,7 +742,7 @@ async fn find_reviewer_from_names(
712
742
}
713
743
}
714
744
715
- let candidates = candidate_reviewers_from_names ( teams, config, issue, names) ?;
745
+ let candidates = candidate_reviewers_from_names ( workqueue , teams, config, issue, names) ?;
716
746
// This uses a relatively primitive random choice algorithm.
717
747
// GitHub's CODEOWNERS supports much more sophisticated options, such as:
718
748
//
@@ -817,6 +847,7 @@ fn expand_teams_and_groups(
817
847
/// Returns a list of candidate usernames (from relevant teams) to choose as a reviewer.
818
848
/// If not reviewer is available, returns an error.
819
849
fn candidate_reviewers_from_names < ' a > (
850
+ workqueue : Arc < RwLock < ReviewerWorkqueue > > ,
820
851
teams : & ' a Teams ,
821
852
config : & ' a AssignConfig ,
822
853
issue : & Issue ,
0 commit comments