diff options
Diffstat (limited to 'src/forge/mod.rs')
| -rw-r--r-- | src/forge/mod.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/forge/mod.rs b/src/forge/mod.rs new file mode 100644 index 0000000..3e94812 --- /dev/null +++ b/src/forge/mod.rs @@ -0,0 +1,48 @@ +use std::ops::Deref; + +use anyhow::{Result, bail}; +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?)) + } + _ => 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>, +} |
