buildfix_types/wire/
plan_v1.rs1use serde::{Deserialize, Serialize};
2
3use crate::plan::{
4 BuildfixPlan, PlanInput, PlanOp, PlanPolicy, PlanPreconditions, PlanSummary, RepoInfo,
5};
6use crate::receipt::ToolInfo;
7use crate::wire::{ToolInfoV1, WireError};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct PlanV1 {
12 pub schema: String,
13 pub tool: ToolInfoV1,
14 pub repo: RepoInfo,
15
16 #[serde(default)]
17 pub inputs: Vec<PlanInput>,
18
19 pub policy: PlanPolicy,
20
21 #[serde(default)]
22 pub preconditions: PlanPreconditions,
23
24 #[serde(default)]
25 pub ops: Vec<PlanOp>,
26
27 pub summary: PlanSummary,
28}
29
30impl TryFrom<&BuildfixPlan> for PlanV1 {
31 type Error = WireError;
32
33 fn try_from(plan: &BuildfixPlan) -> Result<Self, Self::Error> {
34 let version = plan
35 .tool
36 .version
37 .clone()
38 .ok_or(WireError::MissingToolVersion { context: "plan" })?;
39
40 Ok(Self {
41 schema: plan.schema.clone(),
42 tool: ToolInfoV1 {
43 name: plan.tool.name.clone(),
44 version,
45 commit: plan.tool.commit.clone(),
46 },
47 repo: plan.repo.clone(),
48 inputs: plan.inputs.clone(),
49 policy: plan.policy.clone(),
50 preconditions: plan.preconditions.clone(),
51 ops: plan.ops.clone(),
52 summary: plan.summary.clone(),
53 })
54 }
55}
56
57impl From<PlanV1> for BuildfixPlan {
58 fn from(plan: PlanV1) -> Self {
59 BuildfixPlan {
60 schema: plan.schema,
61 tool: ToolInfo {
62 name: plan.tool.name,
63 version: Some(plan.tool.version),
64 repo: None,
65 commit: plan.tool.commit,
66 },
67 repo: plan.repo,
68 inputs: plan.inputs,
69 policy: plan.policy,
70 preconditions: plan.preconditions,
71 ops: plan.ops,
72 summary: plan.summary,
73 }
74 }
75}