From 541ebe27cb917f1929dcb2dbc0dfa99db5b590fa Mon Sep 17 00:00:00 2001 From: apiraino Date: Fri, 24 Jan 2025 15:44:59 +0100 Subject: [PATCH] Disable new PR assignment, just log --- src/handlers/assign.rs | 38 ++++++++++++++++++------------------- src/handlers/pr_tracking.rs | 36 ++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/handlers/assign.rs b/src/handlers/assign.rs index 8ccbccd6..21a2424a 100644 --- a/src/handlers/assign.rs +++ b/src/handlers/assign.rs @@ -541,18 +541,14 @@ pub(super) async fn handle_command( } let db_client = ctx.db.get().await; if is_self_assign(&name, &event.user().login) { - match has_user_capacity(&db_client, &name).await { - Ok(work_queue) => work_queue.username, - Err(_) => { - issue - .post_comment( - &ctx.github, - &REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name), - ) - .await?; - return Ok(()); - } - }; + let work_queue = has_user_capacity(&db_client, &name).await; + if work_queue.is_err() { + // NOTE: disabled for now, just log + log::info!( + "DB reported that user {} has no review capacity. Ignoring.", + name + ); + } name.to_string() } else { let teams = crate::team_data::teams(&ctx.github).await?; @@ -781,7 +777,7 @@ async fn find_reviewer_from_names( // These are all ideas for improving the selection here. However, I'm not // sure they are really worth the effort. - log::info!("Initial list of candidates: {:?}", candidates); + log::info!("Initial unfiltered list of candidates: {:?}", candidates); // Special case user "ghost", we always skip filtering if candidates.contains("ghost") { @@ -794,15 +790,16 @@ async fn find_reviewer_from_names( .expect("Error while filtering out team members"); if filtered_candidates.is_empty() { - return Err(FindReviewerError::AllReviewersFiltered { - initial: names.to_vec(), - filtered: names.to_vec(), - }); + // NOTE: disabled for now, just log + log::info!("Filtered list of PR assignee is empty"); + // return Err(FindReviewerError::AllReviewersFiltered { + // initial: names.to_vec(), + // filtered: names.to_vec(), + // }); } - log::info!("Filtered list of candidates: {:?}", filtered_candidates); - - Ok(filtered_candidates + // Return the unfiltered list + Ok(candidates .into_iter() .choose(&mut rand::thread_rng()) .expect("candidate_reviewers_from_names should return at least one entry") @@ -831,6 +828,7 @@ AND CARDINALITY(r.assigned_prs) < LEAST(COALESCE(r.max_assigned_prs,1000000))", ); let result = db.query(&q, &[]).await.context("Select DB error")?; let candidates: HashSet = result.iter().map(|row| row.get("username")).collect(); + log::info!("DB returned these candidates: {:?}", candidates); Ok(candidates) } diff --git a/src/handlers/pr_tracking.rs b/src/handlers/pr_tracking.rs index 5bb8ea58..4c556065 100644 --- a/src/handlers/pr_tracking.rs +++ b/src/handlers/pr_tracking.rs @@ -15,6 +15,7 @@ use crate::{ }; use anyhow::Context as _; use tokio_postgres::Client as DbClient; +use tracing as log; use super::assign::{FindReviewerError, REVIEWER_HAS_NO_CAPACITY, SELF_ASSIGN_HAS_NO_CAPACITY}; @@ -77,24 +78,28 @@ pub(super) async fn handle_input<'a>( // (i.e. from the "Assignees" dropdown menu). // We need to also check assignee availability here. if matches!(event.action, IssuesAction::Assigned { .. }) { - let work_queue = has_user_capacity(&db_client, &assignee.login) - .await - .context("Failed to retrieve user work queue"); + let work_queue = has_user_capacity(&db_client, &assignee.login).await; // if user has no capacity, revert the PR assignment (GitHub has already assigned it) // and post a comment suggesting what to do if let Err(_) = work_queue { - event - .issue - .remove_assignees(&ctx.github, crate::github::Selection::One(&assignee.login)) - .await?; - - let msg = if assignee.login.to_lowercase() == event.issue.user.login.to_lowercase() { - SELF_ASSIGN_HAS_NO_CAPACITY.replace("{username}", &assignee.login) - } else { - REVIEWER_HAS_NO_CAPACITY.replace("{username}", &assignee.login) - }; - event.issue.post_comment(&ctx.github, &msg).await?; + log::info!( + "DB reported that user {} has no review capacity. Ignoring.", + &assignee.login + ); + + // NOTE: disabled for now, just log + // event + // .issue + // .remove_assignees(&ctx.github, crate::github::Selection::One(&assignee.login)) + // .await?; + + // let msg = if assignee.login.to_lowercase() == event.issue.user.login.to_lowercase() { + // SELF_ASSIGN_HAS_NO_CAPACITY.replace("{username}", &assignee.login) + // } else { + // REVIEWER_HAS_NO_CAPACITY.replace("{username}", &assignee.login) + // }; + // event.issue.post_comment(&ctx.github, &msg).await?; } upsert_pr_into_workqueue(&db_client, assignee.id, event.issue.number) @@ -105,7 +110,8 @@ pub(super) async fn handle_input<'a>( Ok(()) } -// TODO: we should just fetch the number of assigned prs and max assigned prs. The caller should do the check. +// Check user review capacity. +// Returns error if SQL query fails or user has no capacity pub async fn has_user_capacity( db: &crate::db::PooledClient, assignee: &str,