code_ranker_graph/
snapshot.rs1use crate::level_graph::LevelGraph;
11use chrono::{DateTime, Utc};
12use code_ranker_plugin_api::plugin::Preset;
13use serde::{Deserialize, Serialize};
14use std::collections::BTreeMap;
15
16pub const SCHEMA_VERSION: &str = "2";
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct StageTime {
24 pub stage: String,
25 pub ms: u64,
26 #[serde(default, skip_serializing_if = "String::is_empty")]
27 pub detail: String,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct Snapshot {
32 pub schema_version: String,
33 pub generated_at: DateTime<Utc>,
34 pub command: String,
35 pub workspace: String,
37 pub target: String,
39 pub plugin: String,
40 #[serde(default, skip_serializing_if = "Option::is_none")]
42 pub config_file: Option<String>,
43 pub versions: BTreeMap<String, String>,
44 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
46 pub roots: BTreeMap<String, String>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub git: Option<GitInfo>,
49 #[serde(default, skip_serializing_if = "Vec::is_empty")]
50 pub timings: Vec<StageTime>,
51 pub graphs: BTreeMap<String, LevelGraph>,
53 #[serde(default, skip_serializing_if = "Vec::is_empty")]
55 pub presets: Vec<Preset>,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct GitInfo {
60 pub branch: String,
61 pub commit: String,
62 pub dirty_files: u32,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub origin: Option<String>,
66}
67
68impl Snapshot {
69 #[allow(clippy::too_many_arguments)]
70 pub fn new(
71 command: String,
72 workspace: String,
73 target: String,
74 plugin: String,
75 config_file: Option<String>,
76 versions: BTreeMap<String, String>,
77 roots: BTreeMap<String, String>,
78 git: Option<GitInfo>,
79 timings: Vec<StageTime>,
80 graphs: BTreeMap<String, LevelGraph>,
81 presets: Vec<Preset>,
82 ) -> Self {
83 Self {
84 schema_version: SCHEMA_VERSION.to_string(),
85 generated_at: Utc::now(),
86 command,
87 workspace,
88 target,
89 plugin,
90 config_file,
91 versions,
92 roots,
93 git,
94 timings,
95 graphs,
96 presets,
97 }
98 }
99}