Skip to content

Commit 7a0a772

Browse files
committed
Add a handler for requested reviews
1 parent 559e1d3 commit 7a0a772

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) struct Config {
3030
pub(crate) notify_zulip: Option<NotifyZulipConfig>,
3131
pub(crate) github_releases: Option<GitHubReleasesConfig>,
3232
pub(crate) review_submitted: Option<ReviewSubmittedConfig>,
33+
pub(crate) review_requested: Option<ReviewRequestedConfig>,
3334
pub(crate) shortcut: Option<ShortcutConfig>,
3435
pub(crate) note: Option<NoteConfig>,
3536
pub(crate) mentions: Option<MentionsConfig>,
@@ -253,6 +254,12 @@ pub(crate) struct ReviewSubmittedConfig {
253254
pub(crate) reviewed_label: String,
254255
}
255256

257+
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
258+
pub(crate) struct ReviewRequestedConfig {
259+
pub(crate) remove_labels: Vec<String>,
260+
pub(crate) add_labels: Vec<String>,
261+
}
262+
256263
pub(crate) async fn get(
257264
gh: &GithubClient,
258265
repo: &Repository,
@@ -421,6 +428,7 @@ mod tests {
421428
notify_zulip: None,
422429
github_releases: None,
423430
review_submitted: None,
431+
review_requested: None,
424432
mentions: None,
425433
no_merges: None,
426434
}

src/handlers.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mod notify_zulip;
4141
mod ping;
4242
mod prioritize;
4343
mod relabel;
44+
mod review_requested;
4445
mod review_submitted;
4546
mod rfc_helper;
4647
pub mod rustc_commits;
@@ -107,6 +108,20 @@ pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
107108
}
108109
}
109110

111+
if let Some(config) = config
112+
.as_ref()
113+
.ok()
114+
.and_then(|c| c.review_requested.as_ref())
115+
{
116+
if let Err(e) = review_requested::handle(ctx, event, config).await {
117+
log::error!(
118+
"failed to process event {:?} with review_requested handler: {:?}",
119+
event,
120+
e
121+
)
122+
}
123+
}
124+
110125
if let Some(ghr_config) = config
111126
.as_ref()
112127
.ok()

src/handlers/review_requested.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::config::ReviewRequestedConfig;
2+
use crate::github::{Event, IssuesAction, IssuesEvent, Label};
3+
use crate::handlers::Context;
4+
5+
pub(crate) async fn handle(
6+
ctx: &Context,
7+
event: &Event,
8+
config: &ReviewRequestedConfig,
9+
) -> anyhow::Result<()> {
10+
// PR author requests a review from one of the assignees
11+
if let Event::Issue(IssuesEvent {
12+
action,
13+
issue,
14+
sender,
15+
..
16+
}) = event
17+
{
18+
if let IssuesAction::ReviewRequested { requested_reviewer } = action {
19+
if *sender == issue.user && issue.assignees.contains(requested_reviewer) {
20+
issue
21+
.add_labels(
22+
&ctx.github,
23+
config
24+
.add_labels
25+
.iter()
26+
.cloned()
27+
.map(|name| Label { name })
28+
.collect(),
29+
)
30+
.await?;
31+
32+
for label in &config.remove_labels {
33+
issue.remove_label(&ctx.github, label).await?;
34+
}
35+
}
36+
}
37+
}
38+
39+
Ok(())
40+
}

0 commit comments

Comments
 (0)