Skip to main content

artifactize_core/monitor/model/
status.rs

1//! Every status the monitor shows, typed until it is drawn: the statuses of Runs, requests
2//! and Artifact validation, in their urgency order.
3
4use crate::types::{ArtifactValidationStatus, RequestStatus, RunStatus};
5
6/// A shown status. The variants are declared most urgent first, so the derived order is
7/// the urgency order the header, Scope, Runs and headline counts use.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub enum Status {
10    Error,
11    Red,
12    Blocked,
13    Running,
14    WaitingHuman,
15    Queued,
16    BudgetExhausted,
17    WaitDependency,
18    Wait,
19    Stale,
20    Unreviewed,
21    Incomplete,
22    Green,
23    Basis,
24}
25
26impl Status {
27    /// The status as saved and printed, such as `WAITING_HUMAN`.
28    pub fn as_str(self) -> &'static str {
29        match self {
30            Self::Error => "ERROR",
31            Self::Red => "RED",
32            Self::Blocked => "BLOCKED",
33            Self::Running => "RUNNING",
34            Self::WaitingHuman => "WAITING_HUMAN",
35            Self::Queued => "QUEUED",
36            Self::BudgetExhausted => "BUDGET_EXHAUSTED",
37            Self::WaitDependency => "WAIT_DEPENDENCY",
38            Self::Wait => "WAIT",
39            Self::Stale => "STALE",
40            Self::Unreviewed => "UNREVIEWED",
41            Self::Incomplete => "INCOMPLETE",
42            Self::Green => "GREEN",
43            Self::Basis => "BASIS",
44        }
45    }
46
47    /// The one-character mark the tree, counts and headline show for the status.
48    pub fn glyph(self) -> &'static str {
49        match self {
50            Self::Green => "✓",
51            Self::Red => "✗",
52            Self::Error => "!",
53            Self::Running => "◐",
54            Self::WaitingHuman => "?",
55            Self::Queued => "·",
56            Self::Blocked => "⊘",
57            Self::WaitDependency | Self::Wait => "…",
58            Self::BudgetExhausted => "$",
59            Self::Basis => "◇",
60            Self::Stale | Self::Unreviewed | Self::Incomplete => "○",
61        }
62    }
63
64    /// What a request in this status means, for its detail.
65    pub fn meaning(self) -> &'static str {
66        match self {
67            Self::Green => "criteria met",
68            Self::Red => "criteria not met",
69            Self::Error => "operational failure, not a verdict",
70            Self::Running => "executing",
71            Self::WaitingHuman => "waiting for a Human submission",
72            Self::Blocked => "blocked by a RED dependency",
73            Self::WaitDependency => "waiting for current GREEN dependency evidence",
74            Self::BudgetExhausted => "maxExecutions reached before it started",
75            _ => "not executed",
76        }
77    }
78}
79
80impl std::fmt::Display for Status {
81    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82        formatter.write_str(self.as_str())
83    }
84}
85
86impl From<RunStatus> for Status {
87    fn from(status: RunStatus) -> Self {
88        match status {
89            RunStatus::Running => Self::Running,
90            RunStatus::Green => Self::Green,
91            RunStatus::Red => Self::Red,
92            RunStatus::Error => Self::Error,
93            RunStatus::Incomplete => Self::Incomplete,
94        }
95    }
96}
97
98impl From<RequestStatus> for Status {
99    fn from(status: RequestStatus) -> Self {
100        match status {
101            RequestStatus::Queued => Self::Queued,
102            RequestStatus::Running => Self::Running,
103            RequestStatus::WaitingHuman => Self::WaitingHuman,
104            RequestStatus::Green => Self::Green,
105            RequestStatus::Red => Self::Red,
106            RequestStatus::Error => Self::Error,
107            RequestStatus::BudgetExhausted => Self::BudgetExhausted,
108            RequestStatus::Stale => Self::Stale,
109            RequestStatus::Unreviewed => Self::Unreviewed,
110            RequestStatus::WaitDependency => Self::WaitDependency,
111            RequestStatus::Blocked => Self::Blocked,
112        }
113    }
114}
115
116impl From<ArtifactValidationStatus> for Status {
117    fn from(status: ArtifactValidationStatus) -> Self {
118        match status {
119            ArtifactValidationStatus::Basis => Self::Basis,
120            ArtifactValidationStatus::Green => Self::Green,
121            ArtifactValidationStatus::Incomplete => Self::Incomplete,
122            ArtifactValidationStatus::Error => Self::Error,
123            ArtifactValidationStatus::Red => Self::Red,
124            ArtifactValidationStatus::Blocked => Self::Blocked,
125            ArtifactValidationStatus::Wait => Self::Wait,
126            ArtifactValidationStatus::Stale => Self::Stale,
127            ArtifactValidationStatus::Unreviewed => Self::Unreviewed,
128        }
129    }
130}