Skip to content

Commit 63eaec4

Browse files
committed
Move retrieve_pull_request_assignments to pr_tracking
Because it needs to use custom logic for determining if a PR is truly assigned to someone and waiting for a review.
1 parent f32d780 commit 63eaec4

File tree

3 files changed

+58
-57
lines changed

3 files changed

+58
-57
lines changed

src/github.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ use anyhow::{anyhow, Context};
22
use async_trait::async_trait;
33
use bytes::Bytes;
44
use chrono::{DateTime, FixedOffset, Utc};
5-
use futures::{future::BoxFuture, FutureExt, TryStreamExt};
5+
use futures::{future::BoxFuture, FutureExt};
66
use hyper::header::HeaderValue;
7-
use octocrab::params::pulls::Sort;
8-
use octocrab::params::{Direction, State};
9-
use octocrab::Octocrab;
107
use regex::Regex;
118
use reqwest::header::{AUTHORIZATION, USER_AGENT};
129
use reqwest::{Client, Request, RequestBuilder, Response, StatusCode};
@@ -3053,57 +3050,6 @@ async fn project_items_by_status(
30533050
Ok(all_items)
30543051
}
30553052

3056-
/// Retrieve tuples of (user, PR number) where
3057-
/// the given user is assigned as a reviewer for that PR.
3058-
/// Only non-draft, non-rollup and open PRs are taken into account.
3059-
pub async fn retrieve_pull_request_assignments(
3060-
owner: &str,
3061-
repository: &str,
3062-
client: &Octocrab,
3063-
) -> anyhow::Result<Vec<(User, PullRequestNumber)>> {
3064-
let mut assignments = vec![];
3065-
3066-
// We use the REST API to fetch open pull requests, as it is much (~5-10x)
3067-
// faster than using GraphQL here.
3068-
let stream = client
3069-
.pulls(owner, repository)
3070-
.list()
3071-
.state(State::Open)
3072-
.direction(Direction::Ascending)
3073-
.sort(Sort::Created)
3074-
.per_page(100)
3075-
.send()
3076-
.await?
3077-
.into_stream(client);
3078-
let mut stream = std::pin::pin!(stream);
3079-
while let Some(pr) = stream.try_next().await? {
3080-
if pr.draft == Some(true) {
3081-
continue;
3082-
}
3083-
// exclude rollup PRs
3084-
if pr
3085-
.labels
3086-
.unwrap_or_default()
3087-
.iter()
3088-
.any(|label| label.name == "rollup")
3089-
{
3090-
continue;
3091-
}
3092-
for user in pr.assignees.unwrap_or_default() {
3093-
assignments.push((
3094-
User {
3095-
login: user.login,
3096-
id: (*user.id).into(),
3097-
},
3098-
pr.number,
3099-
));
3100-
}
3101-
}
3102-
assignments.sort_by(|a, b| a.0.id.cmp(&b.0.id));
3103-
3104-
Ok(assignments)
3105-
}
3106-
31073053
pub enum DesignMeetingStatus {
31083054
Proposed,
31093055
Scheduled,

src/handlers/pr_tracking.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use crate::{
1313
github::{IssuesAction, IssuesEvent},
1414
handlers::Context,
1515
};
16+
use futures::TryStreamExt;
17+
use octocrab::params::pulls::Sort;
18+
use octocrab::params::{Direction, State};
19+
use octocrab::Octocrab;
1620
use std::collections::{HashMap, HashSet};
1721
use tracing as log;
1822

@@ -126,6 +130,57 @@ pub(super) async fn handle_input<'a>(
126130
Ok(())
127131
}
128132

133+
/// Retrieve tuples of (user, PR number) where
134+
/// the given user is assigned as a reviewer for that PR.
135+
/// Only non-draft, non-rollup and open PRs are taken into account.
136+
pub async fn retrieve_pull_request_assignments(
137+
owner: &str,
138+
repository: &str,
139+
client: &Octocrab,
140+
) -> anyhow::Result<Vec<(User, PullRequestNumber)>> {
141+
let mut assignments = vec![];
142+
143+
// We use the REST API to fetch open pull requests, as it is much (~5-10x)
144+
// faster than using GraphQL here.
145+
let stream = client
146+
.pulls(owner, repository)
147+
.list()
148+
.state(State::Open)
149+
.direction(Direction::Ascending)
150+
.sort(Sort::Created)
151+
.per_page(100)
152+
.send()
153+
.await?
154+
.into_stream(client);
155+
let mut stream = std::pin::pin!(stream);
156+
while let Some(pr) = stream.try_next().await? {
157+
if pr.draft == Some(true) {
158+
continue;
159+
}
160+
// exclude rollup PRs
161+
if pr
162+
.labels
163+
.unwrap_or_default()
164+
.iter()
165+
.any(|label| label.name == "rollup")
166+
{
167+
continue;
168+
}
169+
for user in pr.assignees.unwrap_or_default() {
170+
assignments.push((
171+
User {
172+
login: user.login,
173+
id: (*user.id).into(),
174+
},
175+
pr.number,
176+
));
177+
}
178+
}
179+
assignments.sort_by(|a, b| a.0.id.cmp(&b.0.id));
180+
181+
Ok(assignments)
182+
}
183+
129184
/// Get pull request assignments for a team member
130185
pub async fn get_assigned_prs(ctx: &Context, user_id: UserId) -> HashSet<PullRequestNumber> {
131186
ctx.workqueue

src/handlers/pull_requests_assignment_update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::github::PullRequestNumber;
2-
use crate::github::{retrieve_pull_request_assignments, UserId};
3-
use crate::handlers::pr_tracking::ReviewerWorkqueue;
2+
use crate::github::UserId;
3+
use crate::handlers::pr_tracking::{retrieve_pull_request_assignments, ReviewerWorkqueue};
44
use crate::jobs::Job;
55
use async_trait::async_trait;
66
use octocrab::Octocrab;

0 commit comments

Comments
 (0)