1pub mod bus;
2
3use std::str::FromStr;
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8pub const KIND_EVENT: &str = "EnvoyEvent";
9
10impl FromStr for EventType {
11 type Err = crate::error::EnvoyError;
12
13 fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
14 match s {
15 "ci_status" => Ok(Self::CiStatus),
16 "hook_result" => Ok(Self::HookResult),
17 "gate_result" => Ok(Self::GateResult),
18 "doc_sync" => Ok(Self::DocSync),
19 "task_handoff" => Ok(Self::TaskHandoff),
20 "gate_block" => Ok(Self::GateBlock),
21 "graph_refresh" => Ok(Self::GraphRefresh),
22 "task_verify" => Ok(Self::TaskVerify),
23 "audit_log" => Ok(Self::AuditLog),
24 _ => Err(crate::error::EnvoyError::InvalidMessage(format!(
25 "unknown event type: {}",
26 s
27 ))),
28 }
29 }
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
33#[serde(rename_all = "snake_case")]
34pub enum EventType {
35 CiStatus,
36 HookResult,
37 GateResult,
38 DocSync,
39 TaskHandoff,
40 GateBlock,
41 GraphRefresh,
42 TaskVerify,
43 AuditLog,
44}
45
46impl EventType {
47 pub fn as_str(&self) -> &'static str {
48 match self {
49 Self::CiStatus => "ci_status",
50 Self::HookResult => "hook_result",
51 Self::GateResult => "gate_result",
52 Self::DocSync => "doc_sync",
53 Self::TaskHandoff => "task_handoff",
54 Self::GateBlock => "gate_block",
55 Self::GraphRefresh => "graph_refresh",
56 Self::TaskVerify => "task_verify",
57 Self::AuditLog => "audit_log",
58 }
59 }
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
63#[serde(rename_all = "snake_case")]
64pub enum EventSeverity {
65 Info,
66 Warning,
67 Blocking,
68}
69
70impl EventSeverity {
71 pub fn as_str(&self) -> &'static str {
72 match self {
73 Self::Info => "info",
74 Self::Warning => "warning",
75 Self::Blocking => "blocking",
76 }
77 }
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct EnvoyEvent {
82 pub id: String,
83 pub project: String,
84 pub event_type: EventType,
85 pub severity: EventSeverity,
86 pub source: String,
87 pub message: String,
88 pub data: serde_json::Value,
89 pub timestamp: DateTime<Utc>,
90}
91
92#[derive(Debug, Deserialize)]
93pub struct HookEventRequest {
94 pub project: String,
95 pub hook_name: String,
96 pub exit_code: i32,
97 pub output: String,
98}
99
100#[derive(Debug, Deserialize)]
101pub struct GateEventRequest {
102 pub project: String,
103 pub gates_passed: u32,
104 pub gates_total: u32,
105 pub failures: Vec<String>,
106}
107
108#[derive(Debug, Deserialize)]
109pub struct CiEventRequest {
110 pub project: String,
111 pub run_id: String,
112 pub status: String,
113 pub conclusion: Option<String>,
114 pub head_branch: String,
115 pub display_title: String,
116}
117
118#[derive(Debug, Deserialize)]
119pub struct DocEventRequest {
120 pub project: String,
121 pub doc_files: Vec<String>,
122 pub last_updated_seconds: i64,
123}
124
125#[derive(Debug, Deserialize)]
126pub struct VerifyEventRequest {
127 pub project: String,
128 pub agent_id: String,
129 pub task_type: String,
130 pub claimed_files: Vec<String>,
131 pub passed: usize,
132 pub failed: usize,
133 pub failures: Vec<String>,
134}