Skip to main content

fallow_cli/report/ci/
severity.rs

1use fallow_config::Severity;
2
3#[must_use]
4pub const fn sarif_level(severity: Severity) -> &'static str {
5    match severity {
6        Severity::Error => "error",
7        Severity::Warn => "warning",
8        Severity::Off => unreachable!(),
9    }
10}
11
12#[must_use]
13pub const fn codeclimate_severity(severity: Severity) -> &'static str {
14    match severity {
15        Severity::Error => "major",
16        Severity::Warn => "minor",
17        Severity::Off => unreachable!(),
18    }
19}
20
21#[must_use]
22pub const fn github_check_conclusion(severity: Severity) -> &'static str {
23    match severity {
24        Severity::Error => "failure",
25        Severity::Warn => "neutral",
26        Severity::Off => "success",
27    }
28}
29
30#[must_use]
31pub const fn review_label(severity: Severity) -> &'static str {
32    match severity {
33        Severity::Error => "error",
34        Severity::Warn => "warn",
35        Severity::Off => "off",
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn maps_error_across_ci_surfaces() {
45        assert_eq!(sarif_level(Severity::Error), "error");
46        assert_eq!(codeclimate_severity(Severity::Error), "major");
47        assert_eq!(github_check_conclusion(Severity::Error), "failure");
48        assert_eq!(review_label(Severity::Error), "error");
49    }
50
51    #[test]
52    fn maps_warn_across_ci_surfaces() {
53        assert_eq!(sarif_level(Severity::Warn), "warning");
54        assert_eq!(codeclimate_severity(Severity::Warn), "minor");
55        assert_eq!(github_check_conclusion(Severity::Warn), "neutral");
56        assert_eq!(review_label(Severity::Warn), "warn");
57    }
58}