Skip to content

Commit 0b5ed11

Browse files
authored
Disable new PR assignment, just log (#1893)
* Caller checks review capacity DB query result * Disable new PR assignment, just log
1 parent de42aaf commit 0b5ed11

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

src/handlers/assign.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,22 @@ pub(super) async fn handle_command(
541541
}
542542
let db_client = ctx.db.get().await;
543543
if is_self_assign(&name, &event.user().login) {
544-
match has_user_capacity(&db_client, &name).await {
545-
Ok(work_queue) => work_queue.username,
546-
Err(_) => {
547-
issue
548-
.post_comment(
549-
&ctx.github,
550-
&REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name),
551-
)
552-
.await?;
553-
return Ok(());
554-
}
555-
};
544+
let work_queue = has_user_capacity(&db_client, &name).await;
545+
if work_queue.is_err() {
546+
// NOTE: disabled for now, just log
547+
log::info!(
548+
"DB reported that user {} has no review capacity. Ignoring.",
549+
name
550+
);
551+
// issue
552+
// .post_comment(
553+
// &ctx.github,
554+
// &REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name),
555+
// )
556+
// .await?;
557+
// return Ok(());
558+
}
559+
556560
name.to_string()
557561
} else {
558562
let teams = crate::team_data::teams(&ctx.github).await?;
@@ -781,7 +785,7 @@ async fn find_reviewer_from_names(
781785
// These are all ideas for improving the selection here. However, I'm not
782786
// sure they are really worth the effort.
783787

784-
log::info!("Initial list of candidates: {:?}", candidates);
788+
log::info!("Initial unfiltered list of candidates: {:?}", candidates);
785789

786790
// Special case user "ghost", we always skip filtering
787791
if candidates.contains("ghost") {
@@ -794,15 +798,18 @@ async fn find_reviewer_from_names(
794798
.expect("Error while filtering out team members");
795799

796800
if filtered_candidates.is_empty() {
797-
return Err(FindReviewerError::AllReviewersFiltered {
798-
initial: names.to_vec(),
799-
filtered: names.to_vec(),
800-
});
801+
// NOTE: disabled for now, just log
802+
log::info!("Filtered list of PR assignee is empty");
803+
// return Err(FindReviewerError::AllReviewersFiltered {
804+
// initial: names.to_vec(),
805+
// filtered: names.to_vec(),
806+
// });
801807
}
802808

803809
log::info!("Filtered list of candidates: {:?}", filtered_candidates);
804810

805-
Ok(filtered_candidates
811+
// Return unfiltered list of candidates
812+
Ok(candidates
806813
.into_iter()
807814
.choose(&mut rand::thread_rng())
808815
.expect("candidate_reviewers_from_names should return at least one entry")
@@ -831,6 +838,7 @@ AND CARDINALITY(r.assigned_prs) < LEAST(COALESCE(r.max_assigned_prs,1000000))",
831838
);
832839
let result = db.query(&q, &[]).await.context("Select DB error")?;
833840
let candidates: HashSet<String> = result.iter().map(|row| row.get("username")).collect();
841+
log::info!("DB returned these candidates: {:?}", candidates);
834842
Ok(candidates)
835843
}
836844

src/handlers/pr_tracking.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
};
1616
use anyhow::Context as _;
1717
use tokio_postgres::Client as DbClient;
18+
use tracing as log;
1819

1920
use super::assign::{FindReviewerError, REVIEWER_HAS_NO_CAPACITY, SELF_ASSIGN_HAS_NO_CAPACITY};
2021

@@ -84,17 +85,22 @@ pub(super) async fn handle_input<'a>(
8485
// if user has no capacity, revert the PR assignment (GitHub has already assigned it)
8586
// and post a comment suggesting what to do
8687
if let Err(_) = work_queue {
87-
event
88-
.issue
89-
.remove_assignees(&ctx.github, crate::github::Selection::One(&assignee.login))
90-
.await?;
91-
92-
let msg = if assignee.login.to_lowercase() == event.issue.user.login.to_lowercase() {
93-
SELF_ASSIGN_HAS_NO_CAPACITY.replace("{username}", &assignee.login)
94-
} else {
95-
REVIEWER_HAS_NO_CAPACITY.replace("{username}", &assignee.login)
96-
};
97-
event.issue.post_comment(&ctx.github, &msg).await?;
88+
log::info!(
89+
"DB reported that user {} has no review capacity. Ignoring.",
90+
&assignee.login
91+
);
92+
93+
// NOTE: disabled for now, just log
94+
// event
95+
// .issue
96+
// .remove_assignees(&ctx.github, crate::github::Selection::One(&assignee.login))
97+
// .await?;
98+
// let msg = if assignee.login.to_lowercase() == event.issue.user.login.to_lowercase() {
99+
// SELF_ASSIGN_HAS_NO_CAPACITY.replace("{username}", &assignee.login)
100+
// } else {
101+
// REVIEWER_HAS_NO_CAPACITY.replace("{username}", &assignee.login)
102+
// };
103+
// event.issue.post_comment(&ctx.github, &msg).await?;
98104
}
99105

100106
upsert_pr_into_workqueue(&db_client, assignee.id, event.issue.number)
@@ -105,7 +111,8 @@ pub(super) async fn handle_input<'a>(
105111
Ok(())
106112
}
107113

108-
// TODO: we should just fetch the number of assigned prs and max assigned prs. The caller should do the check.
114+
// Check user review capacity.
115+
// Returns error if SQL query fails or user has no capacity
109116
pub async fn has_user_capacity(
110117
db: &crate::db::PooledClient,
111118
assignee: &str,

0 commit comments

Comments
 (0)