Skip to content

Commit 09bab14

Browse files
committed
Pass reviewer workqueue to candidate_reviewers_from_names
1 parent 9b51b25 commit 09bab14

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/handlers/assign.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//! `assign.owners` config, it will auto-select an assignee based on the files
2121
//! the PR modifies.
2222
23+
use crate::handlers::pr_tracking::ReviewerWorkqueue;
2324
use crate::{
2425
config::AssignConfig,
2526
github::{self, Event, FileDiff, Issue, IssuesAction, Selection},
@@ -33,6 +34,8 @@ use rand::seq::IteratorRandom;
3334
use rust_team_data::v1::Teams;
3435
use std::collections::{HashMap, HashSet};
3536
use std::fmt;
37+
use std::sync::Arc;
38+
use tokio::sync::RwLock;
3639
use tokio_postgres::Client as DbClient;
3740
use tracing as log;
3841

@@ -299,7 +302,16 @@ async fn determine_assignee(
299302
let teams = crate::team_data::teams(&ctx.github).await?;
300303
if let Some(name) = assign_command {
301304
// 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+
{
303315
Ok(assignee) => return Ok((Some(assignee), true)),
304316
Err(e) => {
305317
event
@@ -313,8 +325,15 @@ async fn determine_assignee(
313325
// Errors fall-through to try fallback group.
314326
match find_reviewers_from_diff(config, diff) {
315327
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
318337
{
319338
Ok(assignee) => return Ok((Some(assignee), false)),
320339
Err(FindReviewerError::TeamNotFound(team)) => log::warn!(
@@ -344,7 +363,16 @@ async fn determine_assignee(
344363
}
345364

346365
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+
{
348376
Ok(assignee) => return Ok((Some(assignee), false)),
349377
Err(e) => {
350378
log::trace!(
@@ -522,6 +550,7 @@ pub(super) async fn handle_command(
522550
let db_client = ctx.db.get().await;
523551
let assignee = match find_reviewer_from_names(
524552
&db_client,
553+
ctx.workqueue.clone(),
525554
&teams,
526555
config,
527556
issue,
@@ -700,6 +729,7 @@ impl fmt::Display for FindReviewerError {
700729
/// entry.
701730
async fn find_reviewer_from_names(
702731
_db: &DbClient,
732+
workqueue: Arc<RwLock<ReviewerWorkqueue>>,
703733
teams: &Teams,
704734
config: &AssignConfig,
705735
issue: &Issue,
@@ -712,7 +742,7 @@ async fn find_reviewer_from_names(
712742
}
713743
}
714744

715-
let candidates = candidate_reviewers_from_names(teams, config, issue, names)?;
745+
let candidates = candidate_reviewers_from_names(workqueue, teams, config, issue, names)?;
716746
// This uses a relatively primitive random choice algorithm.
717747
// GitHub's CODEOWNERS supports much more sophisticated options, such as:
718748
//
@@ -817,6 +847,7 @@ fn expand_teams_and_groups(
817847
/// Returns a list of candidate usernames (from relevant teams) to choose as a reviewer.
818848
/// If not reviewer is available, returns an error.
819849
fn candidate_reviewers_from_names<'a>(
850+
workqueue: Arc<RwLock<ReviewerWorkqueue>>,
820851
teams: &'a Teams,
821852
config: &'a AssignConfig,
822853
issue: &Issue,

0 commit comments

Comments
 (0)