2024-05-25 11:25:13 +01:00
|
|
|
//
|
2024-05-23 19:36:05 +01:00
|
|
|
use git_next_forge_forgejo as forgejo;
|
2024-05-25 11:25:13 +01:00
|
|
|
use git_next_forge_github as github;
|
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;
|
|
|
|
|
|
|
|
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 {
|
2024-05-25 11:25:13 +01:00
|
|
|
Mock(mock_forge::MockForge),
|
|
|
|
|
2024-04-16 22:21:55 +01:00
|
|
|
#[cfg(feature = "forgejo")]
|
2024-05-25 11:25:13 +01:00
|
|
|
ForgeJo(git_next_forge_forgejo::ForgeJo),
|
|
|
|
|
2024-04-16 22:21:55 +01:00
|
|
|
#[cfg(feature = "github")]
|
2024-05-25 11:25:13 +01:00
|
|
|
Github(git_next_forge_github::Github),
|
2024-04-16 22:21:55 +01:00
|
|
|
}
|
|
|
|
impl Forge {
|
2024-06-01 12:03:30 +01:00
|
|
|
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()),
|
|
|
|
}
|
2024-04-16 22:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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")]
|
2024-05-25 11:25:13 +01:00
|
|
|
Self::Github(env) => env,
|
2024-04-16 22:21:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2024-04-24 07:08:03 +01:00
|
|
|
pub mod tests;
|