Skip to content

Commit 5b0aa6e

Browse files
authored
Merge pull request #1796 from apiraino/revert-last-two-prs
Revert last two prs
2 parents 5e55888 + 701e207 commit 5b0aa6e

File tree

5 files changed

+25
-206
lines changed

5 files changed

+25
-206
lines changed

src/db.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ CREATE table review_prefs (
332332
assigned_prs INT[] NOT NULL DEFAULT array[]::INT[]
333333
);",
334334
"
335-
CREATE EXTENSION IF NOT EXISTS intarray;",
336-
"
337-
CREATE UNIQUE INDEX IF NOT EXISTS review_prefs_user_id ON review_prefs(user_id);
335+
CREATE EXTENSION intarray;
336+
CREATE UNIQUE INDEX review_prefs_user_id ON review_prefs(user_id);
338337
",
339-
"
340-
ALTER TABLE review_prefs ADD COLUMN IF NOT EXISTS max_assigned_prs INTEGER DEFAULT NULL;
341-
",
342338
];

src/handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ macro_rules! issue_handlers {
159159

160160
// Handle events that happened on issues
161161
//
162-
// This is for events that happen only on issues or pull requests (e.g. label changes or assignments).
162+
// This is for events that happen only on issues (e.g. label changes).
163163
// Each module in the list must contain the functions `parse_input` and `handle_input`.
164164
issue_handlers! {
165165
assign,
@@ -280,7 +280,7 @@ macro_rules! command_handlers {
280280
//
281281
// This is for handlers for commands parsed by the `parser` crate.
282282
// Each variant of `parser::command::Command` must be in this list,
283-
// preceded by the module containing the corresponding `handle_command` function
283+
// preceded by the module containing the coresponding `handle_command` function
284284
command_handlers! {
285285
assign: Assign,
286286
glacier: Glacier,

src/handlers/assign.rs

Lines changed: 15 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
//! * `@rustbot release-assignment`: Removes the commenter's assignment.
88
//! * `r? @user`: Assigns to the given user (PRs only).
99
//!
10-
//! Note: this module does not handle review assignments issued from the
11-
//! GitHub "Assignees" dropdown menu
12-
//!
1310
//! This is capable of assigning to any user, even if they do not have write
1411
//! access to the repo. It does this by fake-assigning the bot and adding a
1512
//! "claimed by" section to the top-level comment.
@@ -23,7 +20,7 @@
2320
use crate::{
2421
config::AssignConfig,
2522
github::{self, Event, FileDiff, Issue, IssuesAction, Selection},
26-
handlers::{pr_tracking::has_user_capacity, Context, GithubClient, IssuesEvent},
23+
handlers::{Context, GithubClient, IssuesEvent},
2724
interactions::EditIssueBody,
2825
};
2926
use anyhow::{bail, Context as _};
@@ -33,7 +30,6 @@ use rand::seq::IteratorRandom;
3330
use rust_team_data::v1::Teams;
3431
use std::collections::{HashMap, HashSet};
3532
use std::fmt;
36-
use tokio_postgres::Client as DbClient;
3733
use tracing as log;
3834

3935
#[cfg(test)]
@@ -79,27 +75,6 @@ const NON_DEFAULT_BRANCH: &str =
7975

8076
const SUBMODULE_WARNING_MSG: &str = "These commits modify **submodules**.";
8177

82-
pub const SELF_ASSIGN_HAS_NO_CAPACITY: &str = "
83-
You have insufficient capacity to be assigned the pull request at this time. PR assignment has been reverted.
84-
85-
Please choose another assignee or increase your assignment limit.
86-
87-
(see [documentation](https://forge.rust-lang.org/triagebot/pr-assignment-tracking.html))";
88-
89-
pub const REVIEWER_HAS_NO_CAPACITY: &str = "
90-
`{username}` has insufficient capacity to be assigned the pull request at this time. PR assignment has been reverted.
91-
92-
Please choose another assignee.
93-
94-
(see [documentation](https://forge.rust-lang.org/triagebot/pr-assignment-tracking.html))";
95-
96-
const NO_REVIEWER_HAS_CAPACITY: &str = "
97-
Could not find a reviewer with enough capacity to be assigned at this time. This is a problem.
98-
99-
Please contact us on [#t-infra](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra) on Zulip.
100-
101-
cc: @jackh726 @apiraino";
102-
10378
fn on_vacation_msg(user: &str) -> String {
10479
ON_VACATION_WARNING.replace("{username}", user)
10580
}
@@ -297,8 +272,6 @@ async fn set_assignee(issue: &Issue, github: &GithubClient, username: &str) {
297272
/// Determines who to assign the PR to based on either an `r?` command, or
298273
/// based on which files were modified.
299274
///
300-
/// Will also check if candidates have capacity in their work queue.
301-
///
302275
/// Returns `(assignee, from_comment)` where `assignee` is who to assign to
303276
/// (or None if no assignee could be found). `from_comment` is a boolean
304277
/// indicating if the assignee came from an `r?` command (it is false if
@@ -309,14 +282,13 @@ async fn determine_assignee(
309282
config: &AssignConfig,
310283
diff: &[FileDiff],
311284
) -> anyhow::Result<(Option<String>, bool)> {
312-
let db_client = ctx.db.get().await;
313285
let teams = crate::team_data::teams(&ctx.github).await?;
314286
if let Some(name) = find_assign_command(ctx, event) {
315287
if is_self_assign(&name, &event.issue.user.login) {
316288
return Ok((Some(name.to_string()), true));
317289
}
318290
// User included `r?` in the opening PR body.
319-
match find_reviewer_from_names(&db_client, &teams, config, &event.issue, &[name]).await {
291+
match find_reviewer_from_names(&teams, config, &event.issue, &[name]) {
320292
Ok(assignee) => return Ok((Some(assignee), true)),
321293
Err(e) => {
322294
event
@@ -330,9 +302,7 @@ async fn determine_assignee(
330302
// Errors fall-through to try fallback group.
331303
match find_reviewers_from_diff(config, diff) {
332304
Ok(candidates) if !candidates.is_empty() => {
333-
match find_reviewer_from_names(&db_client, &teams, config, &event.issue, &candidates)
334-
.await
335-
{
305+
match find_reviewer_from_names(&teams, config, &event.issue, &candidates) {
336306
Ok(assignee) => return Ok((Some(assignee), false)),
337307
Err(FindReviewerError::TeamNotFound(team)) => log::warn!(
338308
"team {team} not found via diff from PR {}, \
@@ -342,9 +312,7 @@ async fn determine_assignee(
342312
// TODO: post a comment on the PR if the reviewers were filtered due to being on vacation
343313
Err(
344314
e @ FindReviewerError::NoReviewer { .. }
345-
| e @ FindReviewerError::AllReviewersFiltered { .. }
346-
| e @ FindReviewerError::NoReviewerHasCapacity
347-
| e @ FindReviewerError::ReviewerHasNoCapacity { .. },
315+
| e @ FindReviewerError::AllReviewersFiltered { .. },
348316
) => log::trace!(
349317
"no reviewer could be determined for PR {}: {e}",
350318
event.issue.global_id()
@@ -362,7 +330,7 @@ async fn determine_assignee(
362330
}
363331

364332
if let Some(fallback) = config.adhoc_groups.get("fallback") {
365-
match find_reviewer_from_names(&db_client, &teams, config, &event.issue, fallback).await {
333+
match find_reviewer_from_names(&teams, config, &event.issue, fallback) {
366334
Ok(assignee) => return Ok((Some(assignee), false)),
367335
Err(e) => {
368336
log::trace!(
@@ -524,20 +492,7 @@ pub(super) async fn handle_command(
524492
// welcome message).
525493
return Ok(());
526494
}
527-
let db_client = ctx.db.get().await;
528495
if is_self_assign(&name, &event.user().login) {
529-
match has_user_capacity(&db_client, &name).await {
530-
Ok(work_queue) => work_queue.username,
531-
Err(_) => {
532-
issue
533-
.post_comment(
534-
&ctx.github,
535-
&REVIEWER_HAS_NO_CAPACITY.replace("{username}", &name),
536-
)
537-
.await?;
538-
return Ok(());
539-
}
540-
};
541496
name.to_string()
542497
} else {
543498
let teams = crate::team_data::teams(&ctx.github).await?;
@@ -557,14 +512,8 @@ pub(super) async fn handle_command(
557512
}
558513
}
559514
}
560-
match find_reviewer_from_names(
561-
&db_client,
562-
&teams,
563-
config,
564-
issue,
565-
&[team_name.to_string()],
566-
)
567-
.await
515+
516+
match find_reviewer_from_names(&teams, config, issue, &[team_name.to_string()])
568517
{
569518
Ok(assignee) => assignee,
570519
Err(e) => {
@@ -575,11 +524,7 @@ pub(super) async fn handle_command(
575524
}
576525
}
577526
};
578-
579-
// This user is validated and can accept the PR
580527
set_assignee(issue, &ctx.github, &username).await;
581-
// This PR will now be registered in the reviewer's work queue
582-
// by the `pr_tracking` handler
583528
return Ok(());
584529
}
585530

@@ -637,7 +582,6 @@ pub(super) async fn handle_command(
637582

638583
e.apply(&ctx.github, String::new(), &data).await?;
639584

640-
// Assign the PR: user's work queue has been checked and can accept this PR
641585
match issue.set_assignee(&ctx.github, &to_assign).await {
642586
Ok(()) => return Ok(()), // we are done
643587
Err(github::AssignmentError::InvalidAssignee) => {
@@ -659,7 +603,7 @@ pub(super) async fn handle_command(
659603
}
660604

661605
#[derive(PartialEq, Debug)]
662-
pub enum FindReviewerError {
606+
enum FindReviewerError {
663607
/// User specified something like `r? foo/bar` where that team name could
664608
/// not be found.
665609
TeamNotFound(String),
@@ -677,11 +621,6 @@ pub enum FindReviewerError {
677621
initial: Vec<String>,
678622
filtered: Vec<String>,
679623
},
680-
/// No reviewer has capacity to accept a pull request assignment at this time
681-
NoReviewerHasCapacity,
682-
/// The requested reviewer has no capacity to accept a pull request
683-
/// assignment at this time
684-
ReviewerHasNoCapacity { username: String },
685624
}
686625

687626
impl std::error::Error for FindReviewerError {}
@@ -711,23 +650,13 @@ impl fmt::Display for FindReviewerError {
711650
write!(
712651
f,
713652
"Could not assign reviewer from: `{}`.\n\
714-
User(s) `{}` are either the PR author, already assigned, or on vacation. \
715-
If it's a team, we could not find any candidates.\n\
716-
Please use `r?` to specify someone else to assign.",
653+
User(s) `{}` are either the PR author, already assigned, or on vacation, \
654+
and there are no other candidates.\n\
655+
Use `r?` to specify someone else to assign.",
717656
initial.join(","),
718657
filtered.join(","),
719658
)
720659
}
721-
FindReviewerError::ReviewerHasNoCapacity { username } => {
722-
write!(
723-
f,
724-
"{}",
725-
REVIEWER_HAS_NO_CAPACITY.replace("{username}", username)
726-
)
727-
}
728-
FindReviewerError::NoReviewerHasCapacity => {
729-
write!(f, "{}", NO_REVIEWER_HAS_CAPACITY)
730-
}
731660
}
732661
}
733662
}
@@ -738,8 +667,7 @@ impl fmt::Display for FindReviewerError {
738667
/// `@octocat`, or names from the owners map. It can contain GitHub usernames,
739668
/// auto-assign groups, or rust-lang team names. It must have at least one
740669
/// entry.
741-
async fn find_reviewer_from_names(
742-
db: &DbClient,
670+
fn find_reviewer_from_names(
743671
teams: &Teams,
744672
config: &AssignConfig,
745673
issue: &Issue,
@@ -765,64 +693,14 @@ async fn find_reviewer_from_names(
765693
//
766694
// These are all ideas for improving the selection here. However, I'm not
767695
// sure they are really worth the effort.
768-
769-
// If we are trying to assign to the ghost GitHub user, bypass every check
770-
let mut filtered_candidates: HashSet<String> = HashSet::new();
771-
if candidates.contains("ghost") {
772-
filtered_candidates.insert("ghost".to_string());
773-
} else {
774-
// filter out team members without capacity
775-
filtered_candidates = filter_by_capacity(db, &candidates)
776-
.await
777-
.expect("Error while filtering out team members");
778-
779-
if filtered_candidates.is_empty() {
780-
return Err(FindReviewerError::AllReviewersFiltered {
781-
initial: names.to_vec(),
782-
filtered: names.to_vec(),
783-
});
784-
}
785-
}
786-
787-
log::debug!("Filtered list of candidates: {:?}", filtered_candidates);
788-
789-
Ok(filtered_candidates
696+
Ok(candidates
790697
.into_iter()
791698
.choose(&mut rand::thread_rng())
792-
.expect("candidate_reviewers_from_names should return at least one entry")
699+
.expect("candidate_reviewers_from_names always returns at least one entry")
793700
.to_string())
794701
}
795702

796-
// FIXME: this query probably needs to take into account when max_assigned_prs is null
797-
/// Filter out candidates not having review capacity
798-
async fn filter_by_capacity(
799-
db: &DbClient,
800-
candidates: &HashSet<&str>,
801-
) -> anyhow::Result<HashSet<String>> {
802-
let usernames = candidates
803-
.iter()
804-
.map(|c| *c)
805-
.collect::<Vec<&str>>()
806-
.join(",");
807-
808-
let q = format!(
809-
"
810-
SELECT username
811-
FROM review_prefs r
812-
JOIN users on users.user_id=r.user_id
813-
AND username = ANY('{{ {} }}')
814-
AND ARRAY_LENGTH(r.assigned_prs, 1) < max_assigned_prs",
815-
usernames
816-
);
817-
let result = db.query(&q, &[]).await.context("Select DB error")?;
818-
let mut candidates: HashSet<String> = HashSet::new();
819-
for row in result {
820-
candidates.insert(row.get("username"));
821-
}
822-
Ok(candidates)
823-
}
824-
825-
/// returns a list of candidate usernames (from relevant teams) to choose as a reviewer.
703+
/// Returns a list of candidate usernames to choose as a reviewer.
826704
fn candidate_reviewers_from_names<'a>(
827705
teams: &'a Teams,
828706
config: &'a AssignConfig,

0 commit comments

Comments
 (0)