codetether_agent/github_pr/
ci_watcher.rs1#[allow(unused_imports)]
4use super::autopilot::PrLifecycle;
5
6#[derive(Debug, Clone)]
8pub struct CiCheckResult {
9 pub all_green: bool,
10 pub failed_jobs: Vec<String>,
11 pub pending_jobs: Vec<String>,
12}
13
14impl CiCheckResult {
15 pub fn from_github_checks(data: &serde_json::Value) -> Self {
16 let statuses = data.get("statuses").and_then(|s| s.as_array());
17 let checks = data.get("check_suites").and_then(|c| c.as_array());
18 let all_results: Vec<&str> = [statuses, checks]
19 .into_iter()
20 .flatten()
21 .flat_map(|arr| arr.iter())
22 .filter_map(|v| v.get("state").and_then(|s| s.as_str()))
23 .collect();
24 let failed: Vec<String> = all_results
25 .iter()
26 .filter(|&&s| s == "failure" || s == "error")
27 .map(|s| s.to_string())
28 .collect();
29 let pending: Vec<String> = all_results
30 .iter()
31 .filter(|&&s| s == "pending" || s == "in_progress")
32 .map(|s| s.to_string())
33 .collect();
34 Self {
35 all_green: failed.is_empty() && pending.is_empty() && !all_results.is_empty(),
36 failed_jobs: failed,
37 pending_jobs: pending,
38 }
39 }
40}