diff options
| author | Max Audron <audron@cocaine.farm> | 2022-06-07 12:28:18 +0200 |
|---|---|---|
| committer | Maximilian Manz <maximilian.manz@de.clara.net> | 2022-06-20 11:33:04 +0200 |
| commit | f869c7f52d8fd1f1ef61e218bbec4d0dac27673d (patch) | |
| tree | 8029b33976fc897a4ae81785e622a7e61ad2eb67 /src/forge/mod.rs | |
init
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>, +} |
