Skip to main content

grp_core/common/orgs/
create.rs

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