1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use std::ops::Deref;
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use crate::config::ForgeConfig;
pub mod gitlab;
#[derive(Clone, Debug)]
pub enum Forge {
Gitlab(self::gitlab::Gitlab),
}
impl Forge {
pub async fn new(config: &ForgeConfig) -> Result<Forge> {
match config {
ForgeConfig::Gitlab(config) => {
Ok(Forge::Gitlab(gitlab::Gitlab::from_config(config).await?))
}
#[allow(unreachable_patterns)]
_ => bail!("wrong forge type found"),
}
}
}
#[async_trait::async_trait]
pub trait ForgeTrait {
async fn projects(&self, scope: &str) -> Result<Vec<Project>>;
}
impl Deref for Forge {
type Target = dyn ForgeTrait;
fn deref(&self) -> &Self::Target {
match self {
Forge::Gitlab(forge) => forge,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Project {
pub id: String,
pub name: String,
pub path: String,
pub ssh_clone_url: Option<String>,
pub http_clone_url: Option<String>,
}
|