|
1 | 1 | use crate::config::ReviewRequestedConfig; |
2 | | -use crate::github::{Event, IssuesAction, IssuesEvent, Label}; |
| 2 | +use crate::github::{IssuesAction, IssuesEvent, Label}; |
3 | 3 | use crate::handlers::Context; |
4 | 4 |
|
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( |
6 | 30 | ctx: &Context, |
7 | | - event: &Event, |
8 | 31 | config: &ReviewRequestedConfig, |
| 32 | + event: &IssuesEvent, |
| 33 | + ReviewRequestedInput {}: ReviewRequestedInput, |
9 | 34 | ) -> 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?; |
37 | 50 | } |
38 | 51 |
|
39 | 52 | Ok(()) |
|
0 commit comments