Skip to main content

gitlab_tracker_notify/
lib.rs

1//! Desktop notification plugin for gitlab-tracker.
2//!
3//! Compiled with the `desktop` feature (on by default) to send OS notifications
4//! via `notify-rust`. Build with `--no-default-features` for a zero-dependency
5//! stub suitable for headless / CI environments.
6
7// ── Notification events ──────────────────────────────────────────────────────
8
9/// Notify that an MR has appeared on a branch it was not previously seen on.
10#[cfg(feature = "desktop")]
11pub fn mr_on_new_branch(mr_id: &str, title: &str, branch: &str) {
12    let _ = notify_rust::Notification::new()
13        .summary("GitLab MR Tracker")
14        .body(&format!(
15            "MR !{} ({}) is now present on branch '{}'!",
16            mr_id, title, branch
17        ))
18        .icon("dialog-information")
19        .show();
20}
21
22/// Notify that an MR's `updated_at` field has changed (i.e. the MR was modified).
23#[cfg(feature = "desktop")]
24pub fn mr_updated(mr_id: &str, title: &str, updated_at: Option<&str>) {
25    let _ = notify_rust::Notification::new()
26        .summary(&format!("MR !{} updated", mr_id))
27        .body(&format!(
28            "{}\n{}",
29            title,
30            updated_at.unwrap_or("unknown date")
31        ))
32        .icon("dialog-information")
33        .show();
34}
35
36/// Notify that an MR's mergeability status has changed.
37/// Accepts string labels so this crate stays independent of gitlab-tracker model types.
38#[cfg(feature = "desktop")]
39pub fn mr_mergeability_changed(mr_id: &str, title: &str, old: &str, new: &str) {
40    let _ = notify_rust::Notification::new()
41        .summary(&format!("MR !{} — mergeability changed", mr_id))
42        .body(&format!("{}\n{} → {}", title, old, new))
43        .icon("dialog-warning")
44        .show();
45}
46
47/// Notify that an MR's milestone has changed.
48#[cfg(feature = "desktop")]
49pub fn mr_milestone_changed(mr_id: &str, title: &str, old: &str, new: &str) {
50    let _ = notify_rust::Notification::new()
51        .summary(&format!("MR !{} — milestone changed", mr_id))
52        .body(&format!("{}\n{} → {}", title, old, new))
53        .icon("dialog-information")
54        .show();
55}
56
57// ── No-op stubs when the `desktop` feature is disabled ───────────────────────
58
59#[cfg(not(feature = "desktop"))]
60#[inline(always)]
61pub fn mr_on_new_branch(_mr_id: &str, _title: &str, _branch: &str) {}
62
63#[cfg(not(feature = "desktop"))]
64#[inline(always)]
65pub fn mr_updated(_mr_id: &str, _title: &str, _updated_at: Option<&str>) {}
66
67#[cfg(not(feature = "desktop"))]
68#[inline(always)]
69pub fn mr_mergeability_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str) {}
70
71#[cfg(not(feature = "desktop"))]
72#[inline(always)]
73pub fn mr_milestone_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str) {}