use super::{Digest, Insight, InsightKind, Insights, LongWait, Severity, WaitSpread};
use crate::api::Tone;
impl InsightKind {
pub fn label(&self) -> &'static str {
match self {
InsightKind::Slower { .. } => "Slower",
InsightKind::Flaky { .. } => "Flaky",
InsightKind::NearCap { .. } => "Near its cap",
InsightKind::ColdCache { .. } => "Cold cache",
InsightKind::Throttled { .. } => "Memory pressure",
InsightKind::Waits { .. } => "Waits",
}
}
pub fn word(&self) -> &'static str {
match self {
InsightKind::Slower { .. } => "slower",
InsightKind::Flaky { .. } => "flaky",
InsightKind::NearCap { .. } => "near-cap",
InsightKind::ColdCache { .. } => "cold-cache",
InsightKind::Throttled { .. } => "throttled",
InsightKind::Waits { .. } => "waits",
}
}
}
impl Severity {
pub fn label(self) -> &'static str {
match self {
Severity::Warning => "warning",
Severity::Notice => "notice",
}
}
}
impl Insight {
pub fn tone(&self) -> Tone {
match self.severity {
Severity::Warning => Tone::Warn,
Severity::Notice => Tone::Neutral,
}
}
}
impl Insights {
pub fn warning_count(&self) -> usize {
self.insights
.iter()
.filter(|insight| insight.severity == Severity::Warning)
.count()
}
pub fn days(&self) -> u64 {
self.until.saturating_sub(self.since) / 86_400
}
pub fn window_line(&self) -> String {
format!("from the last {} days", self.days())
}
pub fn empty_line(&self) -> String {
format!("nothing stands out {}", self.window_line())
}
}
impl WaitSpread {
pub fn reading(&self, value: Option<u64>) -> Option<u64> {
value.filter(|_| self.jobs > 0)
}
}
impl Digest {
pub fn summary_line(&self) -> String {
let jobs = if self.finished == 1 { "job" } else { "jobs" };
let line = format!("{} {jobs} finished, {} failed", self.finished, self.failed);
match self.new.len() {
0 => line,
1 => format!("{line}, 1 new insight"),
new => format!("{line}, {new} new insights"),
}
}
}
impl LongWait {
pub fn line(&self) -> String {
format!(
"{} {} waited {}",
self.repository,
crate::api::job_title(self.workflow.as_deref(), &self.name, Some(self.job)),
crate::api::duration(self.waited)
)
}
}
#[cfg(test)]
mod tests;