From 943291daca5f4b140975cb83e16743c88f22bf0b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 22 May 2024 08:41:30 +0100 Subject: [PATCH] WIP: extract more crates --- Cargo.toml | 11 +++- README.md | 13 ++++ crates/config/Cargo.toml | 18 ++--- crates/gitforge/Cargo.toml | 64 ++++++++++++++++++ .../src/gitforge => gitforge/src}/errors.rs | 0 .../src}/forgejo/branch/get_all.rs | 0 .../src}/forgejo/branch/mod.rs | 0 .../src}/forgejo/branch/validate_positions.rs | 0 .../src}/forgejo/file/mod.rs | 0 .../gitforge => gitforge/src}/forgejo/mod.rs | 0 .../src/gitforge => gitforge/src}/github.rs | 0 .../gitforge/mod.rs => gitforge/src/lib.rs} | 0 .../gitforge => gitforge/src}/mock_forge.rs | 12 ++-- .../gitforge => gitforge/src}/tests/common.rs | 0 .../src}/tests/data-forgejo-branches-get.json | 0 .../src}/tests/forgejo.rs | 0 .../gitforge => gitforge/src}/tests/github.rs | 0 .../gitforge => gitforge/src}/tests/mod.rs | 0 .../src/gitforge => gitforge/src}/types.rs | 0 crates/repo-actor/Cargo.toml | 65 +++++++++++++++++++ .../actors/repo => repo-actor/src}/branch.rs | 0 .../actors/repo => repo-actor/src}/config.rs | 0 .../repo/mod.rs => repo-actor/src/lib.rs} | 4 +- .../actors/repo => repo-actor/src}/status.rs | 0 .../actors/repo => repo-actor/src}/tests.rs | 0 .../actors/repo => repo-actor/src}/webhook.rs | 0 crates/server/Cargo.toml | 2 + crates/server/src/actors/mod.rs | 1 - 28 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 crates/gitforge/Cargo.toml rename crates/{server/src/gitforge => gitforge/src}/errors.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/forgejo/branch/get_all.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/forgejo/branch/mod.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/forgejo/branch/validate_positions.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/forgejo/file/mod.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/forgejo/mod.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/github.rs (100%) rename crates/{server/src/gitforge/mod.rs => gitforge/src/lib.rs} (100%) rename crates/{server/src/gitforge => gitforge/src}/mock_forge.rs (80%) rename crates/{server/src/gitforge => gitforge/src}/tests/common.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/tests/data-forgejo-branches-get.json (100%) rename crates/{server/src/gitforge => gitforge/src}/tests/forgejo.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/tests/github.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/tests/mod.rs (100%) rename crates/{server/src/gitforge => gitforge/src}/types.rs (100%) create mode 100644 crates/repo-actor/Cargo.toml rename crates/{server/src/actors/repo => repo-actor/src}/branch.rs (100%) rename crates/{server/src/actors/repo => repo-actor/src}/config.rs (100%) rename crates/{server/src/actors/repo/mod.rs => repo-actor/src/lib.rs} (98%) rename crates/{server/src/actors/repo => repo-actor/src}/status.rs (100%) rename crates/{server/src/actors/repo => repo-actor/src}/tests.rs (100%) rename crates/{server/src/actors/repo => repo-actor/src}/webhook.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 7f991a6..e79f7d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,13 @@ [workspace] resolver = "2" -members = ["crates/cli", "crates/server", "crates/config", "crates/git"] +members = [ + "crates/cli", + "crates/server", + "crates/config", + "crates/git", + "crates/gitforge", + "crates/repo-actor", +] [workspace.package] version = "0.5.1" @@ -16,6 +23,8 @@ expect_used = "warn" git-next-server = { path = "crates/server" } git-next-config = { path = "crates/config" } git-next-git = { path = "crates/git" } +git-next-gitforge = { path = "crates/gitforge" } +git-next-repo-actor = { path = "crates/repo-actor" } # CLI parsing clap = { version = "4.5", features = ["cargo", "derive"] } diff --git a/README.md b/README.md index bde3241..de3ea25 100644 --- a/README.md +++ b/README.md @@ -190,9 +190,22 @@ The following diagram shows the dependency between the crates that make up `git- stateDiagram-v2 cli --> server cli --> git + server --> config server --> git + server --> gitforge + server --> repo_actor + git --> config + + gitforge --> config + gitforge --> git + + repo_actor --> config + repo_actor --> git + repo_actor --> gitforge + + ``` ## License diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index 53f7463..30d5810 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -9,9 +9,9 @@ forgejo = [] github = [] [dependencies] -# # logging +# logging # console-subscriber = { workspace = true } -# tracing = { workspace = true } +tracing = { workspace = true } # tracing-subscriber = { workspace = true } # # base64 decoding @@ -21,9 +21,9 @@ github = [] # # gix = { workspace = true } # gix = { workspace = true } # async-trait = { workspace = true } -# -# # fs/network -# kxio = { workspace = true } + +# fs/network +kxio = { workspace = true } # TOML parsing serde = { workspace = true } @@ -47,12 +47,12 @@ derive-with = { workspace = true } # # # file watcher # inotify = { workspace = true } -# -# # Actors -# actix = { workspace = true } + +# Actors +actix = { workspace = true } # actix-rt = { workspace = true } # tokio = { workspace = true } -# + [dev-dependencies] # # Testing assert2 = { workspace = true } diff --git a/crates/gitforge/Cargo.toml b/crates/gitforge/Cargo.toml new file mode 100644 index 0000000..b4736b8 --- /dev/null +++ b/crates/gitforge/Cargo.toml @@ -0,0 +1,64 @@ +[package] +name = "git-next-gitforge" +version = { workspace = true } +edition = { workspace = true } + +[features] +default = ["forgejo"] +forgejo = [] +github = [] + +[dependencies] +git-next-config = { workspace = true } +git-next-git = { workspace = true } + +# logging +console-subscriber = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { 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 } + +# Conventional Commit check +git-conventional = { workspace = true } + +# Webhooks +bytes = { workspace = true } +ulid = { workspace = true } +warp = { workspace = true } + +# boilerplate +derive_more = { workspace = true } + +# file watcher +inotify = { workspace = true } + +# Actors +actix = { workspace = true } +actix-rt = { workspace = true } +tokio = { workspace = true } + +[dev-dependencies] +# Testing +assert2 = { workspace = true } + +[lints.clippy] +nursery = { level = "warn", priority = -1 } +# pedantic = "warn" +unwrap_used = "warn" +expect_used = "warn" diff --git a/crates/server/src/gitforge/errors.rs b/crates/gitforge/src/errors.rs similarity index 100% rename from crates/server/src/gitforge/errors.rs rename to crates/gitforge/src/errors.rs diff --git a/crates/server/src/gitforge/forgejo/branch/get_all.rs b/crates/gitforge/src/forgejo/branch/get_all.rs similarity index 100% rename from crates/server/src/gitforge/forgejo/branch/get_all.rs rename to crates/gitforge/src/forgejo/branch/get_all.rs diff --git a/crates/server/src/gitforge/forgejo/branch/mod.rs b/crates/gitforge/src/forgejo/branch/mod.rs similarity index 100% rename from crates/server/src/gitforge/forgejo/branch/mod.rs rename to crates/gitforge/src/forgejo/branch/mod.rs diff --git a/crates/server/src/gitforge/forgejo/branch/validate_positions.rs b/crates/gitforge/src/forgejo/branch/validate_positions.rs similarity index 100% rename from crates/server/src/gitforge/forgejo/branch/validate_positions.rs rename to crates/gitforge/src/forgejo/branch/validate_positions.rs diff --git a/crates/server/src/gitforge/forgejo/file/mod.rs b/crates/gitforge/src/forgejo/file/mod.rs similarity index 100% rename from crates/server/src/gitforge/forgejo/file/mod.rs rename to crates/gitforge/src/forgejo/file/mod.rs diff --git a/crates/server/src/gitforge/forgejo/mod.rs b/crates/gitforge/src/forgejo/mod.rs similarity index 100% rename from crates/server/src/gitforge/forgejo/mod.rs rename to crates/gitforge/src/forgejo/mod.rs diff --git a/crates/server/src/gitforge/github.rs b/crates/gitforge/src/github.rs similarity index 100% rename from crates/server/src/gitforge/github.rs rename to crates/gitforge/src/github.rs diff --git a/crates/server/src/gitforge/mod.rs b/crates/gitforge/src/lib.rs similarity index 100% rename from crates/server/src/gitforge/mod.rs rename to crates/gitforge/src/lib.rs diff --git a/crates/server/src/gitforge/mock_forge.rs b/crates/gitforge/src/mock_forge.rs similarity index 80% rename from crates/server/src/gitforge/mock_forge.rs rename to crates/gitforge/src/mock_forge.rs index d9f6668..fa64f70 100644 --- a/crates/server/src/gitforge/mock_forge.rs +++ b/crates/gitforge/src/mock_forge.rs @@ -2,7 +2,9 @@ use git::OpenRepository; use git_next_config::{BranchName, GitDir, RepoConfig}; use git_next_git::{self as git, GitRef}; -use crate::{actors::repo::RepoActor, gitforge}; +use crate::{ + actors::repo::RepoActor, CommitStatus, ForgeBranchError, ForgeFileError, MessageToken, +}; struct MockForge; #[derive(Clone, Debug)] @@ -18,7 +20,7 @@ impl super::ForgeLike for MockForgeEnv { "mock".to_string() } - async fn branches_get_all(&self) -> Result, gitforge::ForgeBranchError> { + async fn branches_get_all(&self) -> Result, ForgeBranchError> { todo!() } @@ -26,7 +28,7 @@ impl super::ForgeLike for MockForgeEnv { &self, _branch: &BranchName, _file_path: &str, - ) -> Result { + ) -> Result { todo!() } @@ -35,7 +37,7 @@ impl super::ForgeLike for MockForgeEnv { _repository: OpenRepository, _repo_config: RepoConfig, _addr: actix::prelude::Addr, - _message_token: gitforge::MessageToken, + _message_token: MessageToken, ) { todo!() } @@ -50,7 +52,7 @@ impl super::ForgeLike for MockForgeEnv { todo!() } - async fn commit_status(&self, _commit: &git::Commit) -> gitforge::CommitStatus { + async fn commit_status(&self, _commit: &git::Commit) -> CommitStatus { todo!() } diff --git a/crates/server/src/gitforge/tests/common.rs b/crates/gitforge/src/tests/common.rs similarity index 100% rename from crates/server/src/gitforge/tests/common.rs rename to crates/gitforge/src/tests/common.rs diff --git a/crates/server/src/gitforge/tests/data-forgejo-branches-get.json b/crates/gitforge/src/tests/data-forgejo-branches-get.json similarity index 100% rename from crates/server/src/gitforge/tests/data-forgejo-branches-get.json rename to crates/gitforge/src/tests/data-forgejo-branches-get.json diff --git a/crates/server/src/gitforge/tests/forgejo.rs b/crates/gitforge/src/tests/forgejo.rs similarity index 100% rename from crates/server/src/gitforge/tests/forgejo.rs rename to crates/gitforge/src/tests/forgejo.rs diff --git a/crates/server/src/gitforge/tests/github.rs b/crates/gitforge/src/tests/github.rs similarity index 100% rename from crates/server/src/gitforge/tests/github.rs rename to crates/gitforge/src/tests/github.rs diff --git a/crates/server/src/gitforge/tests/mod.rs b/crates/gitforge/src/tests/mod.rs similarity index 100% rename from crates/server/src/gitforge/tests/mod.rs rename to crates/gitforge/src/tests/mod.rs diff --git a/crates/server/src/gitforge/types.rs b/crates/gitforge/src/types.rs similarity index 100% rename from crates/server/src/gitforge/types.rs rename to crates/gitforge/src/types.rs diff --git a/crates/repo-actor/Cargo.toml b/crates/repo-actor/Cargo.toml new file mode 100644 index 0000000..304dcbf --- /dev/null +++ b/crates/repo-actor/Cargo.toml @@ -0,0 +1,65 @@ +[package] +name = "git-next-repo-actor" +version = { workspace = true } +edition = { workspace = true } + +[features] +default = ["forgejo"] +forgejo = [] +github = [] + +[dependencies] +git-next-config = { workspace = true } +git-next-git = { workspace = true } +git-next-gitforge = { workspace = true } + +# logging +console-subscriber = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { 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 } + +# Conventional Commit check +git-conventional = { workspace = true } + +# Webhooks +bytes = { workspace = true } +ulid = { workspace = true } +warp = { workspace = true } + +# boilerplate +derive_more = { workspace = true } + +# file watcher +inotify = { workspace = true } + +# Actors +actix = { workspace = true } +actix-rt = { workspace = true } +tokio = { workspace = true } + +[dev-dependencies] +# Testing +assert2 = { workspace = true } + +[lints.clippy] +nursery = { level = "warn", priority = -1 } +# pedantic = "warn" +unwrap_used = "warn" +expect_used = "warn" diff --git a/crates/server/src/actors/repo/branch.rs b/crates/repo-actor/src/branch.rs similarity index 100% rename from crates/server/src/actors/repo/branch.rs rename to crates/repo-actor/src/branch.rs diff --git a/crates/server/src/actors/repo/config.rs b/crates/repo-actor/src/config.rs similarity index 100% rename from crates/server/src/actors/repo/config.rs rename to crates/repo-actor/src/config.rs diff --git a/crates/server/src/actors/repo/mod.rs b/crates/repo-actor/src/lib.rs similarity index 98% rename from crates/server/src/actors/repo/mod.rs rename to crates/repo-actor/src/lib.rs index 68ba532..7ca19db 100644 --- a/crates/server/src/actors/repo/mod.rs +++ b/crates/repo-actor/src/lib.rs @@ -13,7 +13,9 @@ use git_next_git::{self as git, Generation, RepoDetails}; use kxio::network::Network; use tracing::{debug, info, warn, Instrument}; -use crate::{actors::repo::webhook::WebhookAuth, config::Webhook, gitforge}; +// use crate::{actors::repo::webhook::WebhookAuth, config::Webhook, gitforge}; + +use crate::webhook::WebhookAuth; use self::webhook::WebhookId; diff --git a/crates/server/src/actors/repo/status.rs b/crates/repo-actor/src/status.rs similarity index 100% rename from crates/server/src/actors/repo/status.rs rename to crates/repo-actor/src/status.rs diff --git a/crates/server/src/actors/repo/tests.rs b/crates/repo-actor/src/tests.rs similarity index 100% rename from crates/server/src/actors/repo/tests.rs rename to crates/repo-actor/src/tests.rs diff --git a/crates/server/src/actors/repo/webhook.rs b/crates/repo-actor/src/webhook.rs similarity index 100% rename from crates/server/src/actors/repo/webhook.rs rename to crates/repo-actor/src/webhook.rs diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index 56187d4..a6baf18 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -11,6 +11,8 @@ github = [] [dependencies] git-next-config = { workspace = true } git-next-git = { workspace = true } +git-next-gitforge = { workspace = true } +git-next-repo-actor = { workspace = true } # logging console-subscriber = { workspace = true } diff --git a/crates/server/src/actors/mod.rs b/crates/server/src/actors/mod.rs index 92309df..2fd2c6f 100644 --- a/crates/server/src/actors/mod.rs +++ b/crates/server/src/actors/mod.rs @@ -1,4 +1,3 @@ pub mod file_watcher; -pub mod repo; pub mod server; pub mod webhook;