fallow_output/
pr_details.rs1use serde::{Deserialize, Serialize};
2
3pub const PR_DETAILS_SCHEMA: &str = "fallow-pr-details/v1";
5
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub struct PrDetailsArtifact {
10 pub schema: String,
12 pub title: String,
14 pub sections: Vec<PrDetailsSection>,
16}
17
18#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
20pub struct PrDetailsSection {
21 pub id: String,
23 pub title: String,
25 pub rows: Vec<PrDetailsRow>,
27}
28
29#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
31pub struct PrDetailsRow {
32 pub location: String,
34 pub rule: String,
36 pub description: String,
38 pub fix: Option<String>,
40 pub fingerprint: Option<String>,
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn details_artifact_serializes_stable_schema() {
50 let artifact = PrDetailsArtifact {
51 schema: PR_DETAILS_SCHEMA.to_owned(),
52 title: "Fallow".to_owned(),
53 sections: vec![PrDetailsSection {
54 id: "findings".to_owned(),
55 title: "Findings".to_owned(),
56 rows: vec![PrDetailsRow {
57 location: "src/app.ts:12".to_owned(),
58 rule: "fallow/high-crap-score".to_owned(),
59 description: "Function is hard to safely change.".to_owned(),
60 fix: Some("Extract smaller units.".to_owned()),
61 fingerprint: Some("abc123".to_owned()),
62 }],
63 }],
64 };
65
66 let json = serde_json::to_value(artifact).expect("serializes");
67
68 assert_eq!(json["schema"], PR_DETAILS_SCHEMA);
69 assert_eq!(json["sections"][0]["rows"][0]["location"], "src/app.ts:12");
70 }
71}