#[cfg(feature = "desktop")]
fn show_with_url(notification: notify_rust::Notification, url: String) {
if let Ok(handle) = notification.show() {
std::thread::spawn(move || {
handle.wait_for_action(|action| {
if action == "default" {
let _ = open::that(&url);
}
});
});
}
}
#[cfg(feature = "desktop")]
pub fn mr_on_new_branch(mr_id: &str, title: &str, branch: &str, web_url: &str) {
let notification = notify_rust::Notification::new()
.summary("GitLab MR Tracker")
.body(&format!(
"MR !{} ({}) is now present on branch '{}'!",
mr_id, title, branch
))
.icon("dialog-information")
.action("default", "Open MR")
.finalize();
show_with_url(notification, web_url.to_owned());
}
#[cfg(feature = "desktop")]
pub fn mr_updated(mr_id: &str, title: &str, updated_at: Option<&str>, web_url: &str) {
let notification = notify_rust::Notification::new()
.summary(&format!("MR !{} updated", mr_id))
.body(&format!(
"{}\n{}",
title,
updated_at.unwrap_or("unknown date")
))
.icon("dialog-information")
.action("default", "Open MR")
.finalize();
show_with_url(notification, web_url.to_owned());
}
#[cfg(feature = "desktop")]
pub fn mr_mergeability_changed(mr_id: &str, title: &str, old: &str, new: &str, web_url: &str) {
let notification = notify_rust::Notification::new()
.summary(&format!("MR !{} — mergeability changed", mr_id))
.body(&format!("{}\n{} → {}", title, old, new))
.icon("dialog-warning")
.action("default", "Open MR")
.finalize();
show_with_url(notification, web_url.to_owned());
}
#[cfg(feature = "desktop")]
pub fn mr_milestone_changed(mr_id: &str, title: &str, old: &str, new: &str, web_url: &str) {
let notification = notify_rust::Notification::new()
.summary(&format!("MR !{} — milestone changed", mr_id))
.body(&format!("{}\n{} → {}", title, old, new))
.icon("dialog-information")
.action("default", "Open MR")
.finalize();
show_with_url(notification, web_url.to_owned());
}
#[cfg(feature = "desktop")]
pub fn ticket_field_changed(
ticket_id: &str,
mr_title: &str,
field: &str,
old: &str,
new: &str,
ticket_url: &str,
) {
let icon = if field == "priority" {
"dialog-warning"
} else {
"dialog-information"
};
let notification = notify_rust::Notification::new()
.summary(&format!("Ticket #{} — {} changed", ticket_id, field))
.body(&format!("{}\n{} → {}", mr_title, old, new))
.icon(icon)
.action("default", "Open ticket")
.finalize();
show_with_url(notification, ticket_url.to_owned());
}
#[cfg(not(feature = "desktop"))]
#[inline(always)]
pub fn mr_on_new_branch(_mr_id: &str, _title: &str, _branch: &str, _web_url: &str) {}
#[cfg(not(feature = "desktop"))]
#[inline(always)]
pub fn mr_updated(_mr_id: &str, _title: &str, _updated_at: Option<&str>, _web_url: &str) {}
#[cfg(not(feature = "desktop"))]
#[inline(always)]
pub fn mr_mergeability_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str, _web_url: &str) {
}
#[cfg(not(feature = "desktop"))]
#[inline(always)]
pub fn mr_milestone_changed(_mr_id: &str, _title: &str, _old: &str, _new: &str, _web_url: &str) {}
#[cfg(not(feature = "desktop"))]
#[inline(always)]
pub fn ticket_field_changed(
_ticket_id: &str,
_mr_title: &str,
_field: &str,
_old: &str,
_new: &str,
_ticket_url: &str,
) {
}