From 10955be6968ff76bc25d1c455d9fac611fdd64f1 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 1 Jul 2025 19:15:03 +0200 Subject: [PATCH] Handle base branch changed in `[autolabel]` and check-commits --- src/github.rs | 8 ++++++++ src/handlers/autolabel.rs | 2 ++ src/handlers/check_commits.rs | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/github.rs b/src/github.rs index d3858bf8..4e69e66c 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1116,6 +1116,7 @@ pub struct ChangeInner { pub struct Changes { pub title: Option, pub body: Option, + pub base: Option, } #[derive(PartialEq, Eq, Debug, serde::Deserialize)] @@ -1228,6 +1229,13 @@ pub struct IssuesEvent { pub sender: User, } +impl IssuesEvent { + pub fn has_base_changed(&self) -> bool { + matches!(self.action, IssuesAction::Edited) + && matches!(&self.changes, Some(changes) if changes.base.is_some()) + } +} + #[derive(Debug, serde::Deserialize)] struct PullRequestEventFields {} diff --git a/src/handlers/autolabel.rs b/src/handlers/autolabel.rs index 83adf78c..3693760a 100644 --- a/src/handlers/autolabel.rs +++ b/src/handlers/autolabel.rs @@ -20,6 +20,7 @@ pub(super) async fn parse_input( Some(config) => config, None => return Ok(None), }; + // On opening a new PR or sync'ing the branch, look at the diff and try to // add any appropriate labels. // @@ -39,6 +40,7 @@ pub(super) async fn parse_input( | IssuesAction::ReadyForReview | IssuesAction::ConvertedToDraft ) + || event.has_base_changed() { let files = if can_trigger_files { event diff --git a/src/handlers/check_commits.rs b/src/handlers/check_commits.rs index f7f173dc..d4eeb754 100644 --- a/src/handlers/check_commits.rs +++ b/src/handlers/check_commits.rs @@ -50,7 +50,8 @@ pub(super) async fn handle(ctx: &Context, event: &Event, config: &Config) -> any | IssuesAction::Reopened | IssuesAction::Synchronize | IssuesAction::ReadyForReview - ) || !event.issue.is_pr() + ) || !event.has_base_changed() + || !event.issue.is_pr() { return Ok(()); }