Skip to main content

fallow_output/
pr_details.rs

1use serde::{Deserialize, Serialize};
2
3pub const PR_DETAILS_SCHEMA: &str = "fallow-pr-details/v1";
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6pub struct PrDetailsArtifact {
7    pub schema: String,
8    pub title: String,
9    pub sections: Vec<PrDetailsSection>,
10}
11
12#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
13pub struct PrDetailsSection {
14    pub id: String,
15    pub title: String,
16    pub rows: Vec<PrDetailsRow>,
17}
18
19#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
20pub struct PrDetailsRow {
21    pub location: String,
22    pub rule: String,
23    pub description: String,
24    pub fix: Option<String>,
25    pub fingerprint: Option<String>,
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn details_artifact_serializes_stable_schema() {
34        let artifact = PrDetailsArtifact {
35            schema: PR_DETAILS_SCHEMA.to_owned(),
36            title: "Fallow".to_owned(),
37            sections: vec![PrDetailsSection {
38                id: "findings".to_owned(),
39                title: "Findings".to_owned(),
40                rows: vec![PrDetailsRow {
41                    location: "src/app.ts:12".to_owned(),
42                    rule: "fallow/high-crap-score".to_owned(),
43                    description: "Function is hard to safely change.".to_owned(),
44                    fix: Some("Extract smaller units.".to_owned()),
45                    fingerprint: Some("abc123".to_owned()),
46                }],
47            }],
48        };
49
50        let json = serde_json::to_value(artifact).expect("serializes");
51
52        assert_eq!(json["schema"], PR_DETAILS_SCHEMA);
53        assert_eq!(json["sections"][0]["rows"][0]["location"], "src/app.ts:12");
54    }
55}