Skip to main content

aws_lambda_events/event/code_commit/
mod.rs

1#[cfg(feature = "builders")]
2use bon::Builder;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5#[cfg(feature = "catch-all-fields")]
6use serde_json::Value;
7
8use crate::custom_serde::deserialize_nullish;
9
10/// `CodeCommitEvent` represents a CodeCommit event
11#[non_exhaustive]
12#[cfg_attr(feature = "builders", derive(Builder))]
13#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct CodeCommitEvent {
16    #[serde(rename = "Records")]
17    pub records: Vec<CodeCommitRecord>,
18    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
19    /// Enabled with Cargo feature `catch-all-fields`.
20    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
21    #[cfg(feature = "catch-all-fields")]
22    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
23    #[serde(flatten)]
24    #[cfg_attr(feature = "builders", builder(default))]
25    pub other: serde_json::Map<String, Value>,
26}
27
28pub type CodeCommitEventTime = DateTime<Utc>;
29
30/// `CodeCommitRecord` represents a CodeCommit record
31#[non_exhaustive]
32#[cfg_attr(feature = "builders", derive(Builder))]
33#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
34#[serde(rename_all = "camelCase")]
35pub struct CodeCommitRecord {
36    #[serde(default)]
37    pub event_id: Option<String>,
38    #[serde(default)]
39    pub event_version: Option<String>,
40    pub event_time: CodeCommitEventTime,
41    #[serde(default)]
42    pub event_trigger_name: Option<String>,
43    pub event_part_number: u64,
44    #[serde(rename = "codecommit")]
45    pub code_commit: CodeCommitCodeCommit,
46    #[serde(default)]
47    pub event_name: Option<String>,
48    /// nolint: stylecheck
49    #[serde(default)]
50    pub event_trigger_config_id: Option<String>,
51    #[serde(default)]
52    #[serde(rename = "eventSourceARN")]
53    pub event_source_arn: Option<String>,
54    #[serde(default)]
55    #[serde(rename = "userIdentityARN")]
56    pub user_identity_arn: Option<String>,
57    #[serde(default)]
58    pub event_source: Option<String>,
59    #[serde(default)]
60    pub aws_region: Option<String>,
61    pub event_total_parts: u64,
62    pub custom_data: Option<String>,
63    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
64    /// Enabled with Cargo feature `catch-all-fields`.
65    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
66    #[cfg(feature = "catch-all-fields")]
67    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
68    #[serde(flatten)]
69    #[cfg_attr(feature = "builders", builder(default))]
70    pub other: serde_json::Map<String, Value>,
71}
72
73/// `CodeCommitCodeCommit` represents a CodeCommit object in a record
74#[non_exhaustive]
75#[cfg_attr(feature = "builders", derive(Builder))]
76#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
77#[serde(rename_all = "camelCase")]
78pub struct CodeCommitCodeCommit {
79    pub references: Vec<CodeCommitReference>,
80    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
81    /// Enabled with Cargo feature `catch-all-fields`.
82    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
83    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
84    /// Enabled with Cargo feature `catch-all-fields`.
85    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
86    #[cfg(feature = "catch-all-fields")]
87    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
88    #[serde(flatten)]
89    #[cfg_attr(feature = "builders", builder(default))]
90    pub other: serde_json::Map<String, Value>,
91}
92
93/// `CodeCommitReference` represents a Reference object in a CodeCommit object
94#[non_exhaustive]
95#[cfg_attr(feature = "builders", derive(Builder))]
96#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
97#[serde(rename_all = "camelCase")]
98pub struct CodeCommitReference {
99    #[serde(default)]
100    pub commit: Option<String>,
101    #[serde(default)]
102    pub ref_: Option<String>,
103    #[serde(default, deserialize_with = "deserialize_nullish")]
104    pub created: bool,
105    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
106    /// Enabled with Cargo feature `catch-all-fields`.
107    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
108    #[cfg(feature = "catch-all-fields")]
109    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
110    #[serde(flatten)]
111    #[cfg_attr(feature = "builders", builder(default))]
112    pub other: serde_json::Map<String, Value>,
113}
114
115#[cfg(test)]
116mod test {
117    use super::*;
118
119    #[test]
120    #[cfg(feature = "code_commit")]
121    fn example_code_commit_event() {
122        let data = include_bytes!("../../fixtures/example-code_commit-event.json");
123        let parsed: CodeCommitEvent = serde_json::from_slice(data).unwrap();
124        let output: String = serde_json::to_string(&parsed).unwrap();
125        let reparsed: CodeCommitEvent = serde_json::from_slice(output.as_bytes()).unwrap();
126        assert_eq!(parsed, reparsed);
127    }
128}