set urgency

This commit is contained in:
Brandon Thomas
2026-03-30 22:24:03 -04:00
parent 0f3f686a44
commit 3bd07629de
4 changed files with 27 additions and 3 deletions
+8 -3
View File
@@ -8,6 +8,7 @@ use rootly_client::requests::create_alert::create_alert::{
use crate::error::pager_error::PagerError;
use crate::error::pager_service_error::PagerServiceError;
use crate::notification::notification_details::NotificationDetails;
use crate::notification::notification_urgency::NotificationUrgency;
/// The actual client that sends pages.
#[derive(Clone)]
@@ -100,8 +101,8 @@ impl PagerClient {
let PagerClientConfig::Rootly {
api_key,
urgency_id_high,
urgency_id_medium: _,
urgency_id_low: _,
urgency_id_medium,
urgency_id_low,
notification_target_type,
notification_target_id,
} = &self.client_config else {
@@ -199,7 +200,11 @@ impl PagerClient {
environment_ids: None,
external_id: None,
external_url: None,
alert_urgency_id: urgency_id_high.clone(),
alert_urgency_id: match notification.urgency.unwrap_or(NotificationUrgency::Medium) {
NotificationUrgency::High => urgency_id_high.clone(),
NotificationUrgency::Medium => urgency_id_medium.clone(),
NotificationUrgency::Low => urgency_id_low.clone(),
},
notification_target_type: notification_target_type.clone(),
notification_target_id: notification_target_id.clone(),
labels,
@@ -58,6 +58,7 @@ mod tests {
http_path: http_path.map(|s| s.to_string()),
http_status_code: None,
is_from_error,
urgency: None,
}
}
@@ -212,6 +213,7 @@ mod tests {
http_path: http_path.map(|s| s.to_string()),
http_status_code,
is_from_error,
urgency: None,
}
}
@@ -2,6 +2,7 @@ use chrono::{DateTime, Utc};
use std::fmt::{Debug, Display};
use crate::notification::generate_deduplication_key::generate_deduplication_key;
use crate::notification::notification_urgency::NotificationUrgency;
/// Details for a pager notification.
#[derive(Clone, Debug)]
@@ -26,6 +27,9 @@ pub struct NotificationDetails {
/// Whether this notification originated from an error.
pub is_from_error: bool,
/// Urgency level for the notification.
pub urgency: Option<NotificationUrgency>,
}
impl NotificationDetails {
@@ -43,6 +47,7 @@ impl NotificationDetails {
http_path: None,
http_status_code: None,
is_from_error: false,
urgency: None,
}
}
@@ -56,6 +61,7 @@ impl NotificationDetails {
http_path: None,
http_status_code: None,
is_from_error: false,
urgency: None,
}
}
@@ -116,6 +122,7 @@ impl NotificationDetails {
http_path: None,
http_status_code: None,
is_from_error: true,
urgency: None,
}
}
@@ -2,6 +2,7 @@ use chrono::{DateTime, Utc};
use std::fmt::{Debug, Display};
use crate::notification::notification_details::NotificationDetails;
use crate::notification::notification_urgency::NotificationUrgency;
pub struct NotificationDetailsBuilder {
summary: String,
@@ -11,6 +12,7 @@ pub struct NotificationDetailsBuilder {
http_path: Option<String>,
http_status_code: Option<u16>,
is_from_error: bool,
urgency: Option<NotificationUrgency>,
}
impl NotificationDetailsBuilder {
@@ -24,6 +26,7 @@ impl NotificationDetailsBuilder {
http_path: None,
http_status_code: None,
is_from_error: false,
urgency: None,
}
}
@@ -42,6 +45,7 @@ impl NotificationDetailsBuilder {
http_path: None,
http_status_code: None,
is_from_error: true,
urgency: None,
}
}
@@ -65,6 +69,11 @@ impl NotificationDetailsBuilder {
self
}
pub fn set_urgency(mut self, urgency: Option<NotificationUrgency>) -> Self {
self.urgency = urgency;
self
}
pub fn build(self) -> NotificationDetails {
NotificationDetails {
summary: self.summary,
@@ -74,6 +83,7 @@ impl NotificationDetailsBuilder {
http_path: self.http_path,
http_status_code: self.http_status_code,
is_from_error: self.is_from_error,
urgency: self.urgency,
}
}
}