Skip to main content

cuenv_ci/report/
mod.rs

1//! CI Pipeline Reporting
2//!
3//! Provides types and traits for pipeline execution reporting, including:
4//! - Static report types for completed pipelines
5//! - Live progress reporting traits
6//! - Terminal reporter (provider-specific reporters live in their own crates)
7
8use chrono::{DateTime, Utc};
9use serde::{Deserialize, Serialize};
10
11pub mod json;
12pub mod markdown;
13pub mod progress;
14pub mod terminal;
15
16// Re-export commonly used types
17pub use progress::{
18    LivePipelineProgress, LiveTaskProgress, LiveTaskStatus, NoOpReporter, ProgressReporter,
19};
20pub use terminal::TerminalReporter;
21
22/// Final pipeline report for a completed execution.
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct PipelineReport {
25    /// Report format version.
26    pub version: String,
27    /// Project name.
28    pub project: String,
29    /// Pipeline name.
30    pub pipeline: String,
31    /// Execution context (CI provider, event, etc.).
32    pub context: ContextReport,
33    /// When the pipeline started.
34    pub started_at: DateTime<Utc>,
35    /// When the pipeline completed.
36    pub completed_at: Option<DateTime<Utc>>,
37    /// Total duration in milliseconds.
38    pub duration_ms: Option<u64>,
39    /// Overall pipeline status.
40    pub status: PipelineStatus,
41    /// Individual task reports.
42    pub tasks: Vec<TaskReport>,
43}
44
45impl PipelineReport {
46    /// Get the number of cache hits.
47    #[must_use]
48    pub fn cache_hits(&self) -> usize {
49        self.tasks
50            .iter()
51            .filter(|t| t.status == TaskStatus::Cached)
52            .count()
53    }
54}
55
56/// CI execution context information.
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct ContextReport {
59    /// CI provider name (github, buildkite, etc.).
60    pub provider: String,
61    /// Event type (push, pull_request, etc.).
62    pub event: String,
63    /// Current ref name (branch or tag).
64    pub ref_name: String,
65    /// Base ref for comparison (for PRs).
66    pub base_ref: Option<String>,
67    /// Git commit SHA.
68    pub sha: String,
69    /// List of changed files.
70    pub changed_files: Vec<String>,
71}
72
73/// Individual task execution report.
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct TaskReport {
76    /// Task name.
77    pub name: String,
78    /// Task completion status.
79    pub status: TaskStatus,
80    /// Execution duration in milliseconds.
81    pub duration_ms: u64,
82    /// Process exit code (if applicable).
83    pub exit_code: Option<i32>,
84    /// Input files that matched.
85    pub inputs_matched: Vec<String>,
86    /// Cache key used.
87    pub cache_key: Option<String>,
88    /// Output files produced.
89    pub outputs: Vec<String>,
90}
91
92/// Task completion status.
93#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
94#[serde(rename_all = "lowercase")]
95pub enum TaskStatus {
96    /// Task completed successfully.
97    Success,
98    /// Task failed.
99    Failed,
100    /// Task was restored from cache.
101    Cached,
102    /// Task was skipped.
103    Skipped,
104}
105
106/// Overall pipeline status.
107#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
108#[serde(rename_all = "lowercase")]
109pub enum PipelineStatus {
110    /// Pipeline is pending execution.
111    Pending,
112    /// Pipeline completed successfully.
113    Success,
114    /// Pipeline failed.
115    Failed,
116    /// Pipeline partially completed.
117    Partial,
118}
119
120/// Opaque handle for a check run (provider specific).
121#[derive(Debug, Clone)]
122pub struct CheckHandle {
123    /// Provider-specific identifier.
124    pub id: String,
125}