progit_plugin_sdk/
event.rs1use serde::{Deserialize, Serialize};
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(tag = "type", content = "data")]
27pub enum PluginEvent {
28 Startup,
30 IssueCreated { issue_id: String },
32 IssueUpdated { issue_id: String },
34 IssueStatusChanged {
36 issue_id: String,
37 old_status: String,
38 new_status: String,
39 },
40 CommitCreated { commit_hash: String },
42 BranchCreated { branch_id: String },
44 BranchUpdated { branch_id: String },
46 AgentAction { action: String, branch_id: String },
48 PipelineStatusQuery {
50 mr_id: String,
51 project_id: String,
52 source_branch: String,
53 target_branch: String,
54 forge_type: String,
56 api_url: String,
57 },
58 Custom {
60 name: String,
61 payload: serde_json::Value,
62 },
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct PipelineStatus {
68 pub status: PipelineState,
69 pub pipeline_id: Option<String>,
70 pub jobs: Vec<PipelineJob>,
71 pub updated_at: Option<String>,
72 pub web_url: Option<String>,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
77#[serde(rename_all = "lowercase")]
78pub enum PipelineState {
79 Passed,
80 Failed,
81 Running,
82 Pending,
83 Canceled,
84 Skipped,
85 Unknown,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct PipelineJob {
91 pub name: String,
92 pub status: PipelineState,
93 pub duration: Option<String>,
95}
96
97#[cfg(test)]
98mod tests {
99 use super::*;
100
101 #[test]
102 fn event_round_trips_through_json() {
103 let evt = PluginEvent::IssueStatusChanged {
104 issue_id: "abc".into(),
105 old_status: "todo".into(),
106 new_status: "done".into(),
107 };
108 let s = serde_json::to_string(&evt).unwrap();
109 assert!(s.contains(r#""type":"IssueStatusChanged""#));
110 let back: PluginEvent = serde_json::from_str(&s).unwrap();
111 match back {
112 PluginEvent::IssueStatusChanged { new_status, .. } => assert_eq!(new_status, "done"),
113 _ => panic!("variant lost in round-trip"),
114 }
115 }
116
117 #[test]
118 fn pipeline_state_lowercases() {
119 let s = serde_json::to_string(&PipelineState::Passed).unwrap();
120 assert_eq!(s, "\"passed\"");
121 }
122}