refactor: extract server crate
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-05-11 18:57:18 +01:00
parent 834dff4370
commit 3a112ddd8b
39 changed files with 128 additions and 54 deletions

View file

@ -1,6 +1,10 @@
[workspace]
resolver = "2"
members = ["crates/cli"]
members = ["crates/cli", "crates/server"]
[workspace.package]
version = "0.3.0"
edition = "2021"
[workspace.lints.clippy]
nursery = { level = "warn", priority = -1 }

View file

@ -1,14 +1,16 @@
[package]
name = "git-next"
version = "0.3.0"
edition = "2021"
version = { workspace = true }
edition = { workspace = true }
[features]
default = ["forgejo"]
forgejo = []
github = []
# [features]
# default = ["forgejo"]
# forgejo = []
# github = []
[dependencies]
git-next-server = { path = "../server" }
# CLI parsing
clap = { workspace = true }

View file

@ -1,5 +1,4 @@
mod init;
mod server;
use std::path::PathBuf;
@ -36,10 +35,10 @@ async fn main() {
}
Command::Server(server) => match server {
Server::Init => {
server::init(fs);
git_next_server::init(fs);
}
Server::Start => {
server::start(fs, net).await;
git_next_server::start(fs, net).await;
}
},
}

73
crates/server/Cargo.toml Normal file
View file

@ -0,0 +1,73 @@
[package]
name = "git-next-server"
version = { workspace = true }
edition = { workspace = true }
[features]
default = ["forgejo"]
forgejo = []
github = []
[dependencies]
# CLI parsing
clap = { workspace = true }
# logging
console-subscriber = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
# base64 decoding
base64 = { workspace = true }
# git
# gix = { workspace = true }
gix = { workspace = true }
async-trait = { workspace = true }
# fs/network
kxio = { workspace = true }
# fs
tempfile = { workspace = true }
# TOML parsing
serde = { workspace = true }
serde_json = { workspace = true }
toml = { workspace = true }
# Secrets and Password
secrecy = { workspace = true }
# Conventional Commit check
git-conventional = { workspace = true }
# Webhooks
bytes = { workspace = true }
ulid = { workspace = true }
warp = { workspace = true }
# error handling
derive_more = { workspace = true }
terrors = { workspace = true }
# file watcher
inotify = { workspace = true }
# Actors
actix = { workspace = true }
actix-rt = { workspace = true }
tokio = { workspace = true }
[dev-dependencies]
# Testing
assert2 = { workspace = true }
pretty_assertions = { workspace = true }
test-log = { workspace = true }
anyhow = { workspace = true }
[lints.clippy]
nursery = { level = "warn", priority = -1 }
# pedantic = "warn"
unwrap_used = "warn"
expect_used = "warn"

View file

@ -4,7 +4,7 @@ use actix::prelude::*;
use tracing::{info, warn};
use crate::server::{
use crate::{
actors::repo::{LoadConfigFromRepo, RepoActor, ValidateRepo},
config::{self, RepoConfigSource},
gitforge,

View file

@ -1,7 +1,7 @@
use actix::prelude::*;
use tracing::{error, info};
use crate::server::{config, gitforge};
use crate::{config, gitforge};
use super::{LoadedConfig, RepoActor};

View file

@ -7,7 +7,7 @@ use actix::prelude::*;
use kxio::network::Network;
use tracing::{debug, info, warn, Instrument};
use crate::server::{
use crate::{
actors::repo::webhook::WebhookAuth,
config::{RepoConfig, RepoDetails, Webhook},
gitforge::{self, Repository},
@ -39,11 +39,11 @@ impl RepoActor {
) -> Self {
let forge = match details.forge.forge_type {
#[cfg(feature = "forgejo")]
crate::server::config::ForgeType::ForgeJo => {
crate::config::ForgeType::ForgeJo => {
gitforge::Forge::new_forgejo(details.clone(), net.clone())
}
#[cfg(test)]
crate::server::config::ForgeType::MockForge => gitforge::Forge::new_mock(),
crate::config::ForgeType::MockForge => gitforge::Forge::new_mock(),
};
debug!(?forge, "new");
Self {

View file

@ -2,7 +2,7 @@ use actix::prelude::*;
use gix::trace::warn;
use tracing::info;
use crate::server::{actors::repo::ValidateRepo, gitforge, types::MessageToken};
use crate::{actors::repo::ValidateRepo, gitforge, types::MessageToken};
use super::AdvanceMainTo;

View file

@ -5,7 +5,7 @@ use ulid::DecodeError;
use std::{collections::HashMap, fmt::Display, ops::Deref, str::FromStr};
use crate::server::{
use crate::{
actors::{
repo::{RepoActor, ValidateRepo, WebhookRegistered},
webhook::WebhookMessage,
@ -60,7 +60,7 @@ impl Deref for WebhookAuth {
#[tracing::instrument(skip_all, fields(%webhook_id))]
pub async fn unregister(
webhook_id: WebhookId,
repo_details: crate::server::config::RepoDetails,
repo_details: crate::config::RepoDetails,
net: network::Network,
) {
let hostname = &repo_details.forge.hostname;
@ -88,7 +88,7 @@ pub async fn unregister(
#[tracing::instrument(skip_all)]
pub async fn register(
repo_details: crate::server::config::RepoDetails,
repo_details: crate::config::RepoDetails,
webhook: Webhook,
addr: actix::prelude::Addr<super::RepoActor>,
net: network::Network,
@ -147,7 +147,7 @@ pub async fn register(
}
async fn find_existing_webhooks(
repo_details: &crate::server::config::RepoDetails,
repo_details: &crate::config::RepoDetails,
webhook_url: &WebhookUrl,
net: &network::Network,
) -> Vec<WebhookId> {

View file

@ -5,7 +5,7 @@ use actix::prelude::*;
use kxio::{fs::FileSystem, network::Network};
use tracing::{error, info, warn};
use crate::server::{
use crate::{
actors::{
file_watcher::FileUpdated,
repo::{CloneRepo, RepoActor},
@ -28,7 +28,7 @@ pub enum Error {
path: PathBuf,
},
Config(crate::server::config::Error),
Config(crate::config::Error),
Io(std::io::Error),
}

View file

@ -1,7 +1,7 @@
//
use actix::prelude::*;
use crate::server::actors::repo::webhook::WebhookAuth;
use crate::actors::repo::webhook::WebhookAuth;
#[derive(Message, Debug, Clone)]
#[rtype(result = "()")]

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use actix::prelude::*;
use tracing::{debug, info};
use crate::server::{actors::webhook::message::WebhookMessage, config::RepoAlias};
use crate::{actors::webhook::message::WebhookMessage, config::RepoAlias};
pub struct WebhookRouter {
span: tracing::Span,

View file

@ -4,7 +4,7 @@ use actix::prelude::*;
use tracing::{debug, info};
use crate::server::actors::webhook::message::WebhookMessage;
use crate::actors::webhook::message::WebhookMessage;
pub async fn start(
socket_addr: SocketAddr,

View file

@ -1,7 +1,7 @@
use terrors::OneOf;
use tracing::error;
use crate::server::{
use crate::{
config::{BranchName, RepoConfig, RepoDetails},
gitforge::{self, ForgeFileError},
};
@ -13,7 +13,7 @@ pub async fn load(
RepoConfig,
OneOf<(
ForgeFileError,
crate::server::config::Error,
crate::config::Error,
toml::de::Error,
RepoConfigValidationErrors,
)>,

View file

@ -16,7 +16,7 @@ use serde::Deserialize;
use kxio::fs::FileSystem;
use tracing::info;
use crate::server::{gitforge::Repository, types::ServerGeneration};
use crate::{gitforge::Repository, types::ServerGeneration};
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum Error {

View file

@ -2,7 +2,7 @@ use assert2::let_assert;
use gix::remote::Direction;
use pretty_assertions::assert_eq;
use crate::{server::gitforge::tests::common /* server::gitforge::tests::common */};
use crate::{gitforge::tests::common /* server::gitforge::tests::common */};
use kxio::fs;

View file

@ -3,7 +3,7 @@ use std::ops::Deref;
use secrecy::ExposeSecret;
use tracing::{info, warn};
use crate::server::{
use crate::{
config::{BranchName, RepoDetails},
gitforge::{BranchResetError, BranchResetResult, Force, Repository},
types::GitRef,

View file

@ -1,4 +1,4 @@
use crate::server::config::{BranchName, GitDir};
use crate::config::{BranchName, GitDir};
#[derive(Debug)]
pub enum ForgeFileError {

View file

@ -2,7 +2,7 @@ use std::ops::Deref;
use tracing::{debug, info};
use crate::server::{config::RepoDetails, gitforge::Repository};
use crate::{config::RepoDetails, gitforge::Repository};
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum Error {

View file

@ -1,7 +1,7 @@
use kxio::network::{self, Network};
use tracing::error;
use crate::server::{
use crate::{
config::{BranchName, RepoDetails},
gitforge::{self, ForgeBranchError},
};

View file

@ -1,8 +1,7 @@
use kxio::network;
use tracing::{debug, error, info, warn};
use crate::server::{
self,
use crate::{
config::{BranchName, RepoConfig, RepoDetails},
gitforge::{self, ForgeLike},
};
@ -187,7 +186,7 @@ async fn get_commit_histories(
#[tracing::instrument(fields(%branch_name),skip_all)]
async fn get_commit_history(
repo_details: &server::config::RepoDetails,
repo_details: &crate::config::RepoDetails,
branch_name: &BranchName,
find_commits: Vec<gitforge::Commit>,
net: &kxio::network::Network,

View file

@ -1,7 +1,7 @@
use kxio::network::{self, Network};
use tracing::{error, warn};
use crate::server::{
use crate::{
config::{BranchName, RepoDetails},
gitforge::ForgeFileError,
};

View file

@ -8,7 +8,7 @@ use actix::prelude::*;
use kxio::network::{self, Network};
use tracing::{error, info, warn};
use crate::server::{
use crate::{
actors::repo::{RepoActor, StartMonitoring, ValidateRepo},
config::{BranchName, GitDir, RepoConfig, RepoDetails},
git,

View file

@ -1,4 +1,4 @@
use crate::server::{
use crate::{
actors::repo::RepoActor,
config::{BranchName, GitDir, RepoConfig},
gitforge::{self, RepoCloneError, Repository},

View file

@ -16,7 +16,7 @@ pub use types::*;
mod errors;
pub use errors::*;
use crate::server::{
use crate::{
config::{BranchName, GitDir, RepoConfig, RepoDetails},
types::{GitRef, MessageToken},
};

View file

@ -1,4 +1,4 @@
use crate::server::{
use crate::{
config::{
ApiToken, BranchName, ForgeDetails, ForgeName, ForgeType, GitDir, Hostname, RepoAlias,
RepoBranches, RepoConfig, RepoConfigSource, RepoDetails, RepoPath, User,

View file

@ -2,7 +2,7 @@ use assert2::let_assert;
use kxio::network::{MockNetwork, StatusCode};
use crate::server::{
use crate::{
config::{BranchName, ForgeType, RepoConfigSource},
types::ServerGeneration,
};

View file

@ -1,6 +1,6 @@
use std::{ops::Deref as _, path::PathBuf, sync::atomic::AtomicBool};
use crate::server::{
use crate::{
config::{BranchName, RepoDetails},
gitforge::RepoCloneError,
};
@ -16,7 +16,7 @@ impl Branch {
#[derive(Debug)]
pub enum Force {
No,
From(crate::server::types::GitRef),
From(crate::types::GitRef),
}
impl std::fmt::Display for Force {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -30,7 +30,7 @@ impl std::fmt::Display for Force {
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum BranchResetError {
Open(Box<gix::open::Error>),
Fetch(crate::server::gitforge::forgejo::branch::fetch::Error),
Fetch(crate::gitforge::forgejo::branch::fetch::Error),
Push,
}
impl std::error::Error for BranchResetError {}

View file

@ -6,18 +6,15 @@ pub mod types;
use actix::prelude::*;
use kxio::network::Network;
use kxio::{fs::FileSystem, network::Network};
use std::path::PathBuf;
use tracing::{error, info, level_filters::LevelFilter};
use crate::{
fs::FileSystem,
server::actors::{
use crate::actors::{
file_watcher::{self, FileUpdated},
server::Server,
},
};
pub fn init(fs: FileSystem) {
@ -33,7 +30,7 @@ pub fn init(fs: FileSystem) {
file_name
);
} else {
match fs.file_write(&pathbuf, include_str!("../../../../server-default.toml")) {
match fs.file_write(&pathbuf, include_str!("../../../server-default.toml")) {
Ok(_) => println!("Created a default configuration file at {}", file_name),
Err(e) => {
eprintln!("Failed to write to the configuration file: {}", e)

View file

@ -1,6 +1,6 @@
use std::fmt::Display;
use crate::server::{config::BranchName, gitforge};
use crate::{config::BranchName, gitforge};
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct GitRef(pub String);