1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct DeployKey {
10 pub id: Option<u64>,
11 pub key: Option<String>,
13 pub label: Option<String>,
14 pub comment: Option<String>,
15}
16
17#[derive(Debug, Clone, Serialize)]
19#[non_exhaustive]
20pub struct AddDeployKeyRequest {
21 pub key: String,
22 pub label: String,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct Environment {
32 pub uuid: Option<String>,
33 pub name: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub environment_type: Option<EnvironmentType>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct EnvironmentType {
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub name: Option<String>,
43}
44
45#[derive(Debug, Clone, Serialize)]
47#[non_exhaustive]
48pub struct CreateEnvironmentRequest {
49 pub name: String,
50 pub environment_type: EnvironmentType,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct Deployment {
64 pub uuid: Option<String>,
65 pub state: Option<DeploymentState>,
66 pub environment: Option<Environment>,
67 pub release: Option<serde_json::Value>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct DeploymentState {
73 pub name: Option<String>,
74 pub status: Option<serde_json::Value>,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct BranchingModel {
85 pub development: Option<ModelBranch>,
86 pub production: Option<ModelBranch>,
87 pub branch_types: Option<Vec<BranchType>>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct ModelBranch {
93 pub name: Option<String>,
94 pub branch: Option<crate::models::Branch>,
97 pub use_mainbranch: Option<bool>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct BranchType {
103 pub kind: Option<String>,
104 pub prefix: Option<String>,
105}
106
107#[derive(Debug, Clone, Default, Serialize)]
111pub struct UpdateBranchingModelRequest {
112 #[serde(skip_serializing_if = "Option::is_none")]
113 pub development: Option<BranchingModelBranchSettings>,
114 #[serde(skip_serializing_if = "Option::is_none")]
115 pub production: Option<BranchingModelBranchSettings>,
116}
117
118impl UpdateBranchingModelRequest {
119 pub fn is_empty(&self) -> bool {
120 self.development.is_none() && self.production.is_none()
121 }
122}
123
124#[derive(Debug, Clone, Default, Serialize)]
127pub struct BranchingModelBranchSettings {
128 #[serde(skip_serializing_if = "Option::is_none")]
129 pub name: Option<String>,
130 #[serde(skip_serializing_if = "Option::is_none")]
131 pub use_mainbranch: Option<bool>,
132 #[serde(skip_serializing_if = "Option::is_none")]
133 pub enabled: Option<bool>,
134}
135
136#[cfg(test)]
137mod tests {
138 use super::{
139 BranchingModelBranchSettings, CreateEnvironmentRequest, EnvironmentType,
140 UpdateBranchingModelRequest,
141 };
142
143 #[test]
144 fn add_deploy_key_request_serializes_key_and_label() {
145 let request = super::AddDeployKeyRequest {
146 key: "ssh-ed25519 AAAA host".to_string(),
147 label: "deploy".to_string(),
148 };
149 let json = serde_json::to_value(&request).unwrap();
150 assert_eq!(
151 json,
152 serde_json::json!({ "key": "ssh-ed25519 AAAA host", "label": "deploy" })
153 );
154 }
155
156 #[test]
157 fn create_environment_request_nests_environment_type() {
158 let request = CreateEnvironmentRequest {
159 name: "prod".to_string(),
160 environment_type: EnvironmentType {
161 name: Some("Production".to_string()),
162 },
163 };
164 let json = serde_json::to_value(&request).unwrap();
165 assert_eq!(
166 json,
167 serde_json::json!({
168 "name": "prod",
169 "environment_type": { "name": "Production" }
170 })
171 );
172 }
173
174 #[test]
175 fn update_branching_model_request_omits_unset_fields() {
176 let request = UpdateBranchingModelRequest {
177 development: Some(BranchingModelBranchSettings {
178 name: Some("develop".to_string()),
179 use_mainbranch: Some(false),
180 enabled: None,
181 }),
182 production: None,
183 };
184 let json = serde_json::to_value(&request).unwrap();
185 assert_eq!(
186 json,
187 serde_json::json!({
188 "development": { "name": "develop", "use_mainbranch": false }
189 })
190 );
191 }
192
193 #[test]
194 fn update_branching_model_request_is_empty() {
195 assert!(UpdateBranchingModelRequest::default().is_empty());
196
197 let with_production = UpdateBranchingModelRequest {
198 production: Some(BranchingModelBranchSettings::default()),
199 ..Default::default()
200 };
201 assert!(!with_production.is_empty());
202 }
203}