From 90a64f5201cd570c31294eeb4e39e7bc7c551dc2 Mon Sep 17 00:00:00 2001 From: Aphek Date: Fri, 26 Dec 2025 03:25:18 -0300 Subject: [PATCH 1/2] Fix monthly notifications --- src/notification.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/notification.rs b/src/notification.rs index ee4a709..b6882cd 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -115,7 +115,13 @@ pub async fn notify_build_failure( jiff::Timestamp::from_millisecond(last_update_date).is_ok_and(|last_update_date| { jiff::Timestamp::now() .since(last_update_date) - .is_ok_and(|diff| diff.get_months() > 0) + .is_ok_and(|diff| { + diff.total(( + jiff::Unit::Month, + &last_update_date.to_zoned(jiff::tz::TimeZone::UTC), + )) + .is_ok_and(|diff_months| diff_months >= 1.0) + }) }) }) { info!( From 3a1695c554d8f07aac47a11f516ff65db7420ca6 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Fri, 26 Dec 2025 13:32:31 +0100 Subject: [PATCH 2/2] test --- src/notification.rs | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/notification.rs b/src/notification.rs index b6882cd..264c93e 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -86,6 +86,19 @@ pub async fn notify_build( } } +fn should_notify_since_last_notification( + last_notification: jiff::Timestamp, + now: jiff::Timestamp, +) -> bool { + now.since(last_notification).is_ok_and(|diff| { + diff.total(( + jiff::Unit::Month, + &last_notification.to_zoned(jiff::tz::TimeZone::UTC), + )) + .is_ok_and(|diff_months| diff_months >= 1.0) + }) +} + pub async fn notify_build_failure( github_client: &GitHubClient, db: &Db, @@ -113,15 +126,7 @@ pub async fn notify_build_failure( if issue.last_update_date.is_none_or(|last_update_date| { jiff::Timestamp::from_millisecond(last_update_date).is_ok_and(|last_update_date| { - jiff::Timestamp::now() - .since(last_update_date) - .is_ok_and(|diff| { - diff.total(( - jiff::Unit::Month, - &last_update_date.to_zoned(jiff::tz::TimeZone::UTC), - )) - .is_ok_and(|diff_months| diff_months >= 1.0) - }) + should_notify_since_last_notification(last_update_date, jiff::Timestamp::now()) }) }) { info!( @@ -280,3 +285,22 @@ pub async fn notify_build_pass( Ok(()) } + +#[cfg(test)] +mod tests { + #[test] + fn should_notify_since_last_notification() { + assert!(super::should_notify_since_last_notification( + "2025-11-01T00:00:00Z".parse().unwrap(), + "2025-12-02T00:00:00Z".parse().unwrap() + )); + assert!(super::should_notify_since_last_notification( + "2025-09-01T00:00:00Z".parse().unwrap(), + "2025-12-02T00:00:00Z".parse().unwrap() + )); + assert!(!super::should_notify_since_last_notification( + "2025-11-02T00:00:00Z".parse().unwrap(), + "2025-12-01T00:00:00Z".parse().unwrap() + )); + } +}