rust_diff_analyzer/output/
github.rs1use masterror::AppError;
5
6use super::formatter::Formatter;
7use crate::{config::Config, types::AnalysisResult};
8
9pub struct GithubFormatter;
11
12impl Formatter for GithubFormatter {
13 fn format(&self, result: &AnalysisResult, _config: &Config) -> Result<String, AppError> {
14 use std::fmt::Write;
15
16 let summary = &result.summary;
17 let mut output = String::new();
18
19 let _ = writeln!(output, "prod_functions_changed={}", summary.prod_functions);
20 let _ = writeln!(output, "prod_structs_changed={}", summary.prod_structs);
21 let _ = writeln!(output, "prod_other_changed={}", summary.prod_other);
22 let _ = writeln!(output, "test_units_changed={}", summary.test_units);
23 let _ = writeln!(output, "prod_lines_added={}", summary.prod_lines_added);
24 let _ = writeln!(output, "prod_lines_removed={}", summary.prod_lines_removed);
25 let _ = writeln!(output, "test_lines_added={}", summary.test_lines_added);
26 let _ = writeln!(output, "test_lines_removed={}", summary.test_lines_removed);
27 let _ = writeln!(output, "weighted_score={}", summary.weighted_score);
28 let _ = writeln!(output, "exceeds_limit={}", summary.exceeds_limit);
29
30 Ok(output)
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use crate::types::{AnalysisScope, Summary};
38
39 #[test]
40 fn test_github_format() {
41 let result = AnalysisResult::new(
42 vec![],
43 Summary {
44 prod_functions: 5,
45 prod_structs: 2,
46 prod_other: 1,
47 test_units: 10,
48 prod_lines_added: 50,
49 prod_lines_removed: 20,
50 test_lines_added: 100,
51 test_lines_removed: 30,
52 weighted_score: 23,
53 exceeds_limit: false,
54 },
55 AnalysisScope::new(),
56 );
57
58 let config = Config::default();
59 let output = GithubFormatter
60 .format(&result, &config)
61 .expect("format should succeed");
62
63 let expected = concat!(
64 "prod_functions_changed=5\n",
65 "prod_structs_changed=2\n",
66 "prod_other_changed=1\n",
67 "test_units_changed=10\n",
68 "prod_lines_added=50\n",
69 "prod_lines_removed=20\n",
70 "test_lines_added=100\n",
71 "test_lines_removed=30\n",
72 "weighted_score=23\n",
73 "exceeds_limit=false\n",
74 );
75 assert_eq!(output, expected);
76 }
77}