Skip to main content

grp_core/
platform.rs

1/// Current list of suported repos
2pub const SUPPORTED_REPOS: [(&str, &str, &str); 5] = [
3    ("0", "gh", "github"),
4    ("1", "gt", "gitea"),
5    ("2", "gl", "gitlab"),
6    ("3", "cb", "codeberg"),
7    ("4", "fg", "forgejo"),
8];
9
10/// # Platform
11/// is the main part of grp, this struct allows 
12/// you to interact with any platform, just by 
13/// giving a configuration
14/// 
15/// ~~~
16/// use grp_core::Platform;
17/// 
18/// let platform = Platform::matches("github");
19/// 
20/// assert!(platform.unwrap() == Platform::Github);
21/// ~~~
22/// 
23#[derive(PartialEq, Clone)]
24pub enum Platform {
25    Github,
26    Gitea,
27    Gitlab,
28    Codeberg,
29    Forgejo,
30}
31
32impl Platform {
33    /// return the &str name for the repo.
34    pub fn name(&self) -> &'static str {
35        match self {
36            Platform::Github => "github",
37            Platform::Gitea => "gitea",
38            Platform::Gitlab => "gitlab",
39            Platform::Codeberg => "codeberg",
40            Platform::Forgejo => "forgejo",
41        }
42    }
43    
44    /// Max path depth for a repo
45    pub fn max_repo_depth(&self) -> usize {
46        match self {
47            Platform::Github |
48            Platform::Codeberg |
49            Platform::Forgejo |
50            Platform::Gitea => 1,
51            Platform::Gitlab => usize::MAX,
52        }
53    }
54}