Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/handlers/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,18 +541,22 @@ 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
);
// issue
// .post_comment(
// &ctx.github,
// &REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name),
// )
// .await?;
// return Ok(());
}

name.to_string()
} else {
let teams = crate::team_data::teams(&ctx.github).await?;
Expand Down Expand Up @@ -781,7 +785,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 +798,18 @@ 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 unfiltered list of candidates
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 +838,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
31 changes: 19 additions & 12 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 @@ -84,17 +85,22 @@ pub(super) async fn handle_input<'a>(
// 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 +111,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
Loading