refactor: merge forge crate into cli crate

This commit is contained in:
Paul Campbell 2024-07-28 13:35:26 +01:00
parent c1981d862c
commit 57458173d0
10 changed files with 47 additions and 83 deletions

View file

@ -15,7 +15,6 @@ documentation = "https://git.kemitix.net/kemitix/git-next/src/branch/main/README
keywords = ["git", "cli", "server", "tool"] keywords = ["git", "cli", "server", "tool"]
categories = ["development-tools"] categories = ["development-tools"]
[workspace.lints.clippy] [workspace.lints.clippy]
nursery = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 }
# pedantic = "warn" # pedantic = "warn"

View file

@ -11,10 +11,16 @@ documentation = { workspace = true }
keywords = { workspace = true } keywords = { workspace = true }
categories = { workspace = true } categories = { workspace = true }
[features]
default = ["forgejo", "github"]
forgejo = ["git-next-forge-forgejo"]
github = ["git-next-forge-github"]
[dependencies] [dependencies]
git-next-core = { workspace = true } git-next-core = { workspace = true }
git-next-server-actor = { workspace = true } git-next-server-actor = { workspace = true }
git-next-forge = { workspace = true } git-next-forge-forgejo = { workspace = true, optional = true }
git-next-forge-github = { workspace = true, optional = true }
# CLI parsing # CLI parsing
clap = { workspace = true } clap = { workspace = true }

View file

@ -520,11 +520,8 @@ The following diagram shows the dependency between the crates that make up `git-
stateDiagram-v2 stateDiagram-v2
cli --> core cli --> core
cli --> forge cli --> forge_forgejo
cli --> forge_github
forge --> core
forge --> forge_forgejo
forge --> forge_github
forge_forgejo --> core forge_forgejo --> core

View file

@ -0,0 +1,31 @@
//
use git_next_core::{
git::{ForgeLike, RepoDetails},
ForgeType,
};
#[cfg(feature = "forgejo")]
use git_next_forge_forgejo::ForgeJo;
#[cfg(feature = "github")]
use git_next_forge_github::Github;
use kxio::network::Network;
#[derive(Clone, Debug)]
pub struct Forge;
impl Forge {
pub fn create(repo_details: RepoDetails, net: Network) -> Box<dyn ForgeLike> {
match repo_details.forge.forge_type() {
#[cfg(feature = "forgejo")]
ForgeType::ForgeJo => Box::new(ForgeJo::new(repo_details, net)),
#[cfg(feature = "github")]
ForgeType::GitHub => Box::new(Github::new(repo_details, net)),
ForgeType::MockForge => unreachable!(),
}
}
}
#[cfg(test)]
pub mod tests;

View file

@ -1,5 +1,6 @@
// //
mod file_watcher; mod file_watcher;
mod forge;
mod init; mod init;
mod repo; mod repo;
mod server; mod server;

View file

@ -10,6 +10,7 @@ mod handlers;
pub mod messages; pub mod messages;
use crate::{ use crate::{
forge::Forge,
repo::{ repo::{
messages::{CloneRepo, NotifyUser}, messages::{CloneRepo, NotifyUser},
RepoActor, RepoActor,
@ -179,7 +180,7 @@ impl ServerActor {
&forge_config, &forge_config,
gitdir, gitdir,
); );
let forge = git_next_forge::Forge::create(repo_details.clone(), net.clone()); let forge = Forge::create(repo_details.clone(), net.clone());
tracing::info!("Starting Repo Actor"); tracing::info!("Starting Repo Actor");
let actor = RepoActor::new( let actor = RepoActor::new(
repo_details, repo_details,

View file

@ -4,50 +4,4 @@ version = { workspace = true }
edition = { workspace = true } edition = { workspace = true }
license = { workspace = true } license = { workspace = true }
repository = { workspace = true } repository = { workspace = true }
description = "Generic forge support for git-next, the trunk-based development manager" description = "[deprecated crate] Generic forge support for git-next, the trunk-based development manager"
[features]
default = ["forgejo", "github"]
forgejo = ["git-next-forge-forgejo"]
github = ["git-next-forge-github"]
[dependencies]
git-next-core = { workspace = true }
git-next-forge-forgejo = { workspace = true, optional = true }
git-next-forge-github = { workspace = true, optional = true }
# logging
tracing = { workspace = true }
# base64 decoding
base64 = { workspace = true }
# git
async-trait = { workspace = true }
# fs/network
kxio = { workspace = true }
# TOML parsing
serde = { workspace = true }
serde_json = { workspace = true }
toml = { workspace = true }
# Secrets and Password
secrecy = { workspace = true }
# Webhooks
bytes = { workspace = true }
ulid = { workspace = true }
# boilerplate
derive_more = { workspace = true }
# # Actors
tokio = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"
unwrap_used = "warn"
expect_used = "warn"

View file

@ -7,3 +7,5 @@ development workflows where each commit must pass CI before being included in
the main branch. the main branch.
See [git-next](https://crates.io/crates/git-next) for more information. See [git-next](https://crates.io/crates/git-next) for more information.
N.B. this crate has been merged into [git-next](https://crates.io/git-next).

View file

@ -1,28 +1 @@
// // moved to /crates/cli/src/forge
use git_next_core::{git, ForgeType};
use kxio::network::Network;
#[derive(Clone, Debug)]
pub enum Forge {
Mock,
#[cfg(feature = "forgejo")]
ForgeJo(git_next_forge_forgejo::ForgeJo),
#[cfg(feature = "github")]
Github(git_next_forge_github::Github),
}
impl Forge {
pub fn create(repo_details: git::RepoDetails, net: Network) -> Box<dyn git::ForgeLike> {
match repo_details.forge.forge_type() {
#[cfg(feature = "forgejo")]
ForgeType::ForgeJo => Box::new(git_next_forge_forgejo::ForgeJo::new(repo_details, net)),
#[cfg(feature = "github")]
ForgeType::GitHub => Box::new(git_next_forge_github::Github::new(repo_details, net)),
ForgeType::MockForge => unreachable!(),
}
}
}
#[cfg(test)]
pub mod tests;