From e1decffe738e7b8194f3c345a27c26ef9b608eb6 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 29 Jun 2025 14:46:08 +0200 Subject: [PATCH 1/4] Remove `new_pr` labels when converting to draft --- src/handlers/autolabel.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/handlers/autolabel.rs b/src/handlers/autolabel.rs index 0a16dbe7c..a84da6cf0 100644 --- a/src/handlers/autolabel.rs +++ b/src/handlers/autolabel.rs @@ -39,7 +39,10 @@ pub(super) async fn parse_input( // synchronize may be straddling a rebase, which will break diff generation. if matches!( event.action, - IssuesAction::Opened | IssuesAction::Synchronize | IssuesAction::ReadyForReview + IssuesAction::Opened + | IssuesAction::Synchronize + | IssuesAction::ReadyForReview + | IssuesAction::ConvertedToDraft ) { let mut db = ctx.db.get().await; let mut state: IssueData<'_, AutolabelState> = @@ -55,7 +58,9 @@ pub(super) async fn parse_input( log::error!("failed to fetch diff: {:?}", e); }) .unwrap_or_default(); + let mut autolabels = Vec::new(); + let mut to_remove = Vec::new(); 'outer: for (label, cfg) in config.labels.iter() { let exclude_patterns: Vec = cfg @@ -108,6 +113,14 @@ pub(super) async fn parse_input( }); state.data.new_pr_labels_applied = true; } + + // If a PR is converted to draft remove all the "new PR" labels + if cfg.new_pr && event.action == IssuesAction::ConvertedToDraft { + to_remove.push(Label { + name: label.to_owned(), + }); + state.data.new_pr_labels_applied = false; + } } else { if cfg.new_issue && event.action == IssuesAction::Opened { autolabels.push(Label { @@ -119,10 +132,10 @@ pub(super) async fn parse_input( state.save().await.map_err(|e| e.to_string())?; - if !autolabels.is_empty() { + if !autolabels.is_empty() || !to_remove.is_empty() { return Ok(Some(AutolabelInput { add: autolabels, - remove: vec![], + remove: to_remove, })); } } From 0c505345678fda3b0f703bc2110ef352ef252e56 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 30 Jun 2025 23:07:16 +0200 Subject: [PATCH 2/4] Remove autolabel `new_pr_labels_applied` state --- src/handlers/autolabel.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/handlers/autolabel.rs b/src/handlers/autolabel.rs index a84da6cf0..1b03ee42c 100644 --- a/src/handlers/autolabel.rs +++ b/src/handlers/autolabel.rs @@ -1,4 +1,3 @@ -use crate::db::issue_data::IssueData; use crate::{ config::AutolabelConfig, github::{IssuesAction, IssuesEvent, Label}, @@ -7,16 +6,6 @@ use crate::{ use anyhow::Context as _; use tracing as log; -/// Key for the state in the database -const AUTOLABEL_KEY: &str = "autolabel"; - -/// State stored in the database -#[derive(Debug, Default, PartialEq, Clone, serde::Deserialize, serde::Serialize)] -struct AutolabelState { - /// If true, then `autolabel.new_pr` labels have already been applied to this PR. - new_pr_labels_applied: bool, -} - pub(super) struct AutolabelInput { add: Vec