Skip to content

Commit 9a2eebf

Browse files
authored
Merge pull request #1969 from Kobzol/pr-tracking-improvements
Handle drafts better in PR tracking and do not consider self-assigned PRs for the workqueue
2 parents 891b26d + 10ecdcc commit 9a2eebf

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
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: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ pub(super) async fn parse_input(
8282
})),
8383
// We don't need to handle Opened explicitly, because that will trigger the Assigned event
8484
IssuesAction::Reopened
85+
| IssuesAction::ReadyForReview
86+
| IssuesAction::ConvertedToDraft
8587
| IssuesAction::Closed
8688
| IssuesAction::Deleted
8789
| IssuesAction::Transferred
@@ -107,7 +109,7 @@ pub(super) async fn handle_input<'a>(
107109
// If the PR doesn't wait for a review, remove it from the workqueue completely.
108110
// This handles situations such as labels being modified, which make the PR no longer to be
109111
// in the "waiting for a review" state, or the PR being closed/merged.
110-
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) {
111113
log::info!(
112114
"Removing PR {pr_number} from workqueue, because it is not waiting for a review.",
113115
);
@@ -200,8 +202,23 @@ pub async fn retrieve_pull_request_assignments(
200202
.into_iter()
201203
.map(|l| Label { name: l.name })
202204
.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+
});
203218
if waits_for_a_review(
204219
&labels,
220+
&assignees,
221+
&author,
205222
pr.state == Some(IssueState::Open),
206223
pr.draft.unwrap_or_default(),
207224
) {
@@ -269,14 +286,26 @@ fn delete_pr_from_all_queues(workqueue: &mut ReviewerWorkqueue, pr: PullRequestN
269286
///
270287
/// Note: this functionality is currently hardcoded for rust-lang/rust, other repos might use
271288
/// different labels.
272-
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 {
273296
let is_blocked = labels
274297
.iter()
275298
.any(|l| l.name == "S-blocked" || l.name == "S-inactive");
276299
let is_rollup = labels.iter().any(|l| l.name == "rollup");
277300
let is_waiting_for_reviewer = labels.iter().any(|l| l.name == "S-waiting-on-review");
278-
279-
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
280309
}
281310

282311
#[cfg(test)]

src/zulip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ async fn workqueue_commands(
298298
pluralize("PR", assigned_prs.len())
299299
);
300300
writeln!(response, "Review capacity: {capacity}\n")?;
301-
writeln!(response, "*Note that only selected PRs that are assigned to you are considered as being in the review queue.*")?;
301+
writeln!(response, "*Note that only certain PRs that are assigned to you are included in your review queue.*")?;
302302
response
303303
}
304304
"set-pr-limit" => {

0 commit comments

Comments
 (0)