gitea_sdk/api/orgs/
mod.rs

1pub mod create;
2pub mod create_repo;
3pub mod delete;
4pub mod edit;
5pub mod get;
6pub mod list_repos;
7pub mod members;
8pub mod public_members;
9
10pub struct Orgs {
11    pub name: String,
12}
13
14impl Orgs {
15    /// Create a new [Organization](crate::model::orgs::Organization).
16    ///
17    /// # Example
18    /// ```
19    /// # use gitea_sdk::{Client, Auth};
20    /// # async fn create_org() {
21    /// let client = Client::new(
22    ///     "https://gitea.example.com",
23    ///     Auth::Token("your-token")
24    /// );
25    /// client
26    ///     .orgs("org-name")
27    ///     .create()
28    ///     .full_name("Organization")
29    ///     .send(&client)
30    ///     .await
31    ///     .unwrap();
32    /// # }
33    /// ```
34    /// This will create a new organization with the name "org-name" and the full name
35    /// "Organization
36    pub fn create(&self) -> create::CreateOrgBuilder {
37        create::CreateOrgBuilder::new(self.name.clone())
38    }
39
40    /// Get an [Organization](crate::model::orgs::Organization).
41    ///
42    /// # Example
43    /// ```
44    /// # use gitea_sdk::{Client, Auth};
45    /// # async fn get_org() {
46    /// let client = Client::new(
47    ///     "https://gitea.example.com",
48    ///     Auth::Token("your-token")
49    /// );
50    /// let org = client
51    ///     .orgs("org-name")
52    ///     .get()
53    ///     .send(&client)
54    ///     .await
55    ///     .unwrap();
56    /// # }
57    /// ```
58    /// This will get the organization with the name "org-name".
59    pub fn get(&self) -> get::GetOrgBuilder {
60        get::GetOrgBuilder::new(self.name.clone())
61    }
62
63    /// Delete an [Organization](crate::model::orgs::Organization).
64    /// This will delete the organization with the name "org-name".
65    /// This action is irreversible.
66    ///
67    /// # Example
68    /// ```
69    /// # use gitea_sdk::{Client, Auth};
70    /// # async fn delete_org() {
71    /// let client = Client::new(
72    ///     "https://gitea.example.com",
73    ///     Auth::Token("your-token")
74    /// );
75    /// client
76    ///     .orgs("org-name")
77    ///     .delete()
78    ///     .send(&client)
79    ///     .await
80    ///     .unwrap();
81    /// # }
82    /// ```
83    /// This will delete the organization with the name "org-name".
84    pub fn delete(&self) -> delete::DeleteOrgBuilder {
85        delete::DeleteOrgBuilder::new(self.name.clone())
86    }
87
88    /// Edit an [Organization](crate::model::orgs::Organization).
89    ///
90    /// # Example
91    /// ```
92    /// # use gitea_sdk::{Client, Auth};
93    /// # async fn edit_org() {
94    /// let client = Client::new(
95    ///     "https://gitea.example.com",
96    ///     Auth::Token("your-token")
97    /// );
98    /// client
99    ///     .orgs("org-name")
100    ///     .edit()
101    ///     .description("New description")
102    ///     .send(&client)
103    ///     .await
104    ///     .unwrap();
105    /// # }
106    /// ```
107    /// This will edit the organization with the name "org-name" to have the description "New
108    /// description".
109    pub fn edit(&self) -> edit::EditOrgBuilder {
110        edit::EditOrgBuilder::new(self.name.clone())
111    }
112
113    /// List an [Organization](crate::model::orgs::Organization)'s
114    /// [Repositories](crate::model::repos::Repository).
115    ///
116    /// # Example
117    /// ```
118    /// # use gitea_sdk::{Client, Auth};
119    /// # async fn list_repos() {
120    /// let client = Client::new(
121    ///     "https://gitea.example.com",
122    ///     Auth::Token("your-token")
123    /// );
124    /// let repos = client
125    ///     .orgs("org-name")
126    ///     .list_repos()
127    ///     .page(2)
128    ///     .limit(10)
129    ///     .send(&client)
130    ///     .await
131    ///     .unwrap();
132    /// # }
133    /// ```
134    pub fn list_repos(&self) -> list_repos::ListReposBuilder {
135        list_repos::ListReposBuilder::new(self.name.clone())
136    }
137
138    /// Create a new [Repository](crate::model::repos::Repository) in an
139    /// [Organization](crate::model::orgs::Organization).
140    ///
141    /// # Example
142    /// ```
143    /// # use gitea_sdk::{Client, Auth};
144    /// # async fn create_repo() {
145    /// let client = Client::new(
146    ///     "https://gitea.example.com",
147    ///     Auth::Token("your-token")
148    /// );
149    /// client
150    ///     .orgs("org-name")
151    ///     .create_repo("repo-name")
152    ///     .auto_init(true)
153    ///     .license("mit")
154    ///     .send(&client)
155    ///     .await
156    ///     .unwrap();
157    /// # }
158    /// ```
159    pub fn create_repo(&self, name: impl ToString) -> create_repo::CreateRepoBuilder {
160        create_repo::CreateRepoBuilder::new(self.name.clone(), name)
161    }
162
163    /// List the members of an [Organization](crate::model::orgs::Organization).
164    ///
165    /// # Example
166    /// ```
167    /// # use gitea_sdk::{Client, Auth};
168    /// # async fn list_members() {
169    /// let client = Client::new(
170    ///     "https://gitea.example.com",
171    ///     Auth::Token("your-token")
172    /// );
173    /// let members = client
174    ///     .orgs("org-name")
175    ///     .list_members()
176    ///     .send(&client)
177    ///     .await
178    ///     .unwrap();
179    /// # }
180    /// ```
181    pub fn list_members(&self) -> members::ListMembersBuilder {
182        members::ListMembersBuilder::new(self.name.clone())
183    }
184
185    /// Check if a user is a member of an [Organization](crate::model::orgs::Organization).
186    ///
187    /// # Example
188    /// ```
189    /// # use gitea_sdk::{Client, Auth};
190    /// # async fn is_member() {
191    /// let client = Client::new(
192    ///     "https://gitea.example.com",
193    ///     Auth::Token("your-token")
194    /// );
195    /// let is_member = client
196    ///     .orgs("org-name")
197    ///     .is_member("username")
198    ///     .send(&client)
199    ///     .await
200    ///     .unwrap();
201    /// # }
202    /// ```
203    pub fn is_member(&self, username: impl ToString) -> members::IsMemberBuilder {
204        members::IsMemberBuilder::new(self.name.clone(), username)
205    }
206
207    /// Remove a user from an [Organization](crate::model::orgs::Organization).
208    ///
209    /// # Example
210    /// ```
211    /// # use gitea_sdk::{Client, Auth};
212    /// # async fn remove_member() {
213    /// let client = Client::new(
214    ///     "https://gitea.example.com",
215    ///     Auth::Token("your-token")
216    /// );
217    /// client
218    ///     .orgs("org-name")
219    ///     .remove_member("username")
220    ///     .send(&client)
221    ///     .await
222    ///     .unwrap();
223    /// # }
224    /// ```
225    pub fn remove_member(&self, username: impl ToString) -> members::RemoveMemberBuilder {
226        members::RemoveMemberBuilder::new(self.name.clone(), username)
227    }
228
229    /// List the public members of an [Organization](crate::model::orgs::Organization).
230    /// This will return a list of [User] objects.
231    ///
232    /// # Example
233    /// ```
234    /// # use gitea_sdk::{Client, Auth};
235    /// # async fn list_public_members() {
236    /// let client = Client::new(
237    ///     "https://gitea.example.com",
238    ///     Auth::Token("your-token")
239    /// );
240    /// let public_members = client
241    ///     .orgs("org-name")
242    ///     .list_public_members()
243    ///     .send(&client)
244    ///     .await
245    ///     .unwrap();
246    /// # }
247    /// ```
248    pub fn list_public_members(&self) -> public_members::ListPublicMembersBuilder {
249        public_members::ListPublicMembersBuilder::new(self.name.clone())
250    }
251
252    /// Check if a user is a public member of an [Organization](crate::model::orgs::Organization).
253    ///
254    /// # Example
255    /// ```
256    /// # use gitea_sdk::{Client, Auth};
257    /// # async fn is_public_member() {
258    /// let client = Client::new(
259    ///     "https://gitea.example.com",
260    ///     Auth::Token("your-token")
261    /// );
262    /// let is_public_member = client
263    ///     .orgs("org-name")
264    ///     .is_public_member("username")
265    ///     .send(&client)
266    ///     .await
267    ///     .unwrap();
268    /// # }
269    /// ```
270    pub fn is_public_member(
271        &self,
272        username: impl ToString,
273    ) -> public_members::IsPublicMemberBuilder {
274        public_members::IsPublicMemberBuilder::new(self.name.clone(), username)
275    }
276
277    /// Conceal a user's membership in an [Organization](crate::model::orgs::Organization).
278    /// This will hide the user from the organization's public members list.
279    ///
280    /// # Example
281    /// ```
282    /// # use gitea_sdk::{Client, Auth};
283    /// # async fn conceal_membership() {
284    /// let client = Client::new(
285    ///     "https://gitea.example.com",
286    ///     Auth::Token("your-token")
287    /// );
288    /// client
289    ///     .orgs("org-name")
290    ///     .conceal_membership("username")
291    ///     .send(&client)
292    ///     .await
293    ///     .unwrap();
294    /// # }
295    /// ```
296    pub fn conceal_membership(
297        &self,
298        username: impl ToString,
299    ) -> public_members::ConcealMembershipBuilder {
300        public_members::ConcealMembershipBuilder::new(self.name.clone(), username)
301    }
302
303    /// Publicize a user's membership in an [Organization](crate::model::orgs::Organization).
304    /// This will make the user visible in the organization's public members list.
305    ///
306    /// # Example
307    /// ```
308    /// # use gitea_sdk::{Client, Auth};
309    /// # async fn publicize_membership() {
310    /// let client = Client::new(
311    ///     "https://gitea.example.com",
312    ///     Auth::Token("your-token")
313    /// );
314    /// client
315    ///     .orgs("org-name")
316    ///     .publicize_membership("username")
317    ///     .send(&client)
318    ///     .await
319    ///     .unwrap();
320    /// # }
321    /// ```
322    pub fn publicize_membership(
323        &self,
324        username: impl ToString,
325    ) -> public_members::PublicizeMembershipBuilder {
326        public_members::PublicizeMembershipBuilder::new(self.name.clone(), username)
327    }
328}