Skip to content

Commit 9563aff

Browse files
committed
Un-ad-hoc review_requested handler
Use the `issue_handlers!` instead
1 parent 7a0a772 commit 9563aff

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

src/handlers.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ pub async fn handle(ctx: &Context, event: &Event) -> Vec<HandlerError> {
108108
}
109109
}
110110

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-
125111
if let Some(ghr_config) = config
126112
.as_ref()
127113
.ok()
@@ -179,6 +165,7 @@ issue_handlers! {
179165
mentions,
180166
no_merges,
181167
notify_zulip,
168+
review_requested,
182169
}
183170

184171
macro_rules! command_handlers {

src/handlers/review_requested.rs

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
11
use crate::config::ReviewRequestedConfig;
2-
use crate::github::{Event, IssuesAction, IssuesEvent, Label};
2+
use crate::github::{IssuesAction, IssuesEvent, Label};
33
use crate::handlers::Context;
44

5-
pub(crate) async fn handle(
5+
pub(crate) struct ReviewRequestedInput {}
6+
7+
pub(crate) async fn parse_input(
8+
_ctx: &Context,
9+
event: &IssuesEvent,
10+
_config: Option<&ReviewRequestedConfig>,
11+
) -> Result<Option<ReviewRequestedInput>, String> {
12+
// PR author requests a review from one of the assignees
13+
14+
let IssuesAction::ReviewRequested { requested_reviewer } = &event.action else {
15+
return Ok(None);
16+
};
17+
18+
if event.sender != event.issue.user {
19+
return Ok(None);
20+
}
21+
22+
if !event.issue.assignees.contains(requested_reviewer) {
23+
return Ok(None);
24+
}
25+
26+
Ok(Some(ReviewRequestedInput {}))
27+
}
28+
29+
pub(crate) async fn handle_input(
630
ctx: &Context,
7-
event: &Event,
831
config: &ReviewRequestedConfig,
32+
event: &IssuesEvent,
33+
ReviewRequestedInput {}: ReviewRequestedInput,
934
) -> 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-
}
35+
event
36+
.issue
37+
.add_labels(
38+
&ctx.github,
39+
config
40+
.add_labels
41+
.iter()
42+
.cloned()
43+
.map(|name| Label { name })
44+
.collect(),
45+
)
46+
.await?;
47+
48+
for label in &config.remove_labels {
49+
event.issue.remove_label(&ctx.github, label).await?;
3750
}
3851

3952
Ok(())

0 commit comments

Comments
 (0)