2024-04-16 22:21:55 +01:00
|
|
|
#![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::*;
|
|
|
|
|
2024-05-11 18:57:18 +01:00
|
|
|
use crate::{
|
2024-04-21 18:47:07 +01:00
|
|
|
config::{BranchName, GitDir, RepoConfig, RepoDetails},
|
2024-05-05 08:17:32 +01:00
|
|
|
types::{GitRef, MessageToken},
|
2024-04-16 22:21:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
pub trait ForgeLike {
|
|
|
|
fn name(&self) -> String;
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
/// Returns a list of all branches in the repo.
|
2024-04-16 22:21:55 +01:00
|
|
|
async fn branches_get_all(&self) -> Result<Vec<Branch>, ForgeBranchError>;
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
/// Returns the contents of the file.
|
2024-04-16 22:21:55 +01:00
|
|
|
async fn file_contents_get(
|
|
|
|
&self,
|
|
|
|
branch: &super::config::BranchName,
|
|
|
|
file_path: &str,
|
|
|
|
) -> Result<String, ForgeFileError>;
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
/// Assesses the relative positions of the main, next and dev branch and updates their
|
|
|
|
/// positions as needed.
|
2024-04-16 22:21:55 +01:00
|
|
|
async fn branches_validate_positions(
|
|
|
|
&self,
|
2024-05-09 21:53:50 +01:00
|
|
|
repository: Repository,
|
2024-04-16 22:21:55 +01:00
|
|
|
repo_config: RepoConfig,
|
|
|
|
addr: actix::prelude::Addr<super::actors::repo::RepoActor>,
|
2024-05-05 08:17:32 +01:00
|
|
|
message_token: MessageToken,
|
2024-04-16 22:21:55 +01:00
|
|
|
);
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
/// Moves a branch to a new commit.
|
2024-04-16 22:21:55 +01:00
|
|
|
fn branch_reset(
|
|
|
|
&self,
|
2024-05-09 21:53:50 +01:00
|
|
|
repository: &Repository,
|
2024-04-16 22:21:55 +01:00
|
|
|
branch_name: BranchName,
|
|
|
|
to_commit: GitRef,
|
|
|
|
force: Force,
|
|
|
|
) -> BranchResetResult;
|
|
|
|
|
2024-04-19 18:56:42 +01:00
|
|
|
/// Checks the results of any (e.g. CI) status checks for the commit.
|
2024-04-16 22:21:55 +01:00
|
|
|
async fn commit_status(&self, commit: &Commit) -> CommitStatus;
|
2024-04-19 18:56:42 +01:00
|
|
|
|
|
|
|
/// Clones a repo to disk.
|
2024-05-09 21:18:40 +01:00
|
|
|
fn repo_clone(&self, gitdir: GitDir) -> Result<Repository, RepoCloneError>;
|
2024-04-16 22:21:55 +01:00
|
|
|
}
|
|
|
|
|
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")]
|
|
|
|
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)]
|
2024-04-24 07:08:03 +01:00
|
|
|
pub mod tests;
|