Skip to main content

grp_core/common/orgs/
create.rs

1use crate::empty_notes;
2use crate::error::errors::request::Request;
3use crate::platform::Platform;
4use crate::error::structs::Error;
5use crate::config::Config;
6use crate::common::users::structs::User;
7use crate::animation::Animation;
8use crate::specific::{gitea, gitlab};
9
10
11impl Platform {
12    /// Create a given **org** for the logged user in the selected platform.
13    /// 
14    /// - `name`: the name or path of the **org** to be created.
15    /// - `config`: a `grp_core::Config`.
16    /// - `recursive`: only valid for "Gitlab", it will create all the groups if they not exist. 
17    /// - `animation`: a struct wich implements the trait `grp_core::animation::Animation`.
18    /// 
19    /// # Returns
20    /// a tuple with:
21    /// 1. `Vec<User>`: A list of the created orgs.
22    /// 2. `Vec<Error>`: A list of errors if some org faild to be created.
23    pub async fn create_org<T: Into<String>, A: Animation + ?Sized>(&self, 
24        name: T,
25        config: &Config,
26        recursive: bool, 
27        animation: &Box<A>
28    ) -> (Vec<User>, Vec<Error>) {
29        let name = name.into();
30        match self {
31            Platform::Github => (
32                vec![],
33                vec![ Request::unsuported(self.name(), "Create orgs", empty_notes!()) ]
34            ),
35            Platform::Codeberg |
36            Platform::Forgejo |
37            Platform::Gitea => {
38                let result = gitea::orgs::create::create(self, &name, config, animation).await;
39                match result {
40                    Ok(u)  => (vec![u], vec![]),
41                    Err(e) => (vec![], vec![e]),
42                }
43            },
44            Platform::Gitlab => gitlab::groups::create::create_group(self, &name, &config, recursive, animation).await
45        }
46    }
47}