diff --git a/src/config.rs b/src/config.rs index cbd682e9..b9853552 100644 --- a/src/config.rs +++ b/src/config.rs @@ -34,6 +34,7 @@ pub(crate) struct Config { pub(crate) review_requested: Option, pub(crate) converted_to_draft: Option, pub(crate) ready_for_review: Option, + pub(crate) closed_pr: Option, pub(crate) shortcut: Option, pub(crate) note: Option, pub(crate) mentions: Option, @@ -311,6 +312,13 @@ pub(crate) struct ReadyForReviewConfig { pub(crate) add_labels: Vec, } +#[derive(PartialEq, Eq, Debug, serde::Deserialize)] +#[serde(deny_unknown_fields)] +pub(crate) struct ClosedPrConfig { + pub(crate) remove_labels: Vec, + pub(crate) add_labels: Vec, +} + pub(crate) async fn get( gh: &GithubClient, repo: &Repository, diff --git a/src/handlers.rs b/src/handlers.rs index cdce3af7..0a7d3347 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -26,6 +26,7 @@ impl fmt::Display for HandlerError { mod assign; mod autolabel; mod close; +mod closed_pr; mod converted_to_draft; pub mod docs_update; mod github_releases; @@ -171,6 +172,7 @@ issue_handlers! { review_requested, converted_to_draft, ready_for_review, + closed_pr, validate_config, } diff --git a/src/handlers/closed_pr.rs b/src/handlers/closed_pr.rs new file mode 100644 index 00000000..1ad15480 --- /dev/null +++ b/src/handlers/closed_pr.rs @@ -0,0 +1,44 @@ +use crate::config::ClosedPrConfig; +use crate::github::{IssuesAction, IssuesEvent, Label}; +use crate::handlers::Context; + +pub(crate) struct ClosedPrInput {} + +pub(crate) async fn parse_input( + _ctx: &Context, + event: &IssuesEvent, + _config: Option<&ClosedPrConfig>, +) -> Result, String> { + // PR author requests a review from one of the assignees + + match &event.action { + IssuesAction::Closed if event.issue.is_pr() => Ok(Some(ClosedPrInput {})), + _ => Ok(None), + } +} + +pub(crate) async fn handle_input( + ctx: &Context, + config: &ClosedPrConfig, + event: &IssuesEvent, + ClosedPrInput {}: ClosedPrInput, +) -> anyhow::Result<()> { + event + .issue + .add_labels( + &ctx.github, + config + .add_labels + .iter() + .cloned() + .map(|name| Label { name }) + .collect(), + ) + .await?; + + for label in &config.remove_labels { + event.issue.remove_label(&ctx.github, label).await?; + } + + Ok(()) +}