-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store assigned PRs in memory #1906
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
use crate::{ | ||
config::{AssignConfig, WarnNonDefaultBranchException}, | ||
github::{self, Event, FileDiff, Issue, IssuesAction, Selection}, | ||
handlers::{pr_tracking::has_user_capacity, Context, GithubClient, IssuesEvent}, | ||
handlers::{Context, GithubClient, IssuesEvent}, | ||
interactions::EditIssueBody, | ||
}; | ||
use anyhow::{bail, Context as _}; | ||
|
@@ -39,7 +39,6 @@ use tracing as log; | |
#[cfg(test)] | ||
mod tests { | ||
mod tests_candidates; | ||
mod tests_db; | ||
mod tests_from_diff; | ||
} | ||
|
||
|
@@ -560,22 +559,22 @@ pub(super) async fn handle_command( | |
} | ||
let db_client = ctx.db.get().await; | ||
if is_self_assign(&name, &event.user().login) { | ||
let work_queue = has_user_capacity(&db_client, &name).await; | ||
if work_queue.is_err() { | ||
// NOTE: disabled for now, just log | ||
log::warn!( | ||
"[#{}] PR self-assign failed, DB reported that user {} has no review capacity. Ignoring.", | ||
issue.number, | ||
name | ||
); | ||
// 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this disabled? We definitely want this logging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions that I commented were using the I'm planning to further work on assigning PR capacity limit, and then refactor the way PRs are assigned, and add back logging (and then we can hopefully enable the new assignment logic again). I did not want to do all that in this PR, hence I commented this code. |
||
// if work_queue.is_err() { | ||
// // NOTE: disabled for now, just log | ||
// log::warn!( | ||
// "[#{}] PR self-assign failed, DB reported that user {} has no review capacity. Ignoring.", | ||
// issue.number, | ||
// name | ||
// ); | ||
// // issue | ||
// // .post_comment( | ||
// // &ctx.github, | ||
// // &REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name), | ||
// // ) | ||
// // .await?; | ||
// // return Ok(()); | ||
// } | ||
|
||
name.to_string() | ||
} else { | ||
|
@@ -802,7 +801,7 @@ impl fmt::Display for FindReviewerError { | |
/// auto-assign groups, or rust-lang team names. It must have at least one | ||
/// entry. | ||
async fn find_reviewer_from_names( | ||
db: &DbClient, | ||
_db: &DbClient, | ||
teams: &Teams, | ||
config: &AssignConfig, | ||
issue: &Issue, | ||
|
@@ -841,24 +840,24 @@ async fn find_reviewer_from_names( | |
} | ||
|
||
// filter out team members without capacity | ||
let filtered_candidates = filter_by_capacity(db, &candidates) | ||
.await | ||
.expect("Error while filtering out team members"); | ||
|
||
if filtered_candidates.is_empty() { | ||
// NOTE: disabled for now, just log | ||
log::info!("[#{}] Filtered list of PR assignee is empty", issue.number); | ||
// return Err(FindReviewerError::AllReviewersFiltered { | ||
// initial: names.to_vec(), | ||
// filtered: names.to_vec(), | ||
// }); | ||
} | ||
|
||
log::info!( | ||
"[#{}] Filtered list of candidates: {:?}", | ||
issue.number, | ||
filtered_candidates | ||
); | ||
// let filtered_candidates = filter_by_capacity(db, &candidates) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here. |
||
// .await | ||
// .expect("Error while filtering out team members"); | ||
// | ||
// if filtered_candidates.is_empty() { | ||
// // NOTE: disabled for now, just log | ||
// log::info!("[#{}] Filtered list of PR assignee is empty", issue.number); | ||
// // return Err(FindReviewerError::AllReviewersFiltered { | ||
// // initial: names.to_vec(), | ||
// // filtered: names.to_vec(), | ||
// // }); | ||
// } | ||
// | ||
// log::info!( | ||
// "[#{}] Filtered list of candidates: {:?}", | ||
// issue.number, | ||
// filtered_candidates | ||
// ); | ||
|
||
// Return unfiltered list of candidates | ||
Ok(candidates | ||
|
@@ -868,32 +867,6 @@ async fn find_reviewer_from_names( | |
.to_string()) | ||
} | ||
|
||
/// Filter out candidates not having review capacity | ||
async fn filter_by_capacity( | ||
db: &DbClient, | ||
candidates: &HashSet<&str>, | ||
) -> anyhow::Result<HashSet<String>> { | ||
let usernames = candidates | ||
.iter() | ||
.map(|c| *c) | ||
.collect::<Vec<&str>>() | ||
.join(","); | ||
|
||
let q = format!( | ||
" | ||
SELECT username | ||
FROM review_prefs r | ||
JOIN users on users.user_id=r.user_id | ||
AND username = ANY('{{ {} }}') | ||
AND CARDINALITY(r.assigned_prs) < LEAST(COALESCE(r.max_assigned_prs,1000000))", | ||
usernames | ||
); | ||
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) | ||
} | ||
|
||
/// Returns a list of candidate usernames (from relevant teams) to choose as a reviewer. | ||
fn candidate_reviewers_from_names<'a>( | ||
teams: &'a Teams, | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I don't quite like storing this state like this - I'd rather have some
(Handler, HandlerState)
somewhere. But this is fine for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that this state has to be available across handlers. It is populated in
pull_requests_assignment_update.rs
, updated inpr_tracking.rs
and it will be read in the future inassign.rs
. Thus it's pretty much global state, hence it being stored inContext
.