git-next/crates/forge/src/lib.rs
Paul Campbell 98839c8a00
All checks were successful
Rust / build (push) Successful in 1m11s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
test: add more tests to forge crate
2024-06-01 12:03:30 +01:00

48 lines
1.3 KiB
Rust

//
use git_next_forge_forgejo as forgejo;
use git_next_forge_github as github;
use git_next_git as git;
use kxio::network::Network;
mod mock_forge;
#[derive(Clone, Debug)]
pub enum Forge {
Mock(mock_forge::MockForge),
#[cfg(feature = "forgejo")]
ForgeJo(git_next_forge_forgejo::ForgeJo),
#[cfg(feature = "github")]
Github(git_next_forge_github::Github),
}
impl Forge {
pub fn new(repo_details: git::RepoDetails, net: Network) -> Self {
match repo_details.forge.forge_type() {
#[cfg(feature = "forgejo")]
git_next_config::ForgeType::ForgeJo => {
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net))
}
#[cfg(feature = "github")]
git_next_config::ForgeType::GitHub => {
Self::Github(github::Github::new(repo_details, net))
}
git_next_config::ForgeType::MockForge => Self::Mock(mock_forge::MockForge::new()),
}
}
}
impl std::ops::Deref for Forge {
type Target = dyn git::ForgeLike;
fn deref(&self) -> &Self::Target {
match self {
Self::Mock(env) => env,
#[cfg(feature = "forgejo")]
Self::ForgeJo(env) => env,
#[cfg(feature = "github")]
Self::Github(env) => env,
}
}
}
#[cfg(test)]
pub mod tests;