claude_priority/
github.rs

1use crate::models::{ValidationResult, ValidationSummary};
2use std::env;
3
4pub fn is_github_actions() -> bool {
5    env::var("GITHUB_ACTIONS").unwrap_or_default() == "true"
6}
7
8pub fn print_github_error(message: &str) {
9    if is_github_actions() {
10        println!("::error::{}", message);
11    }
12}
13
14pub fn print_github_warning(message: &str) {
15    if is_github_actions() {
16        println!("::warning::{}", message);
17    }
18}
19
20pub fn print_github_notice(message: &str) {
21    if is_github_actions() {
22        println!("::notice::{}", message);
23    }
24}
25
26pub fn output_github_results(result: &ValidationResult) {
27    if !is_github_actions() {
28        return;
29    }
30
31    for error in &result.errors {
32        print_github_error(error);
33    }
34
35    for warning in &result.warnings {
36        print_github_warning(warning);
37    }
38
39    if result.passed {
40        print_github_notice(&format!("{}: PASSED", result.check_type));
41    }
42}
43
44pub fn set_github_output(summary: &ValidationSummary) {
45    if !is_github_actions() {
46        return;
47    }
48
49    let github_output = env::var("GITHUB_OUTPUT").unwrap_or_default();
50    if github_output.is_empty() {
51        return;
52    }
53
54    use std::fs::OpenOptions;
55    use std::io::Write;
56
57    let status = if summary.is_success() { "pass" } else { "fail" };
58
59    let mut file = match OpenOptions::new()
60        .create(true)
61        .append(true)
62        .open(&github_output)
63    {
64        Ok(f) => f,
65        Err(_) => return,
66    };
67
68    let _ = writeln!(file, "validation-status={}", status);
69    let _ = writeln!(file, "total-checks={}", summary.total_checks);
70    let _ = writeln!(file, "passed-checks={}", summary.passed_checks);
71    let _ = writeln!(file, "failed-checks={}", summary.failed_checks);
72
73    let errors = summary.all_errors();
74    if !errors.is_empty() {
75        let _ = writeln!(file, "error-messages<<EOF");
76        for error in errors {
77            let _ = writeln!(file, "{}", error);
78        }
79        let _ = writeln!(file, "EOF");
80    }
81}
82
83#[cfg(test)]
84mod tests {
85    use super::*;
86
87    #[test]
88    fn test_is_github_actions() {
89        // Should not panic
90        let _ = is_github_actions();
91    }
92}