Skip to content

Commit

Permalink
Disable new PR assignment, just log
Browse files Browse the repository at this point in the history
  • Loading branch information
apiraino committed Jan 27, 2025
1 parent edc6ad8 commit 541ebe2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
38 changes: 18 additions & 20 deletions src/handlers/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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") {
Expand All @@ -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")
Expand Down Expand Up @@ -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<String> = result.iter().map(|row| row.get("username")).collect();
log::info!("DB returned these candidates: {:?}", candidates);
Ok(candidates)
}

Expand Down
36 changes: 21 additions & 15 deletions src/handlers/pr_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 541ebe2

Please sign in to comment.