85 lines
2 KiB
Rust
85 lines
2 KiB
Rust
|
#![allow(dead_code)]
|
||
|
|
||
|
use kxio::network::Network;
|
||
|
|
||
|
#[cfg(feature = "forgejo")]
|
||
|
mod forgejo;
|
||
|
|
||
|
#[cfg(feature = "github")]
|
||
|
mod github;
|
||
|
|
||
|
mod mock_forge;
|
||
|
|
||
|
mod types;
|
||
|
pub use types::*;
|
||
|
|
||
|
mod errors;
|
||
|
pub use errors::*;
|
||
|
|
||
|
use crate::server::{
|
||
|
config::{BranchName, RepoConfig, RepoDetails},
|
||
|
types::GitRef,
|
||
|
};
|
||
|
|
||
|
#[async_trait::async_trait]
|
||
|
pub trait ForgeLike {
|
||
|
fn name(&self) -> String;
|
||
|
async fn branches_get_all(&self) -> Result<Vec<Branch>, ForgeBranchError>;
|
||
|
async fn file_contents_get(
|
||
|
&self,
|
||
|
branch: &super::config::BranchName,
|
||
|
file_path: &str,
|
||
|
) -> Result<String, ForgeFileError>;
|
||
|
async fn branches_validate_positions(
|
||
|
&self,
|
||
|
repo_config: RepoConfig,
|
||
|
addr: actix::prelude::Addr<super::actors::repo::RepoActor>,
|
||
|
);
|
||
|
fn branch_reset(
|
||
|
&self,
|
||
|
branch_name: BranchName,
|
||
|
to_commit: GitRef,
|
||
|
force: Force,
|
||
|
) -> BranchResetResult;
|
||
|
|
||
|
async fn commit_status(&self, commit: &Commit) -> CommitStatus;
|
||
|
}
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub enum Forge {
|
||
|
Mock(mock_forge::MockForgeEnv),
|
||
|
#[allow(clippy::enum_variant_names)]
|
||
|
#[cfg(feature = "forgejo")]
|
||
|
ForgeJo(forgejo::ForgeJoEnv),
|
||
|
#[cfg(feature = "github")]
|
||
|
Github(github::GithubEnv),
|
||
|
}
|
||
|
impl Forge {
|
||
|
pub const fn new_mock() -> Self {
|
||
|
Self::Mock(mock_forge::MockForgeEnv::new())
|
||
|
}
|
||
|
#[cfg(feature = "forgejo")]
|
||
|
pub const fn new_forgejo(repo_details: RepoDetails, net: Network) -> Self {
|
||
|
Self::ForgeJo(forgejo::ForgeJoEnv::new(repo_details, net))
|
||
|
}
|
||
|
#[cfg(feature = "github")]
|
||
|
pub const fn new_github(net: Network) -> Self {
|
||
|
Self::Github(github::GithubEnv::new(net))
|
||
|
}
|
||
|
}
|
||
|
impl std::ops::Deref for Forge {
|
||
|
type Target = dyn ForgeLike;
|
||
|
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)]
|
||
|
mod tests;
|