Skip to content

Pick reviewer who is not previous assignee when r? group #1958

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Apr 24, 2025

Closes #1762

This PR implements similar functionality to the reroll, and based on the discussion #triagebot > @rustbot reroll on zulip, it is not necessary for us to implement a separate reroll.

I optimized the logic for r? group. Each time an assignee is set, it is stored in the database, and when we use an r? group, such as r? compiler, I will take out the previously assigned reviewer from the database to avoid to assign a previous assignee.

However. the use of r? @reviewer to specify a specific assignee does not exclude the previous assignee, as this is explicitly specified.

@Kobzol
Copy link
Contributor

Kobzol commented Apr 24, 2025

Thanks for the PR! I think that we should first discuss the design though. I'm not sure if rerolling based on the diff is the most intuitive solution in all cases. If someone did r? compiler before, then rerolling should IMO select someone else from the compiler team/adhoc group, not determine the reviewer based on the file diff. We might thus have to store some per-issue data to remember that a team was previously requested for a review.

I opened a topic about this on Zulip: https://rust-lang.zulipchat.com/#narrow/channel/224082-triagebot/topic/.40rustbot.20reroll/with/514122139.

@xizheyin xizheyin changed the title Add @rustbot reroll to pick a new reviewer Pick reviewer which was not assigned before **only** when r? group Apr 25, 2025
@xizheyin
Copy link
Contributor Author

I modified the logic:
Only when r? group, we will select a reviewer that has not been previously ASSIGNED. note that this won't work with r? @username because we explicitly specify the name.

I'll comment my changes in the code.

Comment on lines 321 to 325
// TODO: only NoReviewer can be reached here!
| e @ FindReviewerError::ReviewerIsPrAuthor { .. }
| e @ FindReviewerError::ReviewerAlreadyAssigned { .. }
| e @ FindReviewerError::ReviewerOnVacation { .. },
| e @ FindReviewerError::ReviewerOnVacation { .. }
| e @ FindReviewerError::ReviewerPreviouslyAssigned { .. },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting here. Should we use unreachable!() except NoReviewer?

Comment on lines 841 to 842
let previous_reviewer_names = get_previous_reviewer_names(ctx, issue).await;
let is_previously_assigned = previous_reviewer_names.contains(&candidate);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to know if the candidate is a previous reviewer.

Comment on lines 858 to 1016
} else if expansion_happened && is_previously_assigned {
// **Only** when r? group is expanded, we consider the reviewer previously assigned
// `r? @reviewer` will not consider the reviewer previously assigned
Some(FindReviewerError::ReviewerPreviouslyAssigned {
username: candidate.clone(),
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added logic here to determine if it's a previous Reviewer here only when r? group (expansion happened).

Comment on lines 909 to 1121

async fn get_previous_reviewer_names(ctx: &Context, issue: &Issue) -> HashSet<String> {
if cfg!(test) {
return HashSet::new();
}

// Get the state of the warnings for this PR in the database.
let mut db = ctx.db.get().await;
let state: IssueData<'_, Reviewer> =
match IssueData::load(&mut db, &issue, PREVIOUS_REVIEWER_KEY).await {
Ok(state) => state,
Err(_) => return HashSet::new(),
};

state.data.names
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This corresponds to set_assignee, which stores, and this function is used to read from the database. cfg!(test) returns null in order to pass the tests.

let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();
match (
candidate_reviewers_from_names(&self.teams, &self.config, &self.issue, &names),
candidate_reviewers_from_names(&ctx, &self.teams, &self.config, &self.issue, &names)
.await,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the tests into async because candidate_reviewers_from_names is async.

@ehuss
Copy link
Contributor

ehuss commented Apr 25, 2025

Can you please update the description with a detailed explanation of what is changing. From the title it is not clear to me what this is doing.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, remembering the previous requested name (r? name) would be required for rustbot reroll, but it shouldn't be required at all when we are just modifying the request logic to skip the existing reviewer.

In other words, you can get the current assignee directly from the issue passed to the handler. Then we should modify the assignment logic to ignore the previous assignee if a team (not a specific user) was requested.

@@ -678,7 +711,7 @@ async fn find_reviewer_from_names(
}
}

let candidates = candidate_reviewers_from_names(teams, config, issue, names)?;
let candidates = candidate_reviewers_from_names(ctx, teams, config, issue, names).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that #1947 completely refactors these tests and provides them access to an actual database, so it might be better to base the code on top of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, when #1947 is merged, I'll rewrite the test.

@xizheyin
Copy link
Contributor Author

Can you please update the description with a detailed explanation of what is changing. From the title it is not clear to me what this is doing.

As discussed in #triagebot > @rustbot reroll @ 💬, I optimized the logic for r? group. Each time an assignee is set, it is stored in the database, and when we use an r? group, such as r? compiler, I will take out the previously assigned reviewer from the database to avoid to assign a previous assignee.

However. the use of r? @reviewer to specify a specific assignee does not exclude the previous assignee, as this is explicitly specified.

@xizheyin xizheyin changed the title Pick reviewer which was not assigned before **only** when r? group Pick reviewer who is not previous assignee when r? group Apr 25, 2025
@xizheyin
Copy link
Contributor Author

In other words, you can get the current assignee directly from the issue passed to the handler.

issue.assignees seems to only return the current assignees, it may need the database if we want to get all the previous assignees of the issue.

@Kobzol
Copy link
Contributor

Kobzol commented Apr 25, 2025

Hmm, I was thinking that we only ignore the current reviewer, not all previously assigned reviewers 🤔 I'll ask others on Zulip.

@ehuss
Copy link
Contributor

ehuss commented Apr 25, 2025

As discussed in #triagebot > @rustbot reroll @ 💬, I optimized the logic for r? group. Each time an assignee is set, it is stored in the database, and when we use an r? group, such as r? compiler, I will take out the previously assigned reviewer from the database to avoid to assign a previous assignee.

However. the use of r? @reviewer to specify a specific assignee does not exclude the previous assignee, as this is explicitly specified.

OK, can the description be updated to include that? Or, if the design hasn't been concluded, can this be marked as a draft until it is ready?

Also, this doesn't seem like it would close #1762, would it? That seems like a different thing of the ability to say "I want triagebot to pick someone else".

@Kobzol
Copy link
Contributor

Kobzol commented Apr 25, 2025

FWIW, we have been discussing this in https://rust-lang.zulipchat.com/#narrow/channel/224082-triagebot/topic/.40rustbot.20reroll/with/514415765, and me and Jieyou Xu thought that having an explicit reroll command might not be needed if we make this change to the assignment logic.

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

Failed to set assignee to group: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

1 similar comment
@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

Failed to set assignee to group: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

Failed to set assignee to tgross35: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

Failed to set assignee to reviewer: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@xizheyin xizheyin force-pushed the reroll branch 5 times, most recently from cbbb5af to b0574b6 Compare May 9, 2025 09:43
@xizheyin xizheyin marked this pull request as draft May 9, 2025 09:47
This commit optimized the logic for `r? group`. Each time an assignee
is set, it is stored in the database, and when we use an r? group, such
as `r? compiler`, it will take out the previously assigned reviewers
from the database to avoid to assign a previous assignee.

Signed-off-by: xizheyin <[email protected]>
@xizheyin xizheyin marked this pull request as ready for review May 9, 2025 10:07
@xizheyin
Copy link
Contributor Author

xizheyin commented May 9, 2025

I rebase this PR to the newest version of master branch that is compatible with the latest test_candidates.rs.

@Kobzol
Copy link
Contributor

Kobzol commented May 11, 2025

Hi, just wanted to note that I'll be at https://rustweek.org/, so I might not be able to take a look at this for a few days, but it's at the top of my TODO list :)

@xizheyin
Copy link
Contributor Author

It looks great. Have fun! I don't think the demand for this pr is so urgent.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you. Could you please also add some tests? You could add a method to AssignCtx that will store a set of previously assigned names into the DB, and then check that these names will be ignored when expanded from a group/team, and will not be ignored when requested directly.

@@ -92,9 +93,23 @@ const REVIEWER_ALREADY_ASSIGNED: &str =

Please choose another assignee.";

const REVIEWER_ASSIGNED_BEFORE: &str = "Requested reviewers are assigned before.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const REVIEWER_ASSIGNED_BEFORE: &str = "Requested reviewers are assigned before.
const REVIEWER_ASSIGNED_BEFORE: &str = "Requested reviewer(s) were already assigned before.

/// State stored in the database
#[derive(Debug, Clone, PartialEq, Default, serde::Deserialize, serde::Serialize)]
struct Reviewers {
/// List of the last warnings in the most recent comment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong comment.

// Special account that we use to prevent assignment.
const GHOST_ACCOUNT: &str = "ghost";

/// Key for the state in the database
const PREVIOUS_REVIEWER_KEY: &str = "previous-reviewer";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const PREVIOUS_REVIEWER_KEY: &str = "previous-reviewer";
const PREVIOUS_REVIEWERS_KEY: &str = "previous-reviewers";

@@ -680,6 +710,8 @@ enum FindReviewerError {
ReviewerIsPrAuthor { username: String },
/// Requested reviewer is already assigned to that PR
ReviewerAlreadyAssigned { username: String },
/// Requested reviewer is already assigned previously to that PR.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Requested reviewer is already assigned previously to that PR.
/// Requested reviewer was already assigned previously to that PR.

write!(
f,
"{}",
REVIEWER_ASSIGNED_BEFORE.replace("{username}", username)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEWER_ASSIGNED_BEFORE doesn't seem to contain {username}? It shouldn't need any replacement.

@@ -963,6 +1008,12 @@ async fn candidate_reviewers_from_names<'a>(
Some(FindReviewerError::ReviewerAlreadyAssigned {
username: candidate.clone(),
})
} else if expansion_happend && is_previously_assigned {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to check expansion_happened here. We should decide per-reviewer basis if they were expanded or not. It's enough to check reviewer_candidate.origin here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add "bors reroll"
4 participants