Skip to main content

gitea_sdk_rs/options/org/
action.rs

1// Copyright 2026 infinitete. All rights reserved.
2// Use of this source code is governed by a MIT-style
3// license that can be found in the LICENSE file.
4
5use crate::pagination::{ListOptions, QueryEncode};
6use crate::{Deserialize, Serialize};
7
8// ── org_action.go ───────────────────────────────────────────────────────
9
10#[derive(Debug, Clone, Default)]
11pub struct ListOrgActionSecretOption {
12    pub list_options: ListOptions,
13}
14
15impl QueryEncode for ListOrgActionSecretOption {
16    fn query_encode(&self) -> String {
17        self.list_options.query_encode()
18    }
19}
20
21#[derive(Debug, Clone, Default)]
22pub struct ListOrgActionVariableOption {
23    pub list_options: ListOptions,
24}
25
26impl QueryEncode for ListOrgActionVariableOption {
27    fn query_encode(&self) -> String {
28        self.list_options.query_encode()
29    }
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct OrgActionVariable {
34    #[serde(rename = "owner_id")]
35    pub owner_id: i64,
36    #[serde(rename = "repo_id")]
37    pub repo_id: i64,
38    pub name: String,
39    pub data: String,
40    pub description: String,
41}
42
43#[derive(Debug, Clone, Default, Serialize, Deserialize)]
44pub struct CreateOrgActionVariableOption {
45    pub name: String,
46    pub value: String,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub description: Option<String>,
49}
50
51impl CreateOrgActionVariableOption {
52    pub fn validate(&self) -> crate::Result<()> {
53        if self.name.is_empty() {
54            return Err(crate::Error::Validation("name required".to_string()));
55        }
56        if self.name.len() > 30 {
57            return Err(crate::Error::Validation("name too long".to_string()));
58        }
59        if self.value.is_empty() {
60            return Err(crate::Error::Validation("value required".to_string()));
61        }
62        Ok(())
63    }
64}
65
66#[derive(Debug, Clone, Default, Serialize, Deserialize)]
67pub struct UpdateOrgActionVariableOption {
68    pub value: String,
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub description: Option<String>,
71}
72
73impl UpdateOrgActionVariableOption {
74    pub fn validate(&self) -> crate::Result<()> {
75        if self.value.is_empty() {
76            return Err(crate::Error::Validation("value required".to_string()));
77        }
78        Ok(())
79    }
80}
81
82#[derive(Debug, Clone, Default, Serialize, Deserialize)]
83pub struct CreateSecretOption {
84    pub name: String,
85    pub data: String,
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub description: Option<String>,
88}
89
90impl CreateSecretOption {
91    pub fn validate(&self) -> crate::Result<()> {
92        if self.name.is_empty() {
93            return Err(crate::Error::Validation("name required".to_string()));
94        }
95        if self.name.len() > 30 {
96            return Err(crate::Error::Validation("name too long".to_string()));
97        }
98        if self.data.is_empty() {
99            return Err(crate::Error::Validation("data required".to_string()));
100        }
101        Ok(())
102    }
103}
104
105#[cfg(test)]
106mod tests {
107    use super::*;
108
109    #[test]
110    fn test_create_org_action_variable_option_validate_success() {
111        let opt = CreateOrgActionVariableOption {
112            name: "VAR".to_string(),
113            value: "value".to_string(),
114            description: None,
115        };
116        assert!(opt.validate().is_ok());
117    }
118
119    #[test]
120    fn test_create_org_action_variable_option_validate_empty_name() {
121        let opt = CreateOrgActionVariableOption {
122            name: String::new(),
123            value: "value".to_string(),
124            description: None,
125        };
126        assert!(opt.validate().is_err());
127    }
128
129    #[test]
130    fn test_create_org_action_variable_option_validate_name_too_long() {
131        let opt = CreateOrgActionVariableOption {
132            name: "a".repeat(31),
133            value: "value".to_string(),
134            description: None,
135        };
136        assert!(opt.validate().is_err());
137    }
138
139    #[test]
140    fn test_create_org_action_variable_option_validate_empty_value() {
141        let opt = CreateOrgActionVariableOption {
142            name: "VAR".to_string(),
143            value: String::new(),
144            description: None,
145        };
146        assert!(opt.validate().is_err());
147    }
148
149    #[test]
150    fn test_update_org_action_variable_option_validate_success() {
151        let opt = UpdateOrgActionVariableOption {
152            value: "new-value".to_string(),
153            description: None,
154        };
155        assert!(opt.validate().is_ok());
156    }
157
158    #[test]
159    fn test_update_org_action_variable_option_validate_empty_value() {
160        let opt = UpdateOrgActionVariableOption {
161            value: String::new(),
162            description: None,
163        };
164        assert!(opt.validate().is_err());
165    }
166
167    #[test]
168    fn test_create_secret_option_validate_success() {
169        let opt = CreateSecretOption {
170            name: "MY_SECRET".to_string(),
171            data: "secret-data".to_string(),
172            description: None,
173        };
174        assert!(opt.validate().is_ok());
175    }
176
177    #[test]
178    fn test_create_secret_option_validate_empty_name() {
179        let opt = CreateSecretOption {
180            name: String::new(),
181            data: "secret-data".to_string(),
182            description: None,
183        };
184        assert!(opt.validate().is_err());
185    }
186
187    #[test]
188    fn test_create_secret_option_validate_empty_data() {
189        let opt = CreateSecretOption {
190            name: "MY_SECRET".to_string(),
191            data: String::new(),
192            description: None,
193        };
194        assert!(opt.validate().is_err());
195    }
196}