datadog_api_client/datadogV2/model/
model_ci_app_pipeline_event_step.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Details of a CI step.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CIAppPipelineEventStep {
14    /// Time when the step run finished. The time format must be RFC3339.
15    #[serde(rename = "end")]
16    pub end: chrono::DateTime<chrono::Utc>,
17    /// Contains information of the CI error.
18    #[serde(rename = "error", default, with = "::serde_with::rust::double_option")]
19    pub error: Option<Option<crate::datadogV2::model::CIAppCIError>>,
20    /// If pipelines are triggered due to actions to a Git repository, then all payloads must contain this.
21    /// Note that either `tag` or `branch` has to be provided, but not both.
22    #[serde(rename = "git", default, with = "::serde_with::rust::double_option")]
23    pub git: Option<Option<crate::datadogV2::model::CIAppGitInfo>>,
24    /// UUID for the step. It has to be unique within each pipeline execution.
25    #[serde(rename = "id")]
26    pub id: String,
27    /// The parent job UUID (if applicable).
28    #[serde(rename = "job_id", default, with = "::serde_with::rust::double_option")]
29    pub job_id: Option<Option<String>>,
30    /// The parent job name (if applicable).
31    #[serde(
32        rename = "job_name",
33        default,
34        with = "::serde_with::rust::double_option"
35    )]
36    pub job_name: Option<Option<String>>,
37    /// Used to distinguish between pipelines, stages, jobs and steps.
38    #[serde(rename = "level")]
39    pub level: crate::datadogV2::model::CIAppPipelineEventStepLevel,
40    /// A list of user-defined metrics. The metrics must follow the `key:value` pattern and the value must be numeric.
41    #[serde(
42        rename = "metrics",
43        default,
44        with = "::serde_with::rust::double_option"
45    )]
46    pub metrics: Option<Option<Vec<String>>>,
47    /// The name for the step.
48    #[serde(rename = "name")]
49    pub name: String,
50    /// Contains information of the host running the pipeline, stage, job, or step.
51    #[serde(rename = "node", default, with = "::serde_with::rust::double_option")]
52    pub node: Option<Option<crate::datadogV2::model::CIAppHostInfo>>,
53    /// A map of key-value parameters or environment variables that were defined for the pipeline.
54    #[serde(
55        rename = "parameters",
56        default,
57        with = "::serde_with::rust::double_option"
58    )]
59    pub parameters: Option<Option<std::collections::BTreeMap<String, String>>>,
60    /// The parent pipeline name.
61    #[serde(rename = "pipeline_name")]
62    pub pipeline_name: String,
63    /// The parent pipeline UUID.
64    #[serde(rename = "pipeline_unique_id")]
65    pub pipeline_unique_id: String,
66    /// The parent stage UUID (if applicable).
67    #[serde(
68        rename = "stage_id",
69        default,
70        with = "::serde_with::rust::double_option"
71    )]
72    pub stage_id: Option<Option<String>>,
73    /// The parent stage name (if applicable).
74    #[serde(
75        rename = "stage_name",
76        default,
77        with = "::serde_with::rust::double_option"
78    )]
79    pub stage_name: Option<Option<String>>,
80    /// Time when the step run started. The time format must be RFC3339.
81    #[serde(rename = "start")]
82    pub start: chrono::DateTime<chrono::Utc>,
83    /// The final status of the step.
84    #[serde(rename = "status")]
85    pub status: crate::datadogV2::model::CIAppPipelineEventStepStatus,
86    /// A list of user-defined tags. The tags must follow the `key:value` pattern.
87    #[serde(rename = "tags", default, with = "::serde_with::rust::double_option")]
88    pub tags: Option<Option<Vec<String>>>,
89    /// The URL to look at the step in the CI provider UI.
90    #[serde(rename = "url", default, with = "::serde_with::rust::double_option")]
91    pub url: Option<Option<String>>,
92    #[serde(flatten)]
93    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
94    #[serde(skip)]
95    #[serde(default)]
96    pub(crate) _unparsed: bool,
97}
98
99impl CIAppPipelineEventStep {
100    pub fn new(
101        end: chrono::DateTime<chrono::Utc>,
102        id: String,
103        level: crate::datadogV2::model::CIAppPipelineEventStepLevel,
104        name: String,
105        pipeline_name: String,
106        pipeline_unique_id: String,
107        start: chrono::DateTime<chrono::Utc>,
108        status: crate::datadogV2::model::CIAppPipelineEventStepStatus,
109    ) -> CIAppPipelineEventStep {
110        CIAppPipelineEventStep {
111            end,
112            error: None,
113            git: None,
114            id,
115            job_id: None,
116            job_name: None,
117            level,
118            metrics: None,
119            name,
120            node: None,
121            parameters: None,
122            pipeline_name,
123            pipeline_unique_id,
124            stage_id: None,
125            stage_name: None,
126            start,
127            status,
128            tags: None,
129            url: None,
130            additional_properties: std::collections::BTreeMap::new(),
131            _unparsed: false,
132        }
133    }
134
135    pub fn error(mut self, value: Option<crate::datadogV2::model::CIAppCIError>) -> Self {
136        self.error = Some(value);
137        self
138    }
139
140    pub fn git(mut self, value: Option<crate::datadogV2::model::CIAppGitInfo>) -> Self {
141        self.git = Some(value);
142        self
143    }
144
145    pub fn job_id(mut self, value: Option<String>) -> Self {
146        self.job_id = Some(value);
147        self
148    }
149
150    pub fn job_name(mut self, value: Option<String>) -> Self {
151        self.job_name = Some(value);
152        self
153    }
154
155    pub fn metrics(mut self, value: Option<Vec<String>>) -> Self {
156        self.metrics = Some(value);
157        self
158    }
159
160    pub fn node(mut self, value: Option<crate::datadogV2::model::CIAppHostInfo>) -> Self {
161        self.node = Some(value);
162        self
163    }
164
165    pub fn parameters(mut self, value: Option<std::collections::BTreeMap<String, String>>) -> Self {
166        self.parameters = Some(value);
167        self
168    }
169
170    pub fn stage_id(mut self, value: Option<String>) -> Self {
171        self.stage_id = Some(value);
172        self
173    }
174
175    pub fn stage_name(mut self, value: Option<String>) -> Self {
176        self.stage_name = Some(value);
177        self
178    }
179
180    pub fn tags(mut self, value: Option<Vec<String>>) -> Self {
181        self.tags = Some(value);
182        self
183    }
184
185    pub fn url(mut self, value: Option<String>) -> Self {
186        self.url = Some(value);
187        self
188    }
189
190    pub fn additional_properties(
191        mut self,
192        value: std::collections::BTreeMap<String, serde_json::Value>,
193    ) -> Self {
194        self.additional_properties = value;
195        self
196    }
197}
198
199impl<'de> Deserialize<'de> for CIAppPipelineEventStep {
200    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
201    where
202        D: Deserializer<'de>,
203    {
204        struct CIAppPipelineEventStepVisitor;
205        impl<'a> Visitor<'a> for CIAppPipelineEventStepVisitor {
206            type Value = CIAppPipelineEventStep;
207
208            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
209                f.write_str("a mapping")
210            }
211
212            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
213            where
214                M: MapAccess<'a>,
215            {
216                let mut end: Option<chrono::DateTime<chrono::Utc>> = None;
217                let mut error: Option<Option<crate::datadogV2::model::CIAppCIError>> = None;
218                let mut git: Option<Option<crate::datadogV2::model::CIAppGitInfo>> = None;
219                let mut id: Option<String> = None;
220                let mut job_id: Option<Option<String>> = None;
221                let mut job_name: Option<Option<String>> = None;
222                let mut level: Option<crate::datadogV2::model::CIAppPipelineEventStepLevel> = None;
223                let mut metrics: Option<Option<Vec<String>>> = None;
224                let mut name: Option<String> = None;
225                let mut node: Option<Option<crate::datadogV2::model::CIAppHostInfo>> = None;
226                let mut parameters: Option<Option<std::collections::BTreeMap<String, String>>> =
227                    None;
228                let mut pipeline_name: Option<String> = None;
229                let mut pipeline_unique_id: Option<String> = None;
230                let mut stage_id: Option<Option<String>> = None;
231                let mut stage_name: Option<Option<String>> = None;
232                let mut start: Option<chrono::DateTime<chrono::Utc>> = None;
233                let mut status: Option<crate::datadogV2::model::CIAppPipelineEventStepStatus> =
234                    None;
235                let mut tags: Option<Option<Vec<String>>> = None;
236                let mut url: Option<Option<String>> = None;
237                let mut additional_properties: std::collections::BTreeMap<
238                    String,
239                    serde_json::Value,
240                > = std::collections::BTreeMap::new();
241                let mut _unparsed = false;
242
243                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
244                    match k.as_str() {
245                        "end" => {
246                            end = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
247                        }
248                        "error" => {
249                            error = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
250                        }
251                        "git" => {
252                            git = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
253                        }
254                        "id" => {
255                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
256                        }
257                        "job_id" => {
258                            job_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
259                        }
260                        "job_name" => {
261                            job_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
262                        }
263                        "level" => {
264                            level = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
265                            if let Some(ref _level) = level {
266                                match _level {
267                                    crate::datadogV2::model::CIAppPipelineEventStepLevel::UnparsedObject(_level) => {
268                                        _unparsed = true;
269                                    },
270                                    _ => {}
271                                }
272                            }
273                        }
274                        "metrics" => {
275                            metrics = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
276                        }
277                        "name" => {
278                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
279                        }
280                        "node" => {
281                            node = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
282                        }
283                        "parameters" => {
284                            parameters = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
285                        }
286                        "pipeline_name" => {
287                            pipeline_name =
288                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
289                        }
290                        "pipeline_unique_id" => {
291                            pipeline_unique_id =
292                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
293                        }
294                        "stage_id" => {
295                            stage_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
296                        }
297                        "stage_name" => {
298                            stage_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
299                        }
300                        "start" => {
301                            start = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
302                        }
303                        "status" => {
304                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
305                            if let Some(ref _status) = status {
306                                match _status {
307                                    crate::datadogV2::model::CIAppPipelineEventStepStatus::UnparsedObject(_status) => {
308                                        _unparsed = true;
309                                    },
310                                    _ => {}
311                                }
312                            }
313                        }
314                        "tags" => {
315                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
316                        }
317                        "url" => {
318                            url = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
319                        }
320                        &_ => {
321                            if let Ok(value) = serde_json::from_value(v.clone()) {
322                                additional_properties.insert(k, value);
323                            }
324                        }
325                    }
326                }
327                let end = end.ok_or_else(|| M::Error::missing_field("end"))?;
328                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
329                let level = level.ok_or_else(|| M::Error::missing_field("level"))?;
330                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
331                let pipeline_name =
332                    pipeline_name.ok_or_else(|| M::Error::missing_field("pipeline_name"))?;
333                let pipeline_unique_id = pipeline_unique_id
334                    .ok_or_else(|| M::Error::missing_field("pipeline_unique_id"))?;
335                let start = start.ok_or_else(|| M::Error::missing_field("start"))?;
336                let status = status.ok_or_else(|| M::Error::missing_field("status"))?;
337
338                let content = CIAppPipelineEventStep {
339                    end,
340                    error,
341                    git,
342                    id,
343                    job_id,
344                    job_name,
345                    level,
346                    metrics,
347                    name,
348                    node,
349                    parameters,
350                    pipeline_name,
351                    pipeline_unique_id,
352                    stage_id,
353                    stage_name,
354                    start,
355                    status,
356                    tags,
357                    url,
358                    additional_properties,
359                    _unparsed,
360                };
361
362                Ok(content)
363            }
364        }
365
366        deserializer.deserialize_any(CIAppPipelineEventStepVisitor)
367    }
368}