Skip to content

Commit df337f7

Browse files
committed
Do not consider self-assigned PRs for the workqueue
1 parent a24ac27 commit df337f7

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/github.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bytes::Bytes;
44
use chrono::{DateTime, FixedOffset, Utc};
55
use futures::{future::BoxFuture, FutureExt};
66
use hyper::header::HeaderValue;
7+
use octocrab::models::Author;
78
use regex::Regex;
89
use reqwest::header::{AUTHORIZATION, USER_AGENT};
910
use reqwest::{Client, Request, RequestBuilder, Response, StatusCode};
@@ -24,6 +25,15 @@ pub struct User {
2425
pub id: UserId,
2526
}
2627

28+
impl From<&Author> for User {
29+
fn from(author: &Author) -> Self {
30+
Self {
31+
id: author.id.0,
32+
login: author.login.clone(),
33+
}
34+
}
35+
}
36+
2737
impl GithubClient {
2838
async fn send_req(&self, req: RequestBuilder) -> anyhow::Result<(Bytes, String)> {
2939
const MAX_ATTEMPTS: u32 = 2;

src/handlers/pr_tracking.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub(super) async fn handle_input<'a>(
109109
// If the PR doesn't wait for a review, remove it from the workqueue completely.
110110
// This handles situations such as labels being modified, which make the PR no longer to be
111111
// in the "waiting for a review" state, or the PR being closed/merged.
112-
if !waits_for_a_review(&pr.labels, pr.is_open(), pr.draft) {
112+
if !waits_for_a_review(&pr.labels, &pr.assignees, &pr.user, pr.is_open(), pr.draft) {
113113
log::info!(
114114
"Removing PR {pr_number} from workqueue, because it is not waiting for a review.",
115115
);
@@ -202,8 +202,23 @@ pub async fn retrieve_pull_request_assignments(
202202
.into_iter()
203203
.map(|l| Label { name: l.name })
204204
.collect::<Vec<Label>>();
205+
let assignees = pr
206+
.assignees
207+
.as_ref()
208+
.map(|authors| authors.iter().map(User::from).collect::<Vec<_>>())
209+
.unwrap_or_default();
210+
let author = pr
211+
.user
212+
.as_ref()
213+
.map(|author| User::from(author.as_ref()))
214+
.unwrap_or_else(|| User {
215+
login: "ghost".to_string(),
216+
id: 0,
217+
});
205218
if waits_for_a_review(
206219
&labels,
220+
&assignees,
221+
&author,
207222
pr.state == Some(IssueState::Open),
208223
pr.draft.unwrap_or_default(),
209224
) {
@@ -271,14 +286,26 @@ fn delete_pr_from_all_queues(workqueue: &mut ReviewerWorkqueue, pr: PullRequestN
271286
///
272287
/// Note: this functionality is currently hardcoded for rust-lang/rust, other repos might use
273288
/// different labels.
274-
fn waits_for_a_review(labels: &[Label], is_open: bool, is_draft: bool) -> bool {
289+
fn waits_for_a_review(
290+
labels: &[Label],
291+
assignees: &[User],
292+
author: &User,
293+
is_open: bool,
294+
is_draft: bool,
295+
) -> bool {
275296
let is_blocked = labels
276297
.iter()
277298
.any(|l| l.name == "S-blocked" || l.name == "S-inactive");
278299
let is_rollup = labels.iter().any(|l| l.name == "rollup");
279300
let is_waiting_for_reviewer = labels.iter().any(|l| l.name == "S-waiting-on-review");
280-
281-
is_open && !is_draft && !is_blocked && !is_rollup && is_waiting_for_reviewer
301+
let is_assigned_to_author = assignees.contains(author);
302+
303+
is_open
304+
&& !is_draft
305+
&& !is_blocked
306+
&& !is_rollup
307+
&& is_waiting_for_reviewer
308+
&& !is_assigned_to_author
282309
}
283310

284311
#[cfg(test)]

0 commit comments

Comments
 (0)