gitlab_tracker_notify/
lib.rs1#[cfg(feature = "desktop")]
14fn show_with_url(notification: notify_rust::Notification, url: String) {
15 if let Ok(handle) = notification.show() {
16 std::thread::spawn(move || {
17 handle.wait_for_action(|action| {
18 if action == "default" {
19 let _ = open::that(&url);
20 }
21 });
22 });
23 }
24}
25
26#[cfg(feature = "desktop")]
30pub fn mr_on_new_branch(mr_id: &str, title: &str, branch: &str, web_url: &str) {
31 let notification = notify_rust::Notification::new()
32 .summary("GitLab MR Tracker")
33 .body(&format!(
34 "MR !{} ({}) is now present on branch '{}'!",
35 mr_id, title, branch
36 ))
37 .icon("dialog-information")
38 .action("default", "Open MR")
39 .finalize();
40 show_with_url(notification, web_url.to_owned());
41}
42
43#[cfg(feature = "desktop")]
45pub fn mr_updated(mr_id: &str, title: &str, updated_at: Option<&str>, web_url: &str) {
46 let notification = notify_rust::Notification::new()
47 .summary(&format!("MR !{} updated", mr_id))
48 .body(&format!(
49 "{}\n{}",
50 title,
51 updated_at.unwrap_or("unknown date")
52 ))
53 .icon("dialog-information")
54 .action("default", "Open MR")
55 .finalize();
56 show_with_url(notification, web_url.to_owned());
57}
58
59#[cfg(feature = "desktop")]
62pub fn mr_mergeability_changed(mr_id: &str, title: &str, old: &str, new: &str, web_url: &str) {
63 let notification = notify_rust::Notification::new()
64 .summary(&format!("MR !{} — mergeability changed", mr_id))
65 .body(&format!("{}\n{} → {}", title, old, new))
66 .icon("dialog-warning")
67 .action("default", "Open MR")
68 .finalize();
69 show_with_url(notification, web_url.to_owned());
70}
71
72#[cfg(feature = "desktop")]
74pub fn mr_milestone_changed(mr_id: &str, title: &str, old: &str, new: &str, web_url: &str) {
75 let notification = notify_rust::Notification::new()
76 .summary(&format!("MR !{} — milestone changed", mr_id))
77 .body(&format!("{}\n{} → {}", title, old, new))
78 .icon("dialog-information")
79 .action("default", "Open MR")
80 .finalize();
81 show_with_url(notification, web_url.to_owned());
82}
83
84#[cfg(feature = "desktop")]
99pub fn ticket_field_changed(
100 ticket_id: &str,
101 mr_title: &str,
102 field: &str,
103 old: &str,
104 new: &str,
105 ticket_url: &str,
106) {
107 let icon = if field == "priority" {
108 "dialog-warning"
109 } else {
110 "dialog-information"
111 };
112 let notification = notify_rust::Notification::new()
113 .summary(&format!("Ticket #{} — {} changed", ticket_id, field))
114 .body(&format!("{}\n{} → {}", mr_title, old, new))
115 .icon(icon)
116 .action("default", "Open ticket")
117 .finalize();
118 show_with_url(notification, ticket_url.to_owned());
119}
120
121#[cfg(not(feature = "desktop"))]
124#[inline(always)]
125pub fn mr_on_new_branch(_mr_id: &str, _title: &str, _branch: &str, _web_url: &str) {}
126
127#[cfg(not(feature = "desktop"))]
128#[inline(always)]
129pub fn mr_updated(_mr_id: &str, _title: &str, _updated_at: Option<&str>, _web_url: &str) {}
130
131#[cfg(not(feature = "desktop"))]
132#[inline(always)]
133pub fn mr_mergeability_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str, _web_url: &str) {
134}
135
136#[cfg(not(feature = "desktop"))]
137#[inline(always)]
138pub fn mr_milestone_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str, _web_url: &str) {}
139
140#[cfg(not(feature = "desktop"))]
141#[inline(always)]
142pub fn ticket_field_changed(
143 _ticket_id: &str,
144 _mr_title: &str,
145 _field: &str,
146 _old: &str,
147 _new: &str,
148 _ticket_url: &str,
149) {
150}