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)]
64pub struct EnvironmentVariable {
65 pub uuid: Option<String>,
66 pub key: Option<String>,
67 pub value: Option<String>,
68 pub secured: Option<bool>,
69}
70
71#[derive(Debug, Clone, Serialize)]
73pub struct EnvironmentVariableInput {
74 pub key: String,
75 pub value: String,
76 pub secured: bool,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct Deployment {
90 pub uuid: Option<String>,
91 pub state: Option<DeploymentState>,
92 pub environment: Option<Environment>,
93 pub release: Option<serde_json::Value>,
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct DeploymentState {
99 pub name: Option<String>,
100 pub status: Option<serde_json::Value>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct BranchingModel {
111 pub development: Option<ModelBranch>,
112 pub production: Option<ModelBranch>,
113 pub branch_types: Option<Vec<BranchType>>,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct ModelBranch {
119 pub name: Option<String>,
120 pub branch: Option<crate::models::Branch>,
123 pub use_mainbranch: Option<bool>,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct BranchType {
129 pub kind: Option<String>,
130 pub prefix: Option<String>,
131}
132
133#[derive(Debug, Clone, Default, Serialize)]
137pub struct UpdateBranchingModelRequest {
138 #[serde(skip_serializing_if = "Option::is_none")]
139 pub development: Option<BranchingModelBranchSettings>,
140 #[serde(skip_serializing_if = "Option::is_none")]
141 pub production: Option<BranchingModelBranchSettings>,
142}
143
144impl UpdateBranchingModelRequest {
145 pub fn is_empty(&self) -> bool {
146 self.development.is_none() && self.production.is_none()
147 }
148}
149
150#[derive(Debug, Clone, Default, Serialize)]
153pub struct BranchingModelBranchSettings {
154 #[serde(skip_serializing_if = "Option::is_none")]
155 pub name: Option<String>,
156 #[serde(skip_serializing_if = "Option::is_none")]
157 pub use_mainbranch: Option<bool>,
158 #[serde(skip_serializing_if = "Option::is_none")]
159 pub enabled: Option<bool>,
160}
161
162#[cfg(test)]
163mod tests {
164 use super::{
165 BranchingModelBranchSettings, CreateEnvironmentRequest, EnvironmentType,
166 UpdateBranchingModelRequest,
167 };
168
169 #[test]
170 fn add_deploy_key_request_serializes_key_and_label() {
171 let request = super::AddDeployKeyRequest {
172 key: "ssh-ed25519 AAAA host".to_string(),
173 label: "deploy".to_string(),
174 };
175 let json = serde_json::to_value(&request).unwrap();
176 assert_eq!(
177 json,
178 serde_json::json!({ "key": "ssh-ed25519 AAAA host", "label": "deploy" })
179 );
180 }
181
182 #[test]
183 fn create_environment_request_nests_environment_type() {
184 let request = CreateEnvironmentRequest {
185 name: "prod".to_string(),
186 environment_type: EnvironmentType {
187 name: Some("Production".to_string()),
188 },
189 };
190 let json = serde_json::to_value(&request).unwrap();
191 assert_eq!(
192 json,
193 serde_json::json!({
194 "name": "prod",
195 "environment_type": { "name": "Production" }
196 })
197 );
198 }
199
200 #[test]
201 fn update_branching_model_request_omits_unset_fields() {
202 let request = UpdateBranchingModelRequest {
203 development: Some(BranchingModelBranchSettings {
204 name: Some("develop".to_string()),
205 use_mainbranch: Some(false),
206 enabled: None,
207 }),
208 production: None,
209 };
210 let json = serde_json::to_value(&request).unwrap();
211 assert_eq!(
212 json,
213 serde_json::json!({
214 "development": { "name": "develop", "use_mainbranch": false }
215 })
216 );
217 }
218
219 #[test]
220 fn update_branching_model_request_is_empty() {
221 assert!(UpdateBranchingModelRequest::default().is_empty());
222
223 let with_production = UpdateBranchingModelRequest {
224 production: Some(BranchingModelBranchSettings::default()),
225 ..Default::default()
226 };
227 assert!(!with_production.is_empty());
228 }
229}