2024-04-16 22:21:55 +01:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2024-05-23 19:36:05 +01:00
|
|
|
use git_next_forge_forgejo as forgejo;
|
2024-05-23 16:19:28 +01:00
|
|
|
use git_next_git as git;
|
2024-04-16 22:21:55 +01:00
|
|
|
use kxio::network::Network;
|
|
|
|
|
|
|
|
#[cfg(feature = "github")]
|
|
|
|
mod github;
|
|
|
|
|
|
|
|
mod mock_forge;
|
|
|
|
|
2024-05-04 12:37:35 +01:00
|
|
|
#[derive(Clone, Debug)]
|
2024-04-16 22:21:55 +01:00
|
|
|
pub enum Forge {
|
|
|
|
Mock(mock_forge::MockForgeEnv),
|
|
|
|
#[allow(clippy::enum_variant_names)]
|
|
|
|
#[cfg(feature = "forgejo")]
|
2024-05-23 19:36:05 +01:00
|
|
|
ForgeJo(forgejo::ForgeJo),
|
2024-04-16 22:21:55 +01:00
|
|
|
#[cfg(feature = "github")]
|
|
|
|
Github(github::GithubEnv),
|
|
|
|
}
|
|
|
|
impl Forge {
|
|
|
|
pub const fn new_mock() -> Self {
|
|
|
|
Self::Mock(mock_forge::MockForgeEnv::new())
|
|
|
|
}
|
|
|
|
#[cfg(feature = "forgejo")]
|
2024-05-18 11:41:18 +01:00
|
|
|
pub const fn new_forgejo(
|
2024-05-23 16:19:28 +01:00
|
|
|
repo_details: git::RepoDetails,
|
2024-05-18 11:41:18 +01:00
|
|
|
net: Network,
|
|
|
|
repo: git::Repository,
|
|
|
|
) -> Self {
|
2024-05-23 19:36:05 +01:00
|
|
|
Self::ForgeJo(forgejo::ForgeJo::new(repo_details, net, repo))
|
2024-04-16 22:21:55 +01:00
|
|
|
}
|
|
|
|
#[cfg(feature = "github")]
|
|
|
|
pub const fn new_github(net: Network) -> Self {
|
|
|
|
Self::Github(github::GithubEnv::new(net))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::ops::Deref for Forge {
|
2024-05-23 16:50:36 +01:00
|
|
|
type Target = dyn git::ForgeLike;
|
2024-04-16 22:21:55 +01:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
match self {
|
|
|
|
Self::Mock(env) => env,
|
|
|
|
#[cfg(feature = "forgejo")]
|
|
|
|
Self::ForgeJo(env) => env,
|
|
|
|
#[cfg(feature = "github")]
|
|
|
|
Forge::Github(env) => env,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2024-04-24 07:08:03 +01:00
|
|
|
pub mod tests;
|