buildfix_types/wire/
apply_v1.rs1use serde::{Deserialize, Serialize};
2
3use crate::apply::{
4 ApplyPreconditions, ApplyRepoInfo, ApplyResult, ApplySummary, AutoCommitInfo, BuildfixApply,
5 PlanRef,
6};
7use crate::receipt::ToolInfo;
8use crate::wire::{ToolInfoV1, WireError};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct ApplyV1 {
13 pub schema: String,
14 pub tool: ToolInfoV1,
15 pub repo: ApplyRepoInfo,
16 pub plan_ref: PlanRef,
17 pub preconditions: ApplyPreconditions,
18
19 #[serde(default)]
20 pub results: Vec<ApplyResult>,
21
22 pub summary: ApplySummary,
23
24 #[serde(default, skip_serializing_if = "Option::is_none")]
25 pub auto_commit: Option<AutoCommitInfo>,
26
27 #[serde(default, skip_serializing_if = "Vec::is_empty")]
28 pub errors: Vec<String>,
29}
30
31impl TryFrom<&BuildfixApply> for ApplyV1 {
32 type Error = WireError;
33
34 fn try_from(apply: &BuildfixApply) -> Result<Self, Self::Error> {
35 let version = apply
36 .tool
37 .version
38 .clone()
39 .ok_or(WireError::MissingToolVersion { context: "apply" })?;
40
41 Ok(Self {
42 schema: apply.schema.clone(),
43 tool: ToolInfoV1 {
44 name: apply.tool.name.clone(),
45 version,
46 commit: apply.tool.commit.clone(),
47 },
48 repo: apply.repo.clone(),
49 plan_ref: apply.plan_ref.clone(),
50 preconditions: apply.preconditions.clone(),
51 results: apply.results.clone(),
52 summary: apply.summary.clone(),
53 auto_commit: apply.auto_commit.clone(),
54 errors: apply.errors.clone(),
55 })
56 }
57}
58
59impl From<ApplyV1> for BuildfixApply {
60 fn from(apply: ApplyV1) -> Self {
61 BuildfixApply {
62 schema: apply.schema,
63 tool: ToolInfo {
64 name: apply.tool.name,
65 version: Some(apply.tool.version),
66 repo: None,
67 commit: apply.tool.commit,
68 },
69 repo: apply.repo,
70 plan_ref: apply.plan_ref,
71 preconditions: apply.preconditions,
72 results: apply.results,
73 summary: apply.summary,
74 auto_commit: apply.auto_commit,
75 errors: apply.errors,
76 }
77 }
78}