From 2a50a44ed0d7716660add7a27644f20fd4c7b08f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 25 Jul 2024 09:02:43 +0100 Subject: [PATCH] refactor: merge config crate into core crate --- crates/cli/Cargo.toml | 1 + crates/cli/src/init.rs | 1 + crates/cli/src/main.rs | 3 +- crates/config/Cargo.toml | 35 +---- crates/config/README.md | 2 + crates/config/src/lib.rs | 52 +------ crates/config/src/registered_webhook.rs | 16 --- crates/core/Cargo.toml | 27 ++++ .../src => core/src/config}/api_token.rs | 0 .../src => core/src/config}/branch_name.rs | 0 .../{config/src => core/src/config}/common.rs | 2 +- .../src => core/src/config}/forge_alias.rs | 0 .../src => core/src/config}/forge_config.rs | 2 +- .../src => core/src/config}/forge_details.rs | 2 +- .../src => core/src/config}/forge_type.rs | 0 .../src => core/src/config}/git_dir.rs | 0 .../src => core/src/config}/host_name.rs | 0 crates/core/src/config/mod.rs | 49 +++++++ crates/core/src/config/registered_webhook.rs | 16 +++ .../src => core/src/config}/remote_url.rs | 0 .../src => core/src/config}/repo_alias.rs | 0 .../src => core/src/config}/repo_branches.rs | 2 +- .../src => core/src/config}/repo_config.rs | 3 +- .../src/config}/repo_config_source.rs | 0 .../src => core/src/config}/repo_path.rs | 0 .../{config/src => core/src/config}/server.rs | 5 +- .../src/config}/server_repo_config.rs | 8 +- .../{config/src => core/src/config}/tests.rs | 0 .../src => core/src/config}/tests/url.rs | 0 .../{config/src => core/src/config}/user.rs | 0 .../src => core/src/config}/webhook.rs | 0 .../src => core/src/config}/webhook/auth.rs | 4 +- .../src/config}/webhook/forge_notification.rs | 14 +- .../src => core/src/config}/webhook/id.rs | 0 .../src => core/src/config}/webhook/push.rs | 7 +- .../src => core/src/config}/webhook/tests.rs | 0 crates/core/src/lib.rs | 3 + crates/core/src/macros/message.rs | 8 +- crates/core/src/macros/mod.rs | 1 + .../src => core/src/macros}/newtype.rs | 0 crates/forge-forgejo/Cargo.toml | 2 +- crates/forge-forgejo/src/lib.rs | 29 ++-- crates/forge-forgejo/src/tests.rs | 126 +++++++---------- crates/forge-forgejo/src/webhook/list.rs | 9 +- crates/forge-forgejo/src/webhook/mod.rs | 11 +- crates/forge-forgejo/src/webhook/parse.rs | 7 +- crates/forge-forgejo/src/webhook/register.rs | 13 +- .../forge-forgejo/src/webhook/unregister.rs | 4 +- crates/forge-github/Cargo.toml | 2 +- crates/forge-github/src/lib.rs | 37 +++-- crates/forge-github/src/tests/mod.rs | 78 ++++------- crates/forge-github/src/webhook/authorised.rs | 11 +- crates/forge-github/src/webhook/list.rs | 9 +- crates/forge-github/src/webhook/mod.rs | 8 +- crates/forge-github/src/webhook/parse.rs | 7 +- crates/forge-github/src/webhook/register.rs | 12 +- crates/forge-github/src/webhook/unregister.rs | 5 +- crates/forge/Cargo.toml | 2 +- crates/forge/src/lib.rs | 11 +- crates/forge/src/tests.rs | 20 +-- crates/git/Cargo.toml | 22 +-- crates/git/src/commit.rs | 18 +-- crates/git/src/common.rs | 2 +- crates/git/src/forge/like.rs | 32 ++--- crates/git/src/generation.rs | 2 +- crates/git/src/git_ref.rs | 12 +- crates/git/src/git_remote.rs | 7 +- crates/git/src/lib.rs | 2 +- crates/git/src/push.rs | 12 +- crates/git/src/repo_details.rs | 23 +-- crates/git/src/repository/factory.rs | 14 +- crates/git/src/repository/mod.rs | 24 ++-- crates/git/src/repository/open/mod.rs | 27 ++-- crates/git/src/repository/open/oreal.rs | 26 ++-- crates/git/src/repository/open/otest.rs | 48 +++---- .../src/repository/open/tests/commit_log.rs | 16 +-- crates/git/src/repository/open/tests/fetch.rs | 6 +- .../open/tests/find_default_remote.rs | 3 +- .../src/repository/open/tests/forge_config.rs | 46 +++--- crates/git/src/repository/open/tests/mod.rs | 20 +-- .../src/repository/open/tests/read_file.rs | 11 +- .../src/repository/open/tests/repo_config.rs | 20 ++- .../open/tests/server_repo_config.rs | 23 ++- crates/git/src/repository/test.rs | 26 ++-- crates/git/src/repository/tests/factory.rs | 5 +- crates/git/src/repository/tests/mod.rs | 5 +- crates/git/src/tests.rs | 132 ++++++------------ crates/git/src/user_notification.rs | 4 +- crates/git/src/validation/positions.rs | 22 +-- crates/git/src/validation/remotes.rs | 9 +- crates/git/src/validation/tests.rs | 57 ++++---- crates/repo-actor/Cargo.toml | 1 - crates/repo-actor/src/branch.rs | 12 +- .../repo-actor/src/handlers/advance_main.rs | 5 +- .../src/handlers/webhook_notification.rs | 5 +- crates/repo-actor/src/lib.rs | 42 +++--- crates/repo-actor/src/load.rs | 26 ++-- crates/repo-actor/src/messages.rs | 21 +-- crates/repo-actor/src/tests/expect.rs | 5 +- crates/repo-actor/src/tests/given.rs | 22 ++- .../src/tests/handlers/advance_main.rs | 4 +- crates/repo-actor/src/tests/mod.rs | 37 +++-- crates/repo-actor/src/tests/when.rs | 2 - crates/server-actor/Cargo.toml | 1 - .../server-actor/src/handlers/file_updated.rs | 3 +- .../server-actor/src/handlers/notify_user.rs | 7 +- crates/server-actor/src/lib.rs | 24 ++-- crates/server-actor/src/messages.rs | 8 +- .../src/tests/receive_server_config.rs | 6 +- crates/server/Cargo.toml | 3 +- crates/server/src/lib.rs | 6 +- crates/webhook-actor/Cargo.toml | 1 - crates/webhook-actor/src/router.rs | 9 +- crates/webhook-actor/src/server.rs | 13 +- 114 files changed, 740 insertions(+), 865 deletions(-) delete mode 100644 crates/config/src/registered_webhook.rs rename crates/{config/src => core/src/config}/api_token.rs (100%) rename crates/{config/src => core/src/config}/branch_name.rs (100%) rename crates/{config/src => core/src/config}/common.rs (98%) rename crates/{config/src => core/src/config}/forge_alias.rs (100%) rename crates/{config/src => core/src/config}/forge_config.rs (93%) rename crates/{config/src => core/src/config}/forge_details.rs (92%) rename crates/{config/src => core/src/config}/forge_type.rs (100%) rename crates/{config/src => core/src/config}/git_dir.rs (100%) rename crates/{config/src => core/src/config}/host_name.rs (100%) create mode 100644 crates/core/src/config/mod.rs create mode 100644 crates/core/src/config/registered_webhook.rs rename crates/{config/src => core/src/config}/remote_url.rs (100%) rename crates/{config/src => core/src/config}/repo_alias.rs (100%) rename crates/{config/src => core/src/config}/repo_branches.rs (95%) rename crates/{config/src => core/src/config}/repo_config.rs (93%) rename crates/{config/src => core/src/config}/repo_config_source.rs (100%) rename crates/{config/src => core/src/config}/repo_path.rs (100%) rename crates/{config/src => core/src/config}/server.rs (98%) rename crates/{config/src => core/src/config}/server_repo_config.rs (87%) rename crates/{config/src => core/src/config}/tests.rs (100%) rename crates/{config/src => core/src/config}/tests/url.rs (100%) rename crates/{config/src => core/src/config}/user.rs (100%) rename crates/{config/src => core/src/config}/webhook.rs (100%) rename crates/{config/src => core/src/config}/webhook/auth.rs (82%) rename crates/{config/src => core/src/config}/webhook/forge_notification.rs (70%) rename crates/{config/src => core/src/config}/webhook/id.rs (100%) rename crates/{config/src => core/src/config}/webhook/push.rs (83%) rename crates/{config/src => core/src/config}/webhook/tests.rs (100%) rename crates/{config/src => core/src/macros}/newtype.rs (100%) diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 7927c62..757cc3c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -14,6 +14,7 @@ categories = { workspace = true } [dependencies] git-next-core = { workspace = true } git-next-server = { workspace = true } +git-next-git = { workspace = true } # CLI parsing clap = { workspace = true } diff --git a/crates/cli/src/init.rs b/crates/cli/src/init.rs index 915d5ef..4dfe4b6 100644 --- a/crates/cli/src/init.rs +++ b/crates/cli/src/init.rs @@ -1,3 +1,4 @@ +// use kxio::fs::FileSystem; pub fn run(fs: FileSystem) { diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 6741850..0d29330 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,3 +1,4 @@ +// mod init; #[cfg(test)] @@ -29,7 +30,7 @@ enum Server { fn main() { let fs = fs::new(PathBuf::default()); let net = Network::new_real(); - let repository_factory = git_next_server::repository_factory(); + let repository_factory = git_next_git::repository::factory::real(); let commands = Commands::parse(); match commands.command { diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index 3ed140a..8691407 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -4,7 +4,7 @@ version = { workspace = true } edition = { workspace = true } license = { workspace = true } repository = { workspace = true } -description = "Base types for git-next, the trunk-based development manager" +description = "[deprecated crate] Base types for git-next, the trunk-based development manager" [features] default = ["forgejo", "github"] @@ -12,39 +12,6 @@ forgejo = [] github = [] [dependencies] -# logging -tracing = { 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 } - -# Git -gix = { workspace = true } -git-url-parse = { workspace = true } - -# Webhooks -ulid = { workspace = true } - -# boilerplate -derive_more = { workspace = true } -derive-with = { workspace = true } -thiserror = { workspace = true } -pike = { workspace = true } - -[dev-dependencies] -# # Testing -assert2 = { workspace = true } -rand = { workspace = true } -pretty_assertions = { workspace = true } -test-log = { workspace = true } [lints.clippy] nursery = { level = "warn", priority = -1 } diff --git a/crates/config/README.md b/crates/config/README.md index ddc70e2..f12c15d 100644 --- a/crates/config/README.md +++ b/crates/config/README.md @@ -7,3 +7,5 @@ development workflows where each commit must pass CI before being included in the main branch. See [git-next](https://crates.io/crates/git-next) for more information. + +N.B. this crate has been merged into [git-next-core](https://crates.io/crates/git-next-core). diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 7f39a32..d32fd0c 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1,50 +1,2 @@ -// -mod api_token; -mod branch_name; -pub mod common; -mod forge_alias; -mod forge_config; -mod forge_details; -mod forge_type; -pub mod git_dir; -mod host_name; -mod newtype; -mod registered_webhook; -mod remote_url; -mod repo_alias; -mod repo_branches; -mod repo_config; -mod repo_config_source; -mod repo_path; -pub mod server; -mod server_repo_config; -mod user; -pub mod webhook; - -#[cfg(test)] -mod tests; - -pub use api_token::ApiToken; -pub use branch_name::BranchName; -pub use forge_alias::ForgeAlias; -pub use forge_config::ForgeConfig; -pub use forge_details::ForgeDetails; -pub use forge_type::ForgeType; -pub use git_dir::GitDir; -pub use git_dir::StoragePathType; -pub use host_name::Hostname; -pub use registered_webhook::RegisteredWebhook; -pub use remote_url::RemoteUrl; -pub use repo_alias::RepoAlias; -pub use repo_branches::RepoBranches; -pub use repo_config::RepoConfig; -pub use repo_config_source::RepoConfigSource; -pub use repo_path::RepoPath; -pub use server_repo_config::ServerRepoConfig; -pub use user::User; -pub use webhook::auth::WebhookAuth; -pub use webhook::forge_notification::ForgeNotification; -pub use webhook::id::WebhookId; - -// re-export -pub use pike::{pike, pike_opt, pike_res}; +// moved to crates/core/src/config/ +// moved newtype to crates/core/src/macros/ diff --git a/crates/config/src/registered_webhook.rs b/crates/config/src/registered_webhook.rs deleted file mode 100644 index 171e75d..0000000 --- a/crates/config/src/registered_webhook.rs +++ /dev/null @@ -1,16 +0,0 @@ -// -use crate as config; - -#[derive(Debug, derive_more::Constructor)] -pub struct RegisteredWebhook { - id: config::WebhookId, - auth: config::WebhookAuth, -} -impl RegisteredWebhook { - pub const fn id(&self) -> &config::WebhookId { - &self.id - } - pub const fn auth(&self) -> &config::WebhookAuth { - &self.auth - } -} diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 1328984..91f1c79 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -6,6 +6,11 @@ license = { workspace = true } repository = { workspace = true } description = "core for git-next, the trunk-based development manager" +[features] +default = ["forgejo", "github"] +forgejo = [] +github = [] + [dependencies] # logging console-subscriber = { workspace = true } @@ -19,9 +24,31 @@ kxio = { workspace = true } actix = { workspace = true } actix-rt = { workspace = true } +# TOML parsing +serde = { workspace = true } +toml = { workspace = true } + +# Secrets and Password +secrecy = { workspace = true } + +# Git +gix = { workspace = true } +git-url-parse = { workspace = true } + +# Webhooks +ulid = { workspace = true } + +# boilerplate +derive_more = { workspace = true } +derive-with = { workspace = true } +thiserror = { workspace = true } +pike = { workspace = true } + [dev-dependencies] # Testing assert2 = { workspace = true } +rand = { workspace = true } +test-log = { workspace = true } [lints.clippy] nursery = { level = "warn", priority = -1 } diff --git a/crates/config/src/api_token.rs b/crates/core/src/config/api_token.rs similarity index 100% rename from crates/config/src/api_token.rs rename to crates/core/src/config/api_token.rs diff --git a/crates/config/src/branch_name.rs b/crates/core/src/config/branch_name.rs similarity index 100% rename from crates/config/src/branch_name.rs rename to crates/core/src/config/branch_name.rs diff --git a/crates/config/src/common.rs b/crates/core/src/config/common.rs similarity index 98% rename from crates/config/src/common.rs rename to crates/core/src/config/common.rs index fc3f5eb..049dd70 100644 --- a/crates/config/src/common.rs +++ b/crates/core/src/config/common.rs @@ -1,4 +1,4 @@ -use crate::{ +use crate::config::{ ApiToken, BranchName, ForgeAlias, ForgeDetails, ForgeType, Hostname, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, RepoPath, User, }; diff --git a/crates/config/src/forge_alias.rs b/crates/core/src/config/forge_alias.rs similarity index 100% rename from crates/config/src/forge_alias.rs rename to crates/core/src/config/forge_alias.rs diff --git a/crates/config/src/forge_config.rs b/crates/core/src/config/forge_config.rs similarity index 93% rename from crates/config/src/forge_config.rs rename to crates/core/src/config/forge_config.rs index eae2d45..75dff39 100644 --- a/crates/config/src/forge_config.rs +++ b/crates/core/src/config/forge_config.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use crate::{ApiToken, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User}; +use crate::config::{ApiToken, ForgeType, Hostname, RepoAlias, ServerRepoConfig, User}; /// Defines a Forge to connect to /// Maps from `git-next-server.toml` at `forge.{forge}` diff --git a/crates/config/src/forge_details.rs b/crates/core/src/config/forge_details.rs similarity index 92% rename from crates/config/src/forge_details.rs rename to crates/core/src/config/forge_details.rs index c626f83..a1c1716 100644 --- a/crates/config/src/forge_details.rs +++ b/crates/core/src/config/forge_details.rs @@ -1,4 +1,4 @@ -use crate::{ApiToken, ForgeAlias, ForgeConfig, ForgeType, Hostname, User}; +use crate::config::{ApiToken, ForgeAlias, ForgeConfig, ForgeType, Hostname, User}; /// The derived information about a Forge, used to create interactions with it #[derive(Clone, Default, Debug, derive_more::Constructor, derive_with::With)] diff --git a/crates/config/src/forge_type.rs b/crates/core/src/config/forge_type.rs similarity index 100% rename from crates/config/src/forge_type.rs rename to crates/core/src/config/forge_type.rs diff --git a/crates/config/src/git_dir.rs b/crates/core/src/config/git_dir.rs similarity index 100% rename from crates/config/src/git_dir.rs rename to crates/core/src/config/git_dir.rs diff --git a/crates/config/src/host_name.rs b/crates/core/src/config/host_name.rs similarity index 100% rename from crates/config/src/host_name.rs rename to crates/core/src/config/host_name.rs diff --git a/crates/core/src/config/mod.rs b/crates/core/src/config/mod.rs new file mode 100644 index 0000000..70411a8 --- /dev/null +++ b/crates/core/src/config/mod.rs @@ -0,0 +1,49 @@ +// +mod api_token; +mod branch_name; +pub mod common; +mod forge_alias; +mod forge_config; +mod forge_details; +mod forge_type; +pub mod git_dir; +mod host_name; +mod registered_webhook; +mod remote_url; +mod repo_alias; +mod repo_branches; +mod repo_config; +mod repo_config_source; +mod repo_path; +pub mod server; +mod server_repo_config; +mod user; +pub mod webhook; + +#[cfg(test)] +mod tests; + +pub use api_token::ApiToken; +pub use branch_name::BranchName; +pub use forge_alias::ForgeAlias; +pub use forge_config::ForgeConfig; +pub use forge_details::ForgeDetails; +pub use forge_type::ForgeType; +pub use git_dir::GitDir; +pub use git_dir::StoragePathType; +pub use host_name::Hostname; +pub use registered_webhook::RegisteredWebhook; +pub use remote_url::RemoteUrl; +pub use repo_alias::RepoAlias; +pub use repo_branches::RepoBranches; +pub use repo_config::RepoConfig; +pub use repo_config_source::RepoConfigSource; +pub use repo_path::RepoPath; +pub use server_repo_config::ServerRepoConfig; +pub use user::User; +pub use webhook::auth::WebhookAuth; +pub use webhook::forge_notification::ForgeNotification; +pub use webhook::id::WebhookId; + +// re-export +pub use pike::{pike, pike_opt, pike_res}; diff --git a/crates/core/src/config/registered_webhook.rs b/crates/core/src/config/registered_webhook.rs new file mode 100644 index 0000000..31427cb --- /dev/null +++ b/crates/core/src/config/registered_webhook.rs @@ -0,0 +1,16 @@ +// +use crate::config::{WebhookAuth, WebhookId}; + +#[derive(Debug, derive_more::Constructor)] +pub struct RegisteredWebhook { + id: WebhookId, + auth: WebhookAuth, +} +impl RegisteredWebhook { + pub const fn id(&self) -> &WebhookId { + &self.id + } + pub const fn auth(&self) -> &WebhookAuth { + &self.auth + } +} diff --git a/crates/config/src/remote_url.rs b/crates/core/src/config/remote_url.rs similarity index 100% rename from crates/config/src/remote_url.rs rename to crates/core/src/config/remote_url.rs diff --git a/crates/config/src/repo_alias.rs b/crates/core/src/config/repo_alias.rs similarity index 100% rename from crates/config/src/repo_alias.rs rename to crates/core/src/config/repo_alias.rs diff --git a/crates/config/src/repo_branches.rs b/crates/core/src/config/repo_branches.rs similarity index 95% rename from crates/config/src/repo_branches.rs rename to crates/core/src/config/repo_branches.rs index 7851370..0eed541 100644 --- a/crates/config/src/repo_branches.rs +++ b/crates/core/src/config/repo_branches.rs @@ -1,4 +1,4 @@ -use crate::BranchName; +use crate::config::BranchName; /// Mapped from `.git-next.toml` file at `branches` #[derive( diff --git a/crates/config/src/repo_config.rs b/crates/core/src/config/repo_config.rs similarity index 93% rename from crates/config/src/repo_config.rs rename to crates/core/src/config/repo_config.rs index db86a7e..e522959 100644 --- a/crates/config/src/repo_config.rs +++ b/crates/core/src/config/repo_config.rs @@ -1,5 +1,4 @@ -use crate::RepoBranches; -use crate::RepoConfigSource; +use crate::config::{RepoBranches, RepoConfigSource}; /// Mapped from `.git-next.toml` file in target repo /// Is also derived from the optional parameters in `git-next-server.toml` at diff --git a/crates/config/src/repo_config_source.rs b/crates/core/src/config/repo_config_source.rs similarity index 100% rename from crates/config/src/repo_config_source.rs rename to crates/core/src/config/repo_config_source.rs diff --git a/crates/config/src/repo_path.rs b/crates/core/src/config/repo_path.rs similarity index 100% rename from crates/config/src/repo_path.rs rename to crates/core/src/config/repo_path.rs diff --git a/crates/config/src/server.rs b/crates/core/src/config/server.rs similarity index 98% rename from crates/config/src/server.rs rename to crates/core/src/config/server.rs index 199fd43..3708d18 100644 --- a/crates/config/src/server.rs +++ b/crates/core/src/config/server.rs @@ -11,7 +11,10 @@ use kxio::fs::FileSystem; use secrecy::Secret; use tracing::info; -use crate::{newtype, ForgeAlias, ForgeConfig, RepoAlias}; +use crate::{ + config::{ForgeAlias, ForgeConfig, RepoAlias}, + newtype, +}; #[derive(Debug, thiserror::Error)] pub enum Error { diff --git a/crates/config/src/server_repo_config.rs b/crates/core/src/config/server_repo_config.rs similarity index 87% rename from crates/config/src/server_repo_config.rs rename to crates/core/src/config/server_repo_config.rs index 5c3278d..cd70b9d 100644 --- a/crates/config/src/server_repo_config.rs +++ b/crates/core/src/config/server_repo_config.rs @@ -1,6 +1,10 @@ +// use std::path::PathBuf; -use crate::{BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, RepoPath}; +use crate::config::{ + git_dir::StoragePathType, BranchName, GitDir, RepoBranches, RepoConfig, RepoConfigSource, + RepoPath, +}; /// Defines a Repo within a ForgeConfig to be monitored by the server /// Maps from `git-next-server.toml` at `forge.{forge}.repos.{name}` @@ -38,7 +42,7 @@ impl ServerRepoConfig { self.gitdir .clone() // Provenance is external as the gitdir is only used to specify non-internal paths - .map(|dir| GitDir::new(dir, crate::git_dir::StoragePathType::External)) + .map(|dir| GitDir::new(dir, StoragePathType::External)) } /// Returns a RepoConfig from the server configuration if ALL THREE branches were provided diff --git a/crates/config/src/tests.rs b/crates/core/src/config/tests.rs similarity index 100% rename from crates/config/src/tests.rs rename to crates/core/src/config/tests.rs diff --git a/crates/config/src/tests/url.rs b/crates/core/src/config/tests/url.rs similarity index 100% rename from crates/config/src/tests/url.rs rename to crates/core/src/config/tests/url.rs diff --git a/crates/config/src/user.rs b/crates/core/src/config/user.rs similarity index 100% rename from crates/config/src/user.rs rename to crates/core/src/config/user.rs diff --git a/crates/config/src/webhook.rs b/crates/core/src/config/webhook.rs similarity index 100% rename from crates/config/src/webhook.rs rename to crates/core/src/config/webhook.rs diff --git a/crates/config/src/webhook/auth.rs b/crates/core/src/config/webhook/auth.rs similarity index 82% rename from crates/config/src/webhook/auth.rs rename to crates/core/src/config/webhook/auth.rs index c1768b6..f6306c8 100644 --- a/crates/config/src/webhook/auth.rs +++ b/crates/core/src/config/webhook/auth.rs @@ -1,5 +1,7 @@ // -crate::newtype!(WebhookAuth: ulid::Ulid, derive_more::Display: r#"The unique token authorisation for the webhook. +use crate::newtype; + +newtype!(WebhookAuth: ulid::Ulid, derive_more::Display: r#"The unique token authorisation for the webhook. Each monitored repository has it's own unique token, and it is different each time `git-next` runs."#); impl WebhookAuth { diff --git a/crates/config/src/webhook/forge_notification.rs b/crates/core/src/config/webhook/forge_notification.rs similarity index 70% rename from crates/config/src/webhook/forge_notification.rs rename to crates/core/src/config/webhook/forge_notification.rs index 6fda1fe..81bcbd1 100644 --- a/crates/config/src/webhook/forge_notification.rs +++ b/crates/core/src/config/webhook/forge_notification.rs @@ -1,21 +1,23 @@ // -use crate as config; +use crate::config::{ForgeAlias, RepoAlias}; + +use derive_more::Constructor; use std::collections::BTreeMap; /// A notification receive from a Forge, typically via a Webhook. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Constructor)] pub struct ForgeNotification { - forge_alias: config::ForgeAlias, - repo_alias: config::RepoAlias, + forge_alias: ForgeAlias, + repo_alias: RepoAlias, headers: BTreeMap, body: Body, } impl ForgeNotification { - pub const fn forge_alias(&self) -> &config::ForgeAlias { + pub const fn forge_alias(&self) -> &ForgeAlias { &self.forge_alias } - pub const fn repo_alias(&self) -> &config::RepoAlias { + pub const fn repo_alias(&self) -> &RepoAlias { &self.repo_alias } pub const fn body(&self) -> &Body { @@ -26,7 +28,7 @@ impl ForgeNotification { } } -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Constructor)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Constructor)] pub struct Body(String); impl Body { pub fn as_str(&self) -> &str { diff --git a/crates/config/src/webhook/id.rs b/crates/core/src/config/webhook/id.rs similarity index 100% rename from crates/config/src/webhook/id.rs rename to crates/core/src/config/webhook/id.rs diff --git a/crates/config/src/webhook/push.rs b/crates/core/src/config/webhook/push.rs similarity index 83% rename from crates/config/src/webhook/push.rs rename to crates/core/src/config/webhook/push.rs index a1eaeb2..55202e8 100644 --- a/crates/config/src/webhook/push.rs +++ b/crates/core/src/config/webhook/push.rs @@ -1,16 +1,15 @@ // -use crate as config; - +use crate::config::{BranchName, RepoBranches}; use derive_more::Constructor; #[derive(Debug, Constructor, derive_with::With)] pub struct Push { - branch: config::BranchName, + branch: BranchName, sha: String, message: String, } impl Push { - pub fn branch(&self, repo_branches: &crate::RepoBranches) -> Option { + pub fn branch(&self, repo_branches: &RepoBranches) -> Option { if self.branch == repo_branches.main() { return Some(Branch::Main); } diff --git a/crates/config/src/webhook/tests.rs b/crates/core/src/config/webhook/tests.rs similarity index 100% rename from crates/config/src/webhook/tests.rs rename to crates/core/src/config/webhook/tests.rs diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 992f6dd..05df97e 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1 +1,4 @@ +mod config; mod macros; + +pub use config::*; diff --git a/crates/core/src/macros/message.rs b/crates/core/src/macros/message.rs index 7056e84..e1df53c 100644 --- a/crates/core/src/macros/message.rs +++ b/crates/core/src/macros/message.rs @@ -1,25 +1,25 @@ #[macro_export] macro_rules! message { ($name:ident: $value:ty: $docs:literal) => { - git_next_config::newtype!($name: $value: $docs); + git_next_core::newtype!($name: $value: $docs); impl actix::prelude::Message for $name { type Result = (); } }; ($name:ident: $docs:literal) => { - git_next_config::newtype!($name: $docs); + git_next_core::newtype!($name: $docs); impl actix::prelude::Message for $name { type Result = (); } }; ($name:ident: $value:ty => $result:ty: $docs:literal) => { - git_next_config::newtype!($name is a $value: $docs); + git_next_core::newtype!($name is a $value: $docs); impl actix::prelude::Message for $name { type Result = $result; } }; ($name:ident => $result:ty: $docs:literal) => { - git_next_config::newtype!($name: $docs); + git_next_core::newtype!($name: $docs); impl actix::prelude::Message for $name { type Result = $result; } diff --git a/crates/core/src/macros/mod.rs b/crates/core/src/macros/mod.rs index e935b02..23efb2a 100644 --- a/crates/core/src/macros/mod.rs +++ b/crates/core/src/macros/mod.rs @@ -1 +1,2 @@ mod message; +mod newtype; diff --git a/crates/config/src/newtype.rs b/crates/core/src/macros/newtype.rs similarity index 100% rename from crates/config/src/newtype.rs rename to crates/core/src/macros/newtype.rs diff --git a/crates/forge-forgejo/Cargo.toml b/crates/forge-forgejo/Cargo.toml index 43f07ba..f6e3edc 100644 --- a/crates/forge-forgejo/Cargo.toml +++ b/crates/forge-forgejo/Cargo.toml @@ -7,7 +7,7 @@ repository = { workspace = true } description = "Forgejo support for git-next, the trunk-based development manager" [dependencies] -git-next-config = { workspace = true } +git-next-core = { workspace = true } git-next-git = { workspace = true } # logging diff --git a/crates/forge-forgejo/src/lib.rs b/crates/forge-forgejo/src/lib.rs index 4370ca0..c2c22e8 100644 --- a/crates/forge-forgejo/src/lib.rs +++ b/crates/forge-forgejo/src/lib.rs @@ -5,7 +5,9 @@ mod tests; mod webhook; use git::forge::commit::Status; -use git_next_config as config; +use git_next_core::{ + self as core, server, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, +}; use git_next_git as git; use kxio::network::{self, Network}; @@ -30,24 +32,20 @@ impl git::ForgeLike for ForgeJo { "forgejo".to_string() } - fn is_message_authorised( - &self, - msg: &config::ForgeNotification, - expected: &config::WebhookAuth, - ) -> bool { + fn is_message_authorised(&self, msg: &ForgeNotification, expected: &WebhookAuth) -> bool { let authorization = msg.header("authorization"); tracing::info!(?authorization, %expected, "is message authorised?"); authorization .and_then(|header| header.strip_prefix("Basic ").map(|v| v.to_owned())) - .and_then(|value| config::WebhookAuth::try_new(value.as_str()).ok()) + .and_then(|value| WebhookAuth::try_new(value.as_str()).ok()) .map(|auth| &auth == expected) .unwrap_or(false) } fn parse_webhook_body( &self, - body: &config::webhook::forge_notification::Body, - ) -> git::forge::webhook::Result { + body: &core::webhook::forge_notification::Body, + ) -> git::forge::webhook::Result { webhook::parse_body(body) } @@ -96,22 +94,19 @@ impl git::ForgeLike for ForgeJo { async fn list_webhooks( &self, - webhook_url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result> { + webhook_url: &server::WebhookUrl, + ) -> git::forge::webhook::Result> { webhook::list(&self.repo_details, webhook_url, &self.net).await } - async fn unregister_webhook( - &self, - webhook_id: &config::WebhookId, - ) -> git::forge::webhook::Result<()> { + async fn unregister_webhook(&self, webhook_id: &WebhookId) -> git::forge::webhook::Result<()> { webhook::unregister(webhook_id, &self.repo_details, &self.net).await } async fn register_webhook( &self, - webhook_url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result { + webhook_url: &server::WebhookUrl, + ) -> git::forge::webhook::Result { webhook::register(&self.repo_details, webhook_url, &self.net).await } } diff --git a/crates/forge-forgejo/src/tests.rs b/crates/forge-forgejo/src/tests.rs index 2feeef3..4d21593 100644 --- a/crates/forge-forgejo/src/tests.rs +++ b/crates/forge-forgejo/src/tests.rs @@ -1,15 +1,23 @@ // -use git_next_config as config; -use git_next_git as git; +use crate::ForgeJo; +use git_next_core::{ + server::{InboundWebhook, WebhookUrl}, + BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, Hostname, RepoAlias, + RepoBranches, RepoPath, ServerRepoConfig, StoragePathType, WebhookAuth, WebhookId, +}; +use git_next_git::{self as git, forge::commit::Status, ForgeLike as _}; + +use assert2::let_assert; +use kxio::network::{self, MockNetwork, StatusCode}; +use secrecy::ExposeSecret; +use serde::Serialize; +use serde_json::json; + +use std::collections::BTreeMap; mod forgejo { use super::*; - use assert2::let_assert; - - use crate::ForgeJo; - use git::ForgeLike as _; - #[test] fn should_return_name() { let fs = given::a_filesystem(); @@ -65,8 +73,6 @@ mod forgejo { mod parse_webhook_body { - use serde_json::json; - use super::*; #[test] @@ -77,7 +83,7 @@ mod forgejo { let next = repo_branches.next(); let sha = given::a_name(); let message = given::a_name(); - let body = config::webhook::forge_notification::Body::new( + let body = git_next_core::webhook::forge_notification::Body::new( json!({"ref":format!("refs/heads/{next}"),"after":sha,"head_commit":{"message":message}}) .to_string(), ); @@ -86,7 +92,7 @@ mod forgejo { assert_eq!(push.message(), message); assert_eq!( push.branch(&repo_branches), - Some(config::webhook::push::Branch::Next) + Some(git_next_core::webhook::push::Branch::Next) ); } @@ -94,15 +100,14 @@ mod forgejo { fn should_error_invalid_body() { let fs = given::a_filesystem(); let forge = given::a_forgejo_forge(&given::repo_details(&fs), given::a_network()); - let body = - config::webhook::forge_notification::Body::new(r#"{"type":"invalid"}"#.to_string()); + let body = git_next_core::webhook::forge_notification::Body::new( + r#"{"type":"invalid"}"#.to_string(), + ); let_assert!(Err(_) = forge.parse_webhook_body(&body)); } } mod commit_status { - use git_next_git::forge::commit::Status; - use kxio::network::StatusCode; use super::*; @@ -186,10 +191,6 @@ mod forgejo { } mod list_webhooks { - use git_next_config::WebhookId; - use git_next_git::ForgeLike as _; - - use crate::tests::forgejo::with; use super::*; @@ -200,7 +201,6 @@ mod forgejo { let webhook_url = given::any_webhook_url(); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let hook_id_1 = given::a_forgejo_webhook_id(); let hook_id_2 = given::a_forgejo_webhook_id(); @@ -245,7 +245,6 @@ mod forgejo { let webhook_url = given::a_webhook_url(&given::a_forge_alias(), &given::a_repo_alias()); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let mut net = given::a_network(); @@ -263,8 +262,6 @@ mod forgejo { mod unregister_webhook { use super::*; - use git_next_git::ForgeLike; - use kxio::network::StatusCode; #[tokio::test] async fn should_delete_webhook() { @@ -272,7 +269,6 @@ mod forgejo { let repo_details = given::repo_details(&fs); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let webhook_id = given::a_webhook_id(); let mut net = given::a_network(); @@ -297,7 +293,6 @@ mod forgejo { let repo_details = given::repo_details(&fs); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let webhook_id = given::a_webhook_id(); let mut net = given::a_network(); @@ -321,14 +316,8 @@ mod forgejo { } mod register_webhook { - use crate::tests::forgejo::with; - use super::*; - use git_next_config::WebhookId; - use kxio::network::StatusCode; - use serde_json::json; - #[tokio::test] async fn should_register_a_new_webhook() { let fs = given::a_filesystem(); @@ -341,7 +330,6 @@ mod forgejo { given::a_webhook_url(repo_details.forge.forge_alias(), &repo_details.repo_alias); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let mut net = given::a_network(); @@ -403,7 +391,6 @@ mod forgejo { given::a_webhook_url(repo_details.forge.forge_alias(), &repo_details.repo_alias); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let mut net = given::a_network(); @@ -456,7 +443,6 @@ mod forgejo { given::a_webhook_url(repo_details.forge.forge_alias(), &repo_details.repo_alias); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let mut net = given::a_network(); @@ -497,7 +483,6 @@ mod forgejo { given::a_webhook_url(repo_details.forge.forge_alias(), &repo_details.repo_alias); let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); let mut net = given::a_network(); @@ -526,11 +511,7 @@ mod forgejo { } } mod with { - use serde::Serialize; - use serde_json::json; - - use git_next_config::{server::WebhookUrl, Hostname, RepoPath}; - use kxio::network::{self, StatusCode}; + use super::*; pub fn get_webhooks_by_page( page: u8, @@ -589,11 +570,6 @@ mod forgejo { } mod given { - use std::collections::BTreeMap; - - use kxio::network::{MockNetwork, StatusCode}; - use serde_json::json; - use super::*; pub fn a_commit_state( @@ -616,7 +592,6 @@ mod forgejo { ) -> String { let hostname = repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; - use secrecy::ExposeSecret; let token = repo_details.forge.token().expose_secret(); format!( "https://{hostname}/api/v1/repos/{repo_path}/commits/{commit}/status?token={token}" @@ -624,15 +599,15 @@ mod forgejo { } pub enum Header { - Valid(config::WebhookAuth), + Valid(WebhookAuth), Missing, NonBasic, NonUlid, WrongUlid, } - pub fn a_webhook_message(header: Header) -> config::ForgeNotification { - config::ForgeNotification::new( + pub fn a_webhook_message(header: Header) -> ForgeNotification { + ForgeNotification::new( given::a_forge_alias(), given::a_repo_alias(), given::webhook_headers(header), @@ -656,7 +631,7 @@ mod forgejo { Header::WrongUlid => { headers.insert( "authorization".to_string(), - format!("Basic {}", config::WebhookAuth::generate()), + format!("Basic {}", WebhookAuth::generate()), ); } } @@ -675,38 +650,35 @@ mod forgejo { rand::thread_rng().next_u32().into() } - pub fn a_webhook_auth() -> config::WebhookAuth { - config::WebhookAuth::generate() + pub fn a_webhook_auth() -> WebhookAuth { + WebhookAuth::generate() } - pub fn a_webhook_message_body() -> config::webhook::forge_notification::Body { - config::webhook::forge_notification::Body::new(a_name()) + pub fn a_webhook_message_body() -> git_next_core::webhook::forge_notification::Body { + git_next_core::webhook::forge_notification::Body::new(a_name()) } - pub fn repo_branches() -> config::RepoBranches { - config::RepoBranches::new(a_name(), a_name(), a_name()) + pub fn repo_branches() -> RepoBranches { + RepoBranches::new(a_name(), a_name(), a_name()) } - pub fn a_forge_alias() -> config::ForgeAlias { - config::ForgeAlias::new(a_name()) + pub fn a_forge_alias() -> ForgeAlias { + ForgeAlias::new(a_name()) } - pub fn a_repo_alias() -> config::RepoAlias { - config::RepoAlias::new(a_name()) + pub fn a_repo_alias() -> RepoAlias { + RepoAlias::new(a_name()) } pub fn a_network() -> kxio::network::MockNetwork { kxio::network::MockNetwork::new() } - pub fn a_webhook_url( - forge_alias: &config::ForgeAlias, - repo_alias: &config::RepoAlias, - ) -> git_next_config::server::WebhookUrl { - config::server::InboundWebhook::new(a_name()).url(forge_alias, repo_alias) + pub fn a_webhook_url(forge_alias: &ForgeAlias, repo_alias: &RepoAlias) -> WebhookUrl { + InboundWebhook::new(a_name()).url(forge_alias, repo_alias) } - pub fn any_webhook_url() -> git_next_config::server::WebhookUrl { + pub fn any_webhook_url() -> WebhookUrl { a_webhook_url(&a_forge_alias(), &a_repo_alias()) } @@ -723,23 +695,23 @@ mod forgejo { generate(5) } - pub fn a_webhook_id() -> config::WebhookId { - config::WebhookId::new(a_name()) + pub fn a_webhook_id() -> WebhookId { + WebhookId::new(a_name()) } - pub fn a_branch_name() -> config::BranchName { - config::BranchName::new(a_name()) + pub fn a_branch_name() -> BranchName { + BranchName::new(a_name()) } - pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> config::GitDir { + pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> GitDir { let dir_name = a_name(); let dir = fs.base().join(dir_name); - config::GitDir::new(dir, config::git_dir::StoragePathType::Internal) + GitDir::new(dir, StoragePathType::Internal) } - pub fn a_forge_config() -> config::ForgeConfig { - config::ForgeConfig::new( - config::ForgeType::MockForge, + pub fn a_forge_config() -> ForgeConfig { + ForgeConfig::new( + ForgeType::MockForge, a_name(), a_name(), a_name(), @@ -747,11 +719,11 @@ mod forgejo { ) } - pub fn a_server_repo_config() -> config::ServerRepoConfig { + pub fn a_server_repo_config() -> ServerRepoConfig { let main = a_branch_name().unwrap(); let next = a_branch_name().unwrap(); let dev = a_branch_name().unwrap(); - config::ServerRepoConfig::new( + ServerRepoConfig::new( format!("{}/{}", a_name(), a_name()), main.clone(), None, diff --git a/crates/forge-forgejo/src/webhook/list.rs b/crates/forge-forgejo/src/webhook/list.rs index 614fc9d..3135c1e 100644 --- a/crates/forge-forgejo/src/webhook/list.rs +++ b/crates/forge-forgejo/src/webhook/list.rs @@ -1,16 +1,17 @@ // -use git_next_config as config; +use git_next_core::{server::WebhookUrl, WebhookId}; use git_next_git as git; + use kxio::network; use crate::webhook::Hook; pub async fn list( repo_details: &git::RepoDetails, - webhook_url: &config::server::WebhookUrl, + webhook_url: &WebhookUrl, net: &network::Network, -) -> git::forge::webhook::Result> { - let mut ids: Vec = vec![]; +) -> git::forge::webhook::Result> { + let mut ids: Vec = vec![]; let hostname = &repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; let mut page = 1; diff --git a/crates/forge-forgejo/src/webhook/mod.rs b/crates/forge-forgejo/src/webhook/mod.rs index 701d240..cb216ae 100644 --- a/crates/forge-forgejo/src/webhook/mod.rs +++ b/crates/forge-forgejo/src/webhook/mod.rs @@ -1,6 +1,7 @@ // -use git_next_config as config; +use git_next_core::{webhook, BranchName, WebhookId}; use git_next_git as git; + use std::collections::HashMap; mod list; @@ -19,8 +20,8 @@ struct Hook { config: HashMap, } impl Hook { - fn id(&self) -> config::WebhookId { - config::WebhookId::new(format!("{}", self.id)) + fn id(&self) -> WebhookId { + WebhookId::new(format!("{}", self.id)) } } @@ -32,14 +33,14 @@ pub struct Push { head_commit: HeadCommit, } -impl TryFrom for config::webhook::Push { +impl TryFrom for webhook::Push { type Error = git::forge::webhook::Error; fn try_from(push: Push) -> Result { let branch = push .reference .splitn(3, '/') // should be of the form 'refs/heads/branchname' .nth(2) - .map(config::BranchName::new) + .map(BranchName::new) .ok_or(git::forge::webhook::Error::UnknownBranch(push.reference))?; Ok(Self::new(branch, push.after, push.head_commit.message)) } diff --git a/crates/forge-forgejo/src/webhook/parse.rs b/crates/forge-forgejo/src/webhook/parse.rs index f6d577c..a21856c 100644 --- a/crates/forge-forgejo/src/webhook/parse.rs +++ b/crates/forge-forgejo/src/webhook/parse.rs @@ -1,10 +1,11 @@ // use crate as forgejo; -use git_next_config as config; + +use git_next_core::webhook; use git_next_git as git; pub fn parse_body( - body: &config::webhook::forge_notification::Body, -) -> git::forge::webhook::Result { + body: &webhook::forge_notification::Body, +) -> git::forge::webhook::Result { serde_json::from_str::(body.as_str())?.try_into() } diff --git a/crates/forge-forgejo/src/webhook/register.rs b/crates/forge-forgejo/src/webhook/register.rs index aa127c7..cddc32c 100644 --- a/crates/forge-forgejo/src/webhook/register.rs +++ b/crates/forge-forgejo/src/webhook/register.rs @@ -1,6 +1,5 @@ // - -use git_next_config as config; +use git_next_core::{server, RegisteredWebhook, WebhookAuth, WebhookId}; use git_next_git as git; use kxio::network; @@ -12,9 +11,9 @@ use crate::webhook::Hook; #[tracing::instrument(skip_all)] pub async fn register( repo_details: &git::RepoDetails, - webhook_url: &config::server::WebhookUrl, + webhook_url: &server::WebhookUrl, net: &network::Network, -) -> git::forge::webhook::Result { +) -> git::forge::webhook::Result { let Some(repo_config) = repo_details.repo_config.clone() else { return Err(git::forge::webhook::Error::NoRepoConfig); }; @@ -34,7 +33,7 @@ pub async fn register( )); let repo_alias = &repo_details.repo_alias; let headers = network::NetRequestHeaders::new().with("Content-Type", "application/json"); - let authorisation = config::WebhookAuth::generate(); + let authorisation = WebhookAuth::generate(); let body = network::json!({ "active": true, "authorization_header": authorisation.header_value(), @@ -64,8 +63,8 @@ pub async fn register( return Err(git::forge::webhook::Error::NetworkResponseEmpty); }; info!(webhook_id = %hook.id, "Webhook registered"); - Ok(config::RegisteredWebhook::new( - config::WebhookId::new(format!("{}", hook.id)), + Ok(RegisteredWebhook::new( + WebhookId::new(format!("{}", hook.id)), authorisation, )) } diff --git a/crates/forge-forgejo/src/webhook/unregister.rs b/crates/forge-forgejo/src/webhook/unregister.rs index d174c31..d2356e7 100644 --- a/crates/forge-forgejo/src/webhook/unregister.rs +++ b/crates/forge-forgejo/src/webhook/unregister.rs @@ -1,11 +1,11 @@ // -use git_next_config as config; +use git_next_core::WebhookId; use git_next_git as git; use kxio::network; pub async fn unregister( - webhook_id: &config::WebhookId, + webhook_id: &WebhookId, repo_details: &git::RepoDetails, net: &network::Network, ) -> git::forge::webhook::Result<()> { diff --git a/crates/forge-github/Cargo.toml b/crates/forge-github/Cargo.toml index 44813bc..69ef347 100644 --- a/crates/forge-github/Cargo.toml +++ b/crates/forge-github/Cargo.toml @@ -7,7 +7,7 @@ repository = { workspace = true } description = "GitHub support for git-next, the trunk-based development manager" [dependencies] -git-next-config = { workspace = true } +git-next-core = { workspace = true } git-next-git = { workspace = true } # own version for UserAgent requests to github.com diff --git a/crates/forge-github/src/lib.rs b/crates/forge-github/src/lib.rs index e123b3f..4af2133 100644 --- a/crates/forge-github/src/lib.rs +++ b/crates/forge-github/src/lib.rs @@ -7,7 +7,9 @@ mod webhook; use crate as github; use git::forge::commit::Status; -use git_next_config as config; +use git_next_core::{ + self as core, server, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, +}; use git_next_git as git; use derive_more::Constructor; @@ -26,15 +28,11 @@ impl git::ForgeLike for Github { "github".to_string() } - fn is_message_authorised( - &self, - msg: &config::ForgeNotification, - webhook_auth: &config::WebhookAuth, - ) -> bool { + fn is_message_authorised(&self, msg: &ForgeNotification, webhook_auth: &WebhookAuth) -> bool { github::webhook::is_authorised(msg, webhook_auth) } - fn should_ignore_message(&self, message: &config::ForgeNotification) -> bool { + fn should_ignore_message(&self, message: &ForgeNotification) -> bool { let Some(event) = message.header("x-github-event") else { return false; }; @@ -48,8 +46,8 @@ impl git::ForgeLike for Github { fn parse_webhook_body( &self, - body: &config::webhook::forge_notification::Body, - ) -> git::forge::webhook::Result { + body: &core::webhook::forge_notification::Body, + ) -> git::forge::webhook::Result { github::webhook::parse_body(body) } @@ -59,23 +57,20 @@ impl git::ForgeLike for Github { async fn list_webhooks( &self, - webhook_url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result> { + webhook_url: &server::WebhookUrl, + ) -> git::forge::webhook::Result> { github::webhook::list(self, webhook_url).await } - async fn unregister_webhook( - &self, - webhook_id: &config::WebhookId, - ) -> git::forge::webhook::Result<()> { + async fn unregister_webhook(&self, webhook_id: &WebhookId) -> git::forge::webhook::Result<()> { github::webhook::unregister(self, webhook_id).await } // https://docs.github.com/en/rest/repos/webhooks?apiVersion=2022-11-28#create-a-repository-webhook async fn register_webhook( &self, - webhook_url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result { + webhook_url: &server::WebhookUrl, + ) -> git::forge::webhook::Result { github::webhook::register(self, webhook_url).await } } @@ -105,11 +100,11 @@ struct GithubHook { config: Config, } impl GithubHook { - pub fn id(&self) -> config::WebhookId { - config::WebhookId::new(format!("{}", self.id)) + pub fn id(&self) -> WebhookId { + WebhookId::new(format!("{}", self.id)) } - pub fn url(&self) -> config::server::WebhookUrl { - config::server::WebhookUrl::new(self.config.url.clone()) + pub fn url(&self) -> server::WebhookUrl { + server::WebhookUrl::new(self.config.url.clone()) } } #[derive(Debug, serde::Deserialize)] diff --git a/crates/forge-github/src/tests/mod.rs b/crates/forge-github/src/tests/mod.rs index 986211f..6ef01a6 100644 --- a/crates/forge-github/src/tests/mod.rs +++ b/crates/forge-github/src/tests/mod.rs @@ -1,20 +1,26 @@ // -use git_next_config as config; -use git_next_git as git; +use crate::{Github, GithubState, GithubStatus}; +use git_next_core::{ + server::{InboundWebhook, WebhookUrl}, + webhook, + webhook::forge_notification::Body, + ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, Hostname, RepoAlias, + RepoBranches, RepoPath, ServerRepoConfig, StoragePathType, WebhookAuth, WebhookId, +}; +use git_next_git::{self as git, forge::commit::Status, ForgeLike}; + +use assert2::let_assert; +use kxio::network::{self, MockNetwork, StatusCode}; +use rand::RngCore; +use serde::Serialize; +use serde_json::json; + +use std::collections::BTreeMap; +use std::path::PathBuf; mod github { use super::*; - use assert2::let_assert; - use std::collections::BTreeMap; - - use crate::Github; - use config::{ - webhook::forge_notification::Body, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, - GitDir, RepoAlias, RepoBranches, ServerRepoConfig, WebhookAuth, - }; - use git::ForgeLike as _; - #[test] fn should_return_name() { let forge = given::a_github_forge(&given::repo_details(), given::a_network()); @@ -53,8 +59,6 @@ mod github { mod parse_webhook_body { - use serde_json::json; - use super::*; #[test] @@ -73,7 +77,7 @@ mod github { assert_eq!(push.message(), message); assert_eq!( push.branch(&repo_branches), - Some(config::webhook::push::Branch::Next) + Some(webhook::push::Branch::Next) ); } @@ -86,10 +90,6 @@ mod github { } mod commit_status { - use git_next_git::forge::commit::Status; - use kxio::network::StatusCode; - - use crate::GithubState; use super::*; @@ -154,10 +154,6 @@ mod github { } mod list_webhooks { - use git_next_config::WebhookId; - use git_next_git::ForgeLike as _; - - use crate::tests::github::with; use super::*; @@ -221,8 +217,6 @@ mod github { mod unregister_webhook { use super::*; - use git_next_git::ForgeLike; - use kxio::network::StatusCode; #[tokio::test] async fn should_delete_webhook() { @@ -269,14 +263,9 @@ mod github { } mod register_webhook { - use crate::tests::github::with; use super::*; - use git_next_config::WebhookId; - use kxio::network::StatusCode; - use serde_json::json; - #[tokio::test] async fn should_register_a_new_webhook() { let repo_details = given::repo_details(); @@ -451,12 +440,8 @@ mod github { } } - mod with { - use serde::Serialize; - use serde_json::json; - - use git_next_config::{server::WebhookUrl, Hostname, RepoPath}; - use kxio::network::{self, StatusCode}; + pub mod with { + use super::*; pub fn get_webhooks_by_page( page: u8, @@ -508,15 +493,6 @@ mod github { mod given { - use std::path::PathBuf; - - use git_next_config::{server::InboundWebhook, WebhookId}; - use kxio::network::{MockNetwork, StatusCode}; - use rand::RngCore; - use serde_json::json; - - use crate::{GithubState, GithubStatus}; - use super::*; pub fn commit_states( @@ -626,10 +602,7 @@ mod github { a_name(), BTreeMap::default(), ), - GitDir::new( - PathBuf::default(), - config::git_dir::StoragePathType::External, - ), + GitDir::new(PathBuf::default(), StoragePathType::External), ) } @@ -644,13 +617,10 @@ mod github { kxio::network::MockNetwork::new() } - pub fn a_webhook_url( - forge_alias: &ForgeAlias, - repo_alias: &RepoAlias, - ) -> git_next_config::server::WebhookUrl { + pub fn a_webhook_url(forge_alias: &ForgeAlias, repo_alias: &RepoAlias) -> WebhookUrl { InboundWebhook::new(a_name()).url(forge_alias, repo_alias) } - pub fn any_webhook_url() -> git_next_config::server::WebhookUrl { + pub fn any_webhook_url() -> WebhookUrl { given::a_webhook_url(&given::a_forge_alias(), &given::a_repo_alias()) } diff --git a/crates/forge-github/src/webhook/authorised.rs b/crates/forge-github/src/webhook/authorised.rs index ccf2d9d..58aae38 100644 --- a/crates/forge-github/src/webhook/authorised.rs +++ b/crates/forge-github/src/webhook/authorised.rs @@ -1,7 +1,8 @@ // -use git_next_config as config; -pub fn is_authorised(msg: &config::ForgeNotification, webhook_auth: &config::WebhookAuth) -> bool { +use git_next_core::{ForgeNotification, WebhookAuth}; + +pub fn is_authorised(msg: &ForgeNotification, webhook_auth: &WebhookAuth) -> bool { msg.header("x-hub-signature-256") .map(|x| x.trim_matches('"').to_string()) .and_then(|sha| sha.strip_prefix("sha256=").map(|k| k.to_string())) @@ -20,9 +21,9 @@ pub fn is_authorised(msg: &config::ForgeNotification, webhook_auth: &config::Web #[cfg(test)] pub fn sign_body( - webhook_auth: &config::WebhookAuth, - body: &config::webhook::forge_notification::Body, -) -> std::option::Option { + webhook_auth: &WebhookAuth, + body: &git_next_core::webhook::forge_notification::Body, +) -> Option { let payload = body.as_str(); use hmac::Mac; type HmacSha256 = hmac::Hmac; diff --git a/crates/forge-github/src/webhook/list.rs b/crates/forge-github/src/webhook/list.rs index 3771d25..2d86c8c 100644 --- a/crates/forge-github/src/webhook/list.rs +++ b/crates/forge-github/src/webhook/list.rs @@ -1,15 +1,16 @@ // use crate as github; -use git_next_config as config; +use git_next_core::{server, WebhookId}; use git_next_git as git; + use kxio::network; // https://docs.github.com/en/rest/repos/webhooks?apiVersion=2022-11-28#list-repository-webhooks pub async fn list( github: &github::Github, - webhook_url: &config::server::WebhookUrl, -) -> git::forge::webhook::Result> { - let mut ids: Vec = vec![]; + webhook_url: &server::WebhookUrl, +) -> git::forge::webhook::Result> { + let mut ids: Vec = vec![]; let repo_details = &github.repo_details; let hostname = &repo_details.forge.hostname(); let net = &github.net; diff --git a/crates/forge-github/src/webhook/mod.rs b/crates/forge-github/src/webhook/mod.rs index 5e0a06a..78eee6b 100644 --- a/crates/forge-github/src/webhook/mod.rs +++ b/crates/forge-github/src/webhook/mod.rs @@ -1,5 +1,5 @@ // -use git_next_config as config; +use git_next_core::{webhook, ApiToken, BranchName}; use git_next_git as git; mod authorised; @@ -17,7 +17,7 @@ pub use unregister::unregister; #[cfg(test)] pub use authorised::sign_body; -pub fn headers(token: &config::ApiToken) -> kxio::network::NetRequestHeaders { +pub fn headers(token: &ApiToken) -> kxio::network::NetRequestHeaders { use secrecy::ExposeSecret; kxio::network::NetRequestHeaders::default() .with("Accept", "application/vnd.github+json") @@ -44,14 +44,14 @@ pub struct HeadCommit { message: String, } -impl TryFrom for config::webhook::Push { +impl TryFrom for webhook::Push { type Error = git::forge::webhook::Error; fn try_from(push: Push) -> Result { let branch = push .reference .splitn(3, '/') // should be of the form 'refs/heads/branchname' .nth(2) - .map(config::BranchName::new) + .map(BranchName::new) .ok_or(git::forge::webhook::Error::UnknownBranch(push.reference))?; Ok(Self::new(branch, push.after, push.head_commit.message)) } diff --git a/crates/forge-github/src/webhook/parse.rs b/crates/forge-github/src/webhook/parse.rs index 5d2222a..d132ee2 100644 --- a/crates/forge-github/src/webhook/parse.rs +++ b/crates/forge-github/src/webhook/parse.rs @@ -1,10 +1,11 @@ // use crate as github; -use git_next_config as config; + +use git_next_core::webhook; use git_next_git as git; pub fn parse_body( - body: &config::webhook::forge_notification::Body, -) -> git::forge::webhook::Result { + body: &webhook::forge_notification::Body, +) -> git::forge::webhook::Result { serde_json::from_str::(body.as_str())?.try_into() } diff --git a/crates/forge-github/src/webhook/register.rs b/crates/forge-github/src/webhook/register.rs index a283537..60cf976 100644 --- a/crates/forge-github/src/webhook/register.rs +++ b/crates/forge-github/src/webhook/register.rs @@ -1,6 +1,6 @@ // use crate::{self as github, webhook}; -use git_next_config as config; +use git_next_core::{server, RegisteredWebhook, WebhookAuth, WebhookId}; use git_next_git as git; use kxio::network; @@ -8,8 +8,8 @@ use kxio::network; // https://docs.github.com/en/rest/repos/webhooks?apiVersion=2022-11-28#create-a-repository-webhook pub async fn register( github: &github::Github, - webhook_url: &config::server::WebhookUrl, -) -> git::forge::webhook::Result { + webhook_url: &server::WebhookUrl, +) -> git::forge::webhook::Result { let repo_details = &github.repo_details; if repo_details.repo_config.is_none() { return Err(git::forge::webhook::Error::NoRepoConfig); @@ -23,7 +23,7 @@ pub async fn register( let net = &github.net; let hostname = repo_details.forge.hostname(); - let authorisation = config::WebhookAuth::generate(); + let authorisation = WebhookAuth::generate(); let request = network::NetRequest::new( network::RequestMethod::Post, network::NetUrl::new(format!( @@ -55,8 +55,8 @@ pub async fn register( return Err(git::forge::webhook::Error::NetworkResponseEmpty); }; tracing::info!(webhook_id = %hook.id, "Webhook registered"); - Ok(config::RegisteredWebhook::new( - config::WebhookId::new(format!("{}", hook.id)), + Ok(RegisteredWebhook::new( + WebhookId::new(format!("{}", hook.id)), authorisation, )) } diff --git a/crates/forge-github/src/webhook/unregister.rs b/crates/forge-github/src/webhook/unregister.rs index 7bc0ac4..8e15cd2 100644 --- a/crates/forge-github/src/webhook/unregister.rs +++ b/crates/forge-github/src/webhook/unregister.rs @@ -1,6 +1,7 @@ // use crate as github; -use git_next_config as config; + +use git_next_core::WebhookId; use git_next_git as git; use kxio::network; @@ -8,7 +9,7 @@ use kxio::network; // https://docs.github.com/en/rest/repos/webhooks?apiVersion=2022-11-28#delete-a-repository-webhook pub async fn unregister( github: &github::Github, - webhook_id: &config::WebhookId, + webhook_id: &WebhookId, ) -> git::forge::webhook::Result<()> { let net = &github.net; let repo_details = &github.repo_details; diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 737a223..6ffbaa5 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -12,7 +12,7 @@ forgejo = ["git-next-forge-forgejo"] github = ["git-next-forge-github"] [dependencies] -git-next-config = { workspace = true } +git-next-core = { workspace = true } git-next-git = { workspace = true } git-next-forge-forgejo = { workspace = true, optional = true } git-next-forge-github = { workspace = true, optional = true } diff --git a/crates/forge/src/lib.rs b/crates/forge/src/lib.rs index c6ac8c6..09903f3 100644 --- a/crates/forge/src/lib.rs +++ b/crates/forge/src/lib.rs @@ -1,6 +1,5 @@ // -use git_next_forge_forgejo as forgejo; -use git_next_forge_github as github; +use git_next_core::ForgeType; use git_next_git as git; use kxio::network::Network; @@ -18,12 +17,10 @@ impl Forge { pub fn create(repo_details: git::RepoDetails, net: Network) -> Box { match repo_details.forge.forge_type() { #[cfg(feature = "forgejo")] - git_next_config::ForgeType::ForgeJo => { - Box::new(forgejo::ForgeJo::new(repo_details, net)) - } + ForgeType::ForgeJo => Box::new(git_next_forge_forgejo::ForgeJo::new(repo_details, net)), #[cfg(feature = "github")] - git_next_config::ForgeType::GitHub => Box::new(github::Github::new(repo_details, net)), - git_next_config::ForgeType::MockForge => unreachable!(), + ForgeType::GitHub => Box::new(git_next_forge_github::Github::new(repo_details, net)), + ForgeType::MockForge => unreachable!(), } } } diff --git a/crates/forge/src/tests.rs b/crates/forge/src/tests.rs index 08137d9..65719a9 100644 --- a/crates/forge/src/tests.rs +++ b/crates/forge/src/tests.rs @@ -1,13 +1,13 @@ // use super::*; -use git_next_config as config; +use git_next_core::{self as core, GitDir, RepoConfigSource, StoragePathType}; use git_next_git::{self as git, RepoDetails}; #[test] fn test_forgejo_name() { let net = Network::new_mock(); - let repo_details = given_repo_details(config::ForgeType::ForgeJo); + let repo_details = given_repo_details(ForgeType::ForgeJo); let forge = Forge::create(repo_details, net); assert_eq!(forge.name(), "forgejo"); } @@ -15,7 +15,7 @@ fn test_forgejo_name() { #[test] fn test_github_name() { let net = Network::new_mock(); - let repo_details = given_repo_details(config::ForgeType::GitHub); + let repo_details = given_repo_details(ForgeType::GitHub); let forge = Forge::create(repo_details, net); assert_eq!(forge.name(), "github"); } @@ -27,19 +27,13 @@ fn given_fs() -> kxio::fs::FileSystem { }) } -fn given_repo_details(forge_type: config::ForgeType) -> RepoDetails { +fn given_repo_details(forge_type: ForgeType) -> RepoDetails { let fs = given_fs(); git::common::repo_details( 1, git::Generation::default(), - config::common::forge_details(1, forge_type), - Some(config::common::repo_config( - 1, - config::RepoConfigSource::Repo, - )), - config::GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ), + core::common::forge_details(1, forge_type), + Some(core::common::repo_config(1, RepoConfigSource::Repo)), + GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal), ) } diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.toml index e60d092..865df5f 100644 --- a/crates/git/Cargo.toml +++ b/crates/git/Cargo.toml @@ -7,18 +7,12 @@ repository = { workspace = true } description = "git support for git-next, the trunk-based development manager" [dependencies] -git-next-config = { workspace = true } +git-next-core = { 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 } @@ -27,7 +21,6 @@ kxio = { workspace = true } # TOML parsing serde_json = { workspace = true } -# toml = { workspace = true } # webhooks - user notification serde = { workspace = true } @@ -35,26 +28,13 @@ serde = { 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 } derive-with = { workspace = true } thiserror = { workspace = true } -# # file watcher -# inotify = { workspace = true } - # Actors actix = { workspace = true } -# actix-rt = { workspace = true } -# tokio = { workspace = true } mockall = { workspace = true } diff --git a/crates/git/src/commit.rs b/crates/git/src/commit.rs index 443a780..b55f880 100644 --- a/crates/git/src/commit.rs +++ b/crates/git/src/commit.rs @@ -1,7 +1,7 @@ -use config::newtype; -use derive_more::Display; // -use git_next_config as config; +use git_next_core::{newtype, webhook}; + +use derive_more::Display; use serde::Serialize; #[derive( @@ -30,8 +30,8 @@ impl Commit { } } -impl From for Commit { - fn from(value: config::webhook::Push) -> Self { +impl From for Commit { + fn from(value: webhook::Push) -> Self { Self::new( Sha::new(value.sha().to_owned()), Message::new(value.message().to_owned()), @@ -50,18 +50,14 @@ pub struct Histories { } pub mod log { - - use git_next_config as config; + use git_next_core::BranchName; pub type Result = core::result::Result; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("branch: {branch}, error: {error}")] - Gix { - branch: config::BranchName, - error: String, - }, + Gix { branch: BranchName, error: String }, #[error("lock")] Lock, diff --git a/crates/git/src/common.rs b/crates/git/src/common.rs index 57fd59c..1eedcf9 100644 --- a/crates/git/src/common.rs +++ b/crates/git/src/common.rs @@ -1,6 +1,6 @@ // -use git_next_config::{ +use git_next_core::{ common::{branch_name, repo_alias, repo_path}, ForgeDetails, GitDir, RepoConfig, }; diff --git a/crates/git/src/forge/like.rs b/crates/git/src/forge/like.rs index 06f4013..5bd6052 100644 --- a/crates/git/src/forge/like.rs +++ b/crates/git/src/forge/like.rs @@ -1,5 +1,9 @@ +// use crate as git; -use git_next_config as config; + +use git_next_core::{ + server::WebhookUrl, webhook, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, +}; #[mockall::automock] #[async_trait::async_trait] @@ -8,43 +12,33 @@ pub trait ForgeLike: std::fmt::Debug + Send + Sync { fn name(&self) -> String; /// Checks that the message has a valid authorisation. - fn is_message_authorised( - &self, - message: &config::ForgeNotification, - expected: &config::WebhookAuth, - ) -> bool; + fn is_message_authorised(&self, message: &ForgeNotification, expected: &WebhookAuth) -> bool; /// Checks if the message should be ignored. /// /// Default implementation says that no messages should be ignored. - fn should_ignore_message(&self, _message: &config::ForgeNotification) -> bool { + fn should_ignore_message(&self, _message: &ForgeNotification) -> bool { false } /// Parses the webhook body into Some(Push) struct if appropriate, or None if not. fn parse_webhook_body( &self, - body: &config::webhook::forge_notification::Body, - ) -> git::forge::webhook::Result; + body: &webhook::forge_notification::Body, + ) -> git::forge::webhook::Result; /// Checks the results of any (e.g. CI) status checks for the commit. async fn commit_status(&self, commit: &git::Commit) -> git::forge::commit::Status; // Lists all the webhooks - async fn list_webhooks( - &self, - url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result>; + async fn list_webhooks(&self, url: &WebhookUrl) -> git::forge::webhook::Result>; // Unregisters a webhook - async fn unregister_webhook( - &self, - webhook: &config::WebhookId, - ) -> git::forge::webhook::Result<()>; + async fn unregister_webhook(&self, webhook: &WebhookId) -> git::forge::webhook::Result<()>; // Registers a webhook async fn register_webhook( &self, - webhook_url: &config::server::WebhookUrl, - ) -> git::forge::webhook::Result; + webhook_url: &WebhookUrl, + ) -> git::forge::webhook::Result; } diff --git a/crates/git/src/generation.rs b/crates/git/src/generation.rs index 1339db5..ed691f4 100644 --- a/crates/git/src/generation.rs +++ b/crates/git/src/generation.rs @@ -1,5 +1,5 @@ use derive_more::Display; -use git_next_config::newtype; +use git_next_core::newtype; newtype!(Generation: u32, Display, Default, Copy: r#"A counter for the server generation. diff --git a/crates/git/src/git_ref.rs b/crates/git/src/git_ref.rs index f832e4b..f3fcaf3 100644 --- a/crates/git/src/git_ref.rs +++ b/crates/git/src/git_ref.rs @@ -1,9 +1,9 @@ // -use crate as git; -use derive_more::Display; -use git_next_config::newtype; +use git_next_core::newtype; -use crate::Commit; +use derive_more::Display; + +use crate::{commit::Sha, Commit}; newtype!(GitRef: String, Display: "A git reference to a git commit."); impl From for GitRef { @@ -11,8 +11,8 @@ impl From for GitRef { Self(value.sha().to_string()) } } -impl From for GitRef { - fn from(value: git::commit::Sha) -> Self { +impl From for GitRef { + fn from(value: Sha) -> Self { Self(value.to_string()) } } diff --git a/crates/git/src/git_remote.rs b/crates/git/src/git_remote.rs index 8f383be..f23cda7 100644 --- a/crates/git/src/git_remote.rs +++ b/crates/git/src/git_remote.rs @@ -1,6 +1,9 @@ -use git_next_config::{Hostname, RepoPath}; +// +use derive_more::{Constructor, Display}; -#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)] +use git_next_core::{Hostname, RepoPath}; + +#[derive(Clone, Debug, PartialEq, Eq, Constructor, Display)] #[display("{}:{}", host, repo_path)] pub struct GitRemote { host: Hostname, diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs index 99a93e0..5393dda 100644 --- a/crates/git/src/lib.rs +++ b/crates/git/src/lib.rs @@ -23,6 +23,6 @@ pub use generation::Generation; pub use git_ref::GitRef; pub use git_remote::GitRemote; pub use repo_details::RepoDetails; -pub use repository::OpenRepository; pub use repository::Repository; +pub use repository::RepositoryFactory; pub use user_notification::UserNotification; diff --git a/crates/git/src/push.rs b/crates/git/src/push.rs index adf1096..991da09 100644 --- a/crates/git/src/push.rs +++ b/crates/git/src/push.rs @@ -1,11 +1,11 @@ -use super::GitRef; -use crate as git; -use git_next_config as config; +// +use crate::{self as git, repository::open::OpenRepositoryLike}; +use git_next_core::BranchName; #[derive(Debug, PartialEq, Eq)] pub enum Force { No, - From(GitRef), + From(git::GitRef), } impl std::fmt::Display for Force { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -47,9 +47,9 @@ pub enum Error { } pub fn reset( - open_repository: &dyn git::repository::OpenRepositoryLike, + open_repository: &dyn OpenRepositoryLike, repo_details: &git::RepoDetails, - branch_name: &config::BranchName, + branch_name: &BranchName, to_commit: &git::GitRef, force: &git::push::Force, ) -> Result<()> { diff --git a/crates/git/src/repo_details.rs b/crates/git/src/repo_details.rs index a24f1db..1f163af 100644 --- a/crates/git/src/repo_details.rs +++ b/crates/git/src/repo_details.rs @@ -1,16 +1,17 @@ +// +use crate::{ + repository::open::{oreal::RealOpenRepository, OpenRepositoryLike}, + Generation, GitRemote, +}; +use git_next_core::{ + pike, BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, Hostname, RemoteUrl, + RepoAlias, RepoConfig, RepoPath, ServerRepoConfig, StoragePathType, +}; + use std::sync::{Arc, RwLock}; -use config::{ - BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, RepoAlias, RepoConfig, RepoPath, - ServerRepoConfig, StoragePathType, -}; -use git_next_config::{self as config, pike, RemoteUrl}; use secrecy::Secret; -use crate::repository::{OpenRepositoryLike, RealOpenRepository}; - -use super::{Generation, GitRemote}; - /// The derived information about a repo, used to interact with it #[derive(Clone, Debug, derive_more::Display, derive_with::With)] #[display("gen-{}:{}:{}/{}", generation, forge.forge_type(), forge.forge_alias(), repo_alias )] @@ -68,7 +69,7 @@ impl RepoDetails { GitRemote::new(self.forge.hostname().clone(), self.repo_path.clone()) } - pub fn with_hostname(mut self, hostname: config::Hostname) -> Self { + pub fn with_hostname(mut self, hostname: Hostname) -> Self { let forge = self.forge; self.forge = forge.with_hostname(hostname); self @@ -101,7 +102,7 @@ impl RepoDetails { Ok(repo) } - pub fn remote_url(&self) -> Option { + pub fn remote_url(&self) -> Option { use secrecy::ExposeSecret; RemoteUrl::parse(self.url().expose_secret()) } diff --git a/crates/git/src/repository/factory.rs b/crates/git/src/repository/factory.rs index e983aae..0663ec2 100644 --- a/crates/git/src/repository/factory.rs +++ b/crates/git/src/repository/factory.rs @@ -1,8 +1,14 @@ -use super::RepoDetails; -use super::Result; -pub use crate::repository::open::OpenRepositoryLike; -use crate::repository::{Direction, RealOpenRepository}; +// +use crate::{ + repository::{ + open::{oreal::RealOpenRepository, OpenRepositoryLike}, + Direction, Result, + }, + RepoDetails, +}; + use derive_more::Deref as _; + use std::sync::{atomic::AtomicBool, Arc, RwLock}; #[mockall::automock] diff --git a/crates/git/src/repository/mod.rs b/crates/git/src/repository/mod.rs index 7a1ba7f..081875b 100644 --- a/crates/git/src/repository/mod.rs +++ b/crates/git/src/repository/mod.rs @@ -1,20 +1,22 @@ // -use super::RepoDetails; -use crate::repository::test::TestRepository; -use crate::validation::remotes::validate_default_remotes; -pub use factory::RepositoryFactory; -use git_next_config::{GitDir, RemoteUrl}; -pub use open::otest::OnFetch; -pub use open::otest::OnPush; -pub use open::OpenRepository; -pub use open::OpenRepositoryLike; -pub use open::RealOpenRepository; +use crate::{ + repository::{ + open::{OpenRepository, OpenRepositoryLike}, + test::TestRepository, + }, + validation::remotes::validate_default_remotes, + RepoDetails, +}; +use git_next_core::{GitDir, RemoteUrl}; + use tracing::info; pub mod factory; pub mod open; mod test; +pub use factory::RepositoryFactory; + #[cfg(test)] mod tests; @@ -85,7 +87,7 @@ pub type Result = core::result::Result; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("invalid git dir: {0}")] - InvalidGitDir(git_next_config::GitDir), + InvalidGitDir(GitDir), #[error("kxiofs: {0}")] KxioFs(#[from] kxio::fs::Error), diff --git a/crates/git/src/repository/open/mod.rs b/crates/git/src/repository/open/mod.rs index 5e501c3..47a05eb 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -5,16 +5,19 @@ mod tests; pub mod oreal; pub mod otest; +use git_next_core::{BranchName, GitDir, RemoteUrl}; +use crate as git; +use git::repository::{ + open::{oreal::RealOpenRepository, otest::TestOpenRepository}, + Direction, +}; + use std::{ path::Path, sync::{Arc, RwLock}, }; -use crate as git; -use git::repository::Direction; -use git_next_config::{self as config, RemoteUrl}; -pub use oreal::RealOpenRepository; -pub use otest::TestOpenRepository; + #[derive(Clone, Debug)] pub enum OpenRepository { @@ -41,7 +44,7 @@ pub fn real(gix_repo: gix::Repository) -> OpenRepository { #[cfg(not(tarpaulin_include))] // don't test mocks pub fn test( - gitdir: &config::GitDir, + gitdir: &GitDir, fs: kxio::fs::FileSystem, on_fetch: Vec, on_push: Vec, @@ -52,13 +55,13 @@ pub fn test( #[mockall::automock] pub trait OpenRepositoryLike: std::fmt::Debug + Sync { fn duplicate(&self) -> Box; - fn remote_branches(&self) -> git::push::Result>; + fn remote_branches(&self) -> git::push::Result>; fn find_default_remote(&self, direction: Direction) -> Option; fn fetch(&self) -> Result<(), git::fetch::Error>; fn push( &self, repo_details: &git::RepoDetails, - branch_name: &config::BranchName, + branch_name: &BranchName, to_commit: &git::GitRef, force: &git::push::Force, ) -> git::push::Result<()>; @@ -66,18 +69,14 @@ pub trait OpenRepositoryLike: std::fmt::Debug + Sync { /// List of commits in a branch, optionally up-to any specified commit. fn commit_log( &self, - branch_name: &config::BranchName, + branch_name: &BranchName, find_commits: &[git::Commit], ) -> git::commit::log::Result>; /// Read the contents of a file as a string. /// /// Only handles files in the root of the repo. - fn read_file( - &self, - branch_name: &config::BranchName, - file_name: &Path, - ) -> git::file::Result; + fn read_file(&self, branch_name: &BranchName, file_name: &Path) -> git::file::Result; } pub fn mock() -> Box { diff --git a/crates/git/src/repository/open/oreal.rs b/crates/git/src/repository/open/oreal.rs index c16d252..0269fdc 100644 --- a/crates/git/src/repository/open/oreal.rs +++ b/crates/git/src/repository/open/oreal.rs @@ -1,20 +1,21 @@ // use crate::{self as git, repository::OpenRepositoryLike}; -use config::BranchName; -use derive_more::Constructor; -use git_next_config::{self as config, RemoteUrl}; +use git_next_core::{BranchName, Hostname, RemoteUrl, RepoPath}; + +use derive_more::Constructor; use gix::bstr::BStr; +use tracing::{info, warn}; + use std::{ path::Path, sync::{Arc, RwLock}, }; -use tracing::{info, warn}; #[derive(Clone, Debug, Constructor)] pub struct RealOpenRepository(Arc>); impl super::OpenRepositoryLike for RealOpenRepository { - fn remote_branches(&self) -> git::push::Result> { + fn remote_branches(&self) -> git::push::Result> { let refs = self .0 .read() @@ -87,7 +88,7 @@ impl super::OpenRepositoryLike for RealOpenRepository { fn push( &self, repo_details: &git::RepoDetails, - branch_name: &config::BranchName, + branch_name: &BranchName, to_commit: &git::GitRef, force: &git::push::Force, ) -> Result<(), git::push::Error> { @@ -126,7 +127,7 @@ impl super::OpenRepositoryLike for RealOpenRepository { fn commit_log( &self, - branch_name: &config::BranchName, + branch_name: &BranchName, find_commits: &[git::Commit], ) -> Result, git::commit::log::Error> { let limit = match find_commits.is_empty() { @@ -187,11 +188,7 @@ impl super::OpenRepositoryLike for RealOpenRepository { } #[tracing::instrument(skip_all, fields(%branch_name, ?file_name))] - fn read_file( - &self, - branch_name: &config::BranchName, - file_name: &Path, - ) -> git::file::Result { + fn read_file(&self, branch_name: &BranchName, file_name: &Path) -> git::file::Result { self.0 .read() .map_err(|_| git::file::Error::Lock) @@ -229,9 +226,6 @@ impl From<&RemoteUrl> for git::GitRemote { let path = url.path.to_string(); let path = path.strip_prefix('/').map_or(path.as_str(), |path| path); let path = path.strip_suffix(".git").map_or(path, |path| path); - Self::new( - config::Hostname::new(host), - config::RepoPath::new(path.to_string()), - ) + Self::new(Hostname::new(host), RepoPath::new(path.to_string())) } } diff --git a/crates/git/src/repository/open/otest.rs b/crates/git/src/repository/open/otest.rs index b040c9f..84a727f 100644 --- a/crates/git/src/repository/open/otest.rs +++ b/crates/git/src/repository/open/otest.rs @@ -1,19 +1,23 @@ // -use crate::{self as git, repository::OpenRepositoryLike}; +use crate::{ + self as git, + repository::open::{OpenRepositoryLike, RealOpenRepository}, +}; + +use git_next_core::{BranchName, GitDir, RemoteUrl, RepoBranches}; + use derive_more::{Constructor, Deref}; -use git_next_config::{self as config, RemoteUrl}; use std::{ path::Path, sync::{Arc, RwLock}, }; -pub type OnFetchFn = - fn(&config::RepoBranches, &config::GitDir, &kxio::fs::FileSystem) -> git::fetch::Result<()>; +pub type OnFetchFn = fn(&RepoBranches, &GitDir, &kxio::fs::FileSystem) -> git::fetch::Result<()>; #[derive(Clone, Debug, Constructor)] pub struct OnFetch { - repo_branches: config::RepoBranches, - gitdir: config::GitDir, + repo_branches: RepoBranches, + gitdir: GitDir, fs: kxio::fs::FileSystem, action: OnFetchFn, } @@ -25,17 +29,17 @@ impl OnFetch { pub type OnPushFn = fn( &git::RepoDetails, - &config::BranchName, + &BranchName, &git::GitRef, &git::push::Force, - &config::RepoBranches, - &config::GitDir, + &RepoBranches, + &GitDir, &kxio::fs::FileSystem, ) -> git::push::Result<()>; #[derive(Clone, Debug, Constructor)] pub struct OnPush { - repo_branches: config::RepoBranches, - gitdir: config::GitDir, + repo_branches: RepoBranches, + gitdir: GitDir, fs: kxio::fs::FileSystem, action: OnPushFn, } @@ -43,7 +47,7 @@ impl OnPush { pub fn invoke( &self, repo_details: &git::RepoDetails, - branch_name: &config::BranchName, + branch_name: &BranchName, to_commit: &git::GitRef, force: &git::push::Force, ) -> git::push::Result<()> { @@ -65,11 +69,11 @@ pub struct TestOpenRepository { fetch_counter: Arc>, on_push: Vec, push_counter: Arc>, - real: git::repository::RealOpenRepository, + real: RealOpenRepository, } #[cfg(not(tarpaulin_include))] impl git::repository::OpenRepositoryLike for TestOpenRepository { - fn remote_branches(&self) -> git::push::Result> { + fn remote_branches(&self) -> git::push::Result> { self.real.remote_branches() } @@ -96,7 +100,7 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository { fn push( &self, repo_details: &git::RepoDetails, - branch_name: &config::BranchName, + branch_name: &BranchName, to_commit: &git::GitRef, force: &git::push::Force, ) -> git::push::Result<()> { @@ -120,17 +124,13 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository { fn commit_log( &self, - branch_name: &config::BranchName, + branch_name: &BranchName, find_commits: &[git::Commit], ) -> git::commit::log::Result> { self.real.commit_log(branch_name, find_commits) } - fn read_file( - &self, - branch_name: &config::BranchName, - file_name: &Path, - ) -> git::file::Result { + fn read_file(&self, branch_name: &BranchName, file_name: &Path) -> git::file::Result { self.real.read_file(branch_name, file_name) } @@ -140,7 +140,7 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository { } impl TestOpenRepository { pub fn new( - gitdir: &config::GitDir, + gitdir: &GitDir, fs: kxio::fs::FileSystem, on_fetch: Vec, on_push: Vec, @@ -154,11 +154,11 @@ impl TestOpenRepository { fetch_counter: Arc::new(RwLock::new(0)), on_push, push_counter: Arc::new(RwLock::new(0)), - real: git::repository::RealOpenRepository::new(Arc::new(RwLock::new(gix.into()))), + real: RealOpenRepository::new(Arc::new(RwLock::new(gix.into()))), } } - fn write_origin(gitdir: &config::GitDir, fs: &kxio::fs::FileSystem) { + fn write_origin(gitdir: &GitDir, fs: &kxio::fs::FileSystem) { let config_file = fs.base().join(gitdir.to_path_buf()).join(".git/config"); #[allow(clippy::expect_used)] let contents = fs diff --git a/crates/git/src/repository/open/tests/commit_log.rs b/crates/git/src/repository/open/tests/commit_log.rs index 597161d..fe3655e 100644 --- a/crates/git/src/repository/open/tests/commit_log.rs +++ b/crates/git/src/repository/open/tests/commit_log.rs @@ -1,13 +1,11 @@ +// use super::*; #[test] // assumes running in the git-next repo which should have main, next and dev as remote branches fn should_return_single_item_in_commit_log_when_not_searching() -> TestResult { let_assert!(Ok(fs) = kxio::fs::temp()); - let gitdir = GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let test_repository = git::repository::test(fs.clone()); let_assert!(Ok(open_repository) = test_repository.open(&gitdir)); let repo_config = &given::a_repo_config(); @@ -24,10 +22,7 @@ fn should_return_single_item_in_commit_log_when_not_searching() -> TestResult { fn should_return_capacity_50_in_commit_log_when_searching_for_garbage() -> TestResult { let_assert!(Ok(fs) = kxio::fs::temp()); let branch_name = given::a_branch_name(); - let gitdir = GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let test_repository = git::repository::test(fs.clone()); let_assert!(Ok(open_repository) = test_repository.open(&gitdir)); for _ in [0; 60] { @@ -44,10 +39,7 @@ fn should_return_capacity_50_in_commit_log_when_searching_for_garbage() -> TestR fn should_return_5_in_commit_log_when_searching_for_5th_item() -> TestResult { let_assert!(Ok(fs) = kxio::fs::temp(), "create temp directory"); let branch_name = given::a_branch_name(); - let gitdir = GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let test_repository = git::repository::test(fs.clone()); let_assert!( Ok(open_repository) = test_repository.open(&gitdir), diff --git a/crates/git/src/repository/open/tests/fetch.rs b/crates/git/src/repository/open/tests/fetch.rs index 0048c8f..b423f72 100644 --- a/crates/git/src/repository/open/tests/fetch.rs +++ b/crates/git/src/repository/open/tests/fetch.rs @@ -1,3 +1,4 @@ +// use super::*; #[test] @@ -5,10 +6,7 @@ use super::*; fn should_fetch_from_repo() { // uses the current repo and fetches from the remote server let_assert!(Ok(cwd) = std::env::current_dir()); - let gitdir = GitDir::new( - cwd.join("../.."), - config::git_dir::StoragePathType::External, - ); + let gitdir = GitDir::new(cwd.join("../.."), StoragePathType::External); let repo_details = given::repo_details(&given::a_filesystem()).with_gitdir(gitdir); let_assert!(Ok(repo) = crate::repository::factory::real().open(&repo_details)); let_assert!(Ok(_) = repo.fetch()); diff --git a/crates/git/src/repository/open/tests/find_default_remote.rs b/crates/git/src/repository/open/tests/find_default_remote.rs index 3e19fa2..6841a9a 100644 --- a/crates/git/src/repository/open/tests/find_default_remote.rs +++ b/crates/git/src/repository/open/tests/find_default_remote.rs @@ -1,9 +1,10 @@ +// use super::*; #[test_log::test] fn should_find_default_push_remote() { let fs = given::a_filesystem(); - let gitdir = GitDir::new(fs.base().to_path_buf(), config::StoragePathType::External); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::External); let repo_details = given::repo_details(&given::a_filesystem()).with_gitdir(gitdir); let url = repo_details.url(); given::a_bare_repo_with_url(fs.base(), url.expose_secret(), &fs); diff --git a/crates/git/src/repository/open/tests/forge_config.rs b/crates/git/src/repository/open/tests/forge_config.rs index e05c218..c433920 100644 --- a/crates/git/src/repository/open/tests/forge_config.rs +++ b/crates/git/src/repository/open/tests/forge_config.rs @@ -2,21 +2,19 @@ use super::*; #[test] fn should_return_repos() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); // alphabetical order by key let red_name = format!("a-{}", given::a_name()); let blue_name = format!("b-{}", given::a_name()); - let red = - config::ServerRepoConfig::new(red_name.clone(), given::a_name(), None, None, None, None); - let blue = - config::ServerRepoConfig::new(blue_name.clone(), given::a_name(), None, None, None, None); + let red = ServerRepoConfig::new(red_name.clone(), given::a_name(), None, None, None, None); + let blue = ServerRepoConfig::new(blue_name.clone(), given::a_name(), None, None, None, None); let mut repos = BTreeMap::new(); repos.insert(red_name.clone(), red.clone()); repos.insert(blue_name.clone(), blue.clone()); - let fc = config::ForgeConfig::new(forge_type, hostname, user, token, repos); + let fc = ForgeConfig::new(forge_type, hostname, user, token, repos); let returned_repos = fc.repos().collect::>(); @@ -24,77 +22,75 @@ fn should_return_repos() { returned_repos, vec![ // alphabetical order by key - (config::RepoAlias::new(red_name.as_str()), &red), - (config::RepoAlias::new(blue_name.as_str()), &blue), + (RepoAlias::new(red_name.as_str()), &red), + (RepoAlias::new(blue_name.as_str()), &blue), ] ); } #[test] fn should_return_forge_type() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); let repos = BTreeMap::new(); - let fc = config::ForgeConfig::new(forge_type, hostname, user, token, repos); + let fc = ForgeConfig::new(forge_type, hostname, user, token, repos); - assert_eq!(fc.forge_type(), config::ForgeType::MockForge); + assert_eq!(fc.forge_type(), ForgeType::MockForge); } #[test] fn should_return_hostname() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); let repos = BTreeMap::new(); - let fc = config::ForgeConfig::new(forge_type, hostname.clone(), user, token, repos); + let fc = ForgeConfig::new(forge_type, hostname.clone(), user, token, repos); - assert_eq!(fc.hostname(), config::Hostname::new(hostname)); + assert_eq!(fc.hostname(), Hostname::new(hostname)); } #[test] fn should_return_user() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); let repos = BTreeMap::new(); - let fc = config::ForgeConfig::new(forge_type, hostname, user.clone(), token, repos); + let fc = ForgeConfig::new(forge_type, hostname, user.clone(), token, repos); - assert_eq!(fc.user(), config::User::new(user)); + assert_eq!(fc.user(), User::new(user)); } #[test] fn should_return_token() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); let repos = BTreeMap::new(); - let fc = config::ForgeConfig::new(forge_type, hostname, user, token.clone(), repos); + let fc = ForgeConfig::new(forge_type, hostname, user, token.clone(), repos); assert_eq!(fc.token().expose_secret(), token.as_str()); } #[test] fn should_return_repo() { - let forge_type = config::ForgeType::MockForge; + let forge_type = ForgeType::MockForge; let hostname = given::a_name(); let user = given::a_name(); let token = given::a_name(); let red_name = given::a_name(); let blue_name = given::a_name(); - let red = - config::ServerRepoConfig::new(red_name.clone(), given::a_name(), None, None, None, None); - let blue = - config::ServerRepoConfig::new(blue_name.clone(), given::a_name(), None, None, None, None); + let red = ServerRepoConfig::new(red_name.clone(), given::a_name(), None, None, None, None); + let blue = ServerRepoConfig::new(blue_name.clone(), given::a_name(), None, None, None, None); let mut repos = BTreeMap::new(); repos.insert(red_name.clone(), red.clone()); repos.insert(blue_name, blue); - let fc = config::ForgeConfig::new(forge_type, hostname, user, token, repos); + let fc = ForgeConfig::new(forge_type, hostname, user, token, repos); let returned_repo = fc.get_repo(red_name.as_str()); diff --git a/crates/git/src/repository/open/tests/mod.rs b/crates/git/src/repository/open/tests/mod.rs index d047cc3..12a53f4 100644 --- a/crates/git/src/repository/open/tests/mod.rs +++ b/crates/git/src/repository/open/tests/mod.rs @@ -1,14 +1,18 @@ // -use crate as git; +use crate::{ + self as git, + repository::RepositoryLike as _, + tests::{given, then}, +}; +use git_next_core::{ + BranchName, ForgeConfig, ForgeType, GitDir, Hostname, RepoAlias, RepoBranches, RepoConfig, + RepoConfigSource, RepoPath, ServerRepoConfig, StoragePathType, User, +}; + use assert2::let_assert; -use config::GitDir; -use git::repository::RepositoryLike as _; -use git::tests::given; -use git::tests::then; -use git_next_config as config; use secrecy::ExposeSecret; -use std::collections::BTreeMap; -use std::path::PathBuf; + +use std::{collections::BTreeMap, path::PathBuf}; type TestResult = Result<(), Box>; diff --git a/crates/git/src/repository/open/tests/read_file.rs b/crates/git/src/repository/open/tests/read_file.rs index aee1ecd..375ac29 100644 --- a/crates/git/src/repository/open/tests/read_file.rs +++ b/crates/git/src/repository/open/tests/read_file.rs @@ -1,3 +1,4 @@ +// use super::*; #[test] @@ -7,10 +8,7 @@ fn should_return_file() -> TestResult { let repo_config = given::a_repo_config(); let file_name = given::a_pathbuf(); let contents = given::a_name(); - let gitdir = GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let test_repository = git::repository::test(fs.clone()); let_assert!(Ok(open_repository) = test_repository.open(&gitdir)); @@ -34,10 +32,7 @@ fn should_return_file() -> TestResult { // assumes running in the git-next repo which should have main, next and dev as remote branches fn should_error_on_missing_file() -> TestResult { let_assert!(Ok(fs) = kxio::fs::temp()); - let gitdir = GitDir::new( - fs.base().to_path_buf(), - config::git_dir::StoragePathType::Internal, - ); + let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let test_repository = git::repository::test(fs.clone()); let_assert!(Ok(open_repository) = test_repository.open(&gitdir)); let repo_config = &given::a_repo_config(); diff --git a/crates/git/src/repository/open/tests/repo_config.rs b/crates/git/src/repository/open/tests/repo_config.rs index 9017333..16ddec2 100644 --- a/crates/git/src/repository/open/tests/repo_config.rs +++ b/crates/git/src/repository/open/tests/repo_config.rs @@ -1,3 +1,4 @@ +// use super::*; #[test] @@ -14,13 +15,13 @@ fn should_parse_toml() -> TestResult { "# ); - let rc = config::RepoConfig::parse(toml.as_str())?; + let rc = RepoConfig::parse(toml.as_str())?; assert_eq!( rc, - config::RepoConfig::new( - config::RepoBranches::new(main, next, dev), - config::RepoConfigSource::Repo // reading from repo is the default + RepoConfig::new( + RepoBranches::new(main, next, dev), + RepoConfigSource::Repo // reading from repo is the default ) ); @@ -31,8 +32,8 @@ fn should_return_branches() { let main = given::a_name(); let next = given::a_name(); let dev = given::a_name(); - let branches = config::RepoBranches::new(main, next, dev); - let repo_config = config::RepoConfig::new(branches.clone(), config::RepoConfigSource::Repo); + let branches = RepoBranches::new(main, next, dev); + let repo_config = RepoConfig::new(branches.clone(), RepoConfigSource::Repo); assert_eq!(repo_config.branches(), &branches); } @@ -41,10 +42,7 @@ fn should_return_source() { let main = given::a_name(); let next = given::a_name(); let dev = given::a_name(); - let repo_config = config::RepoConfig::new( - config::RepoBranches::new(main, next, dev), - config::RepoConfigSource::Repo, - ); + let repo_config = RepoConfig::new(RepoBranches::new(main, next, dev), RepoConfigSource::Repo); - assert_eq!(repo_config.source(), config::RepoConfigSource::Repo); + assert_eq!(repo_config.source(), RepoConfigSource::Repo); } diff --git a/crates/git/src/repository/open/tests/server_repo_config.rs b/crates/git/src/repository/open/tests/server_repo_config.rs index 6a49193..4bd2237 100644 --- a/crates/git/src/repository/open/tests/server_repo_config.rs +++ b/crates/git/src/repository/open/tests/server_repo_config.rs @@ -1,3 +1,4 @@ +// use super::*; #[test] @@ -5,8 +6,7 @@ fn should_not_return_repo_config_when_no_branches() { let main = None; let next = None; let dev = None; - let src = - config::ServerRepoConfig::new(given::a_name(), given::a_name(), None, main, next, dev); + let src = ServerRepoConfig::new(given::a_name(), given::a_name(), None, main, next, dev); let_assert!(None = src.repo_config()); } @@ -16,7 +16,7 @@ fn should_return_repo_config_when_branches() { let main = given::a_name(); let next = given::a_name(); let dev = given::a_name(); - let src = config::ServerRepoConfig::new( + let src = ServerRepoConfig::new( given::a_name(), given::a_name(), None, @@ -28,17 +28,14 @@ fn should_return_repo_config_when_branches() { let_assert!(Some(rc) = src.repo_config()); assert_eq!( rc, - config::RepoConfig::new( - config::RepoBranches::new(main, next, dev), - config::RepoConfigSource::Server - ) + RepoConfig::new(RepoBranches::new(main, next, dev), RepoConfigSource::Server) ); } #[test] fn should_return_repo() { let repo_path = given::a_name(); - let src = config::ServerRepoConfig::new( + let src = ServerRepoConfig::new( repo_path.clone(), given::a_name(), None, @@ -47,13 +44,13 @@ fn should_return_repo() { Some(given::a_name()), ); - assert_eq!(src.repo(), config::RepoPath::new(repo_path)); + assert_eq!(src.repo(), RepoPath::new(repo_path)); } #[test] fn should_return_branch() { let branch = given::a_name(); - let src = config::ServerRepoConfig::new( + let src = ServerRepoConfig::new( given::a_name(), branch.clone(), None, @@ -62,13 +59,13 @@ fn should_return_branch() { Some(given::a_name()), ); - assert_eq!(src.branch(), config::BranchName::new(branch)); + assert_eq!(src.branch(), BranchName::new(branch)); } #[test] fn should_return_gitdir() { let gitdir = given::a_name(); - let src = config::ServerRepoConfig::new( + let src = ServerRepoConfig::new( given::a_name(), given::a_name(), Some(gitdir.clone().into()), @@ -81,7 +78,7 @@ fn should_return_gitdir() { src.gitdir(), Some(GitDir::new( PathBuf::default().join(gitdir), - config::StoragePathType::External, + StoragePathType::External, )) ); } diff --git a/crates/git/src/repository/test.rs b/crates/git/src/repository/test.rs index e9f0e5a..da1cb52 100644 --- a/crates/git/src/repository/test.rs +++ b/crates/git/src/repository/test.rs @@ -1,9 +1,18 @@ // use derive_more::Constructor; -use crate as git; -use git::repository::RepositoryLike; -use git_next_config as config; +use crate::{ + self as git, + repository::{ + open::{ + otest::{OnFetch, OnPush}, + OpenRepository, + }, + RepositoryLike, Result, + }, + RepoDetails, +}; +use git_next_core::GitDir; #[derive(Clone, Debug, Constructor)] pub struct TestRepository { @@ -12,16 +21,16 @@ pub struct TestRepository { on_push: Vec, } impl TestRepository { - pub fn on_fetch(&mut self, on_fetch: git::repository::OnFetch) { + pub fn on_fetch(&mut self, on_fetch: OnFetch) { self.on_fetch.push(on_fetch); } - pub fn on_push(&mut self, on_push: git::repository::OnPush) { + pub fn on_push(&mut self, on_push: OnPush) { self.on_push.push(on_push); } } impl RepositoryLike for TestRepository { - fn open(&self, gitdir: &config::GitDir) -> super::Result { + fn open(&self, gitdir: &GitDir) -> Result { Ok(git::repository::open::test( gitdir, self.fs.clone(), @@ -30,10 +39,7 @@ impl RepositoryLike for TestRepository { )) } - fn git_clone( - &self, - _repo_details: &crate::RepoDetails, - ) -> super::Result { + fn git_clone(&self, _repo_details: &RepoDetails) -> Result { todo!() } } diff --git a/crates/git/src/repository/tests/factory.rs b/crates/git/src/repository/tests/factory.rs index 76e06cc..7c75b40 100644 --- a/crates/git/src/repository/tests/factory.rs +++ b/crates/git/src/repository/tests/factory.rs @@ -1,9 +1,6 @@ -use git_next_config::{ApiToken, GitDir, StoragePathType}; - +// use super::*; -use crate::tests::given; - // clone - can't test are this required a remote server (git_clone only works with https origins) // open // - outside storage path diff --git a/crates/git/src/repository/tests/mod.rs b/crates/git/src/repository/tests/mod.rs index a4dec8b..64af3e6 100644 --- a/crates/git/src/repository/tests/mod.rs +++ b/crates/git/src/repository/tests/mod.rs @@ -1,4 +1,7 @@ -use crate as git; +// +use crate::{self as git, tests::given}; +use git_next_core::{ApiToken, GitDir, StoragePathType}; + use assert2::let_assert; mod factory; diff --git a/crates/git/src/tests.rs b/crates/git/src/tests.rs index 9bbe2f5..20181d9 100644 --- a/crates/git/src/tests.rs +++ b/crates/git/src/tests.rs @@ -1,7 +1,20 @@ -#![allow(dead_code)] +// +use crate::{self as git, Generation, GitRef, GitRemote, RepoDetails}; +use git_next_core::{ + git_dir::StoragePathType, webhook, BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, + Hostname, RemoteUrl, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, RepoPath, + ServerRepoConfig, +}; -use crate as git; -use git_next_config as config; +use assert2::let_assert; +use secrecy::ExposeSecret; + +use std::{ + collections::BTreeMap, + path::{Path, PathBuf}, +}; + +type TestResult = Result<(), Box>; mod commit { use super::*; @@ -36,7 +49,7 @@ mod commit { } } mod generation { - use crate::Generation; + use super::*; #[test] fn should_increment() { @@ -49,12 +62,13 @@ mod generation { } } mod gitref { - use crate::{commit, Commit, GitRef}; + use super::*; + #[test] fn should_convert_from_commit() { - let commit = Commit::new( - commit::Sha::new("sha".to_string()), - commit::Message::new("message".to_string()), + let commit = git::Commit::new( + git::commit::Sha::new("sha".to_string()), + git::commit::Message::new("message".to_string()), ); let gitref = GitRef::from(commit); @@ -62,9 +76,8 @@ mod gitref { } } mod gitremote { - use git_next_config::{Hostname, RepoPath}; - use crate::GitRemote; + use super::*; #[test] fn should_return_hostname() { @@ -85,7 +98,6 @@ mod gitremote { } mod push { use super::*; - use crate::GitRef; #[test] fn force_no_should_display() { @@ -104,8 +116,6 @@ mod push { mod reset { use super::*; - use crate::tests::given; - use assert2::let_assert; #[test] fn should_perform_a_fetch_then_push() { @@ -141,15 +151,7 @@ mod push { } mod repo_details { - use std::{collections::BTreeMap, path::PathBuf}; - - use git_next_config::{ - git_dir::StoragePathType, ForgeAlias, ForgeConfig, ForgeType, GitDir, Hostname, RepoAlias, - RepoPath, ServerRepoConfig, - }; - use secrecy::ExposeSecret; - - use crate::{Generation, GitRemote, RepoDetails}; + use super::*; #[test] fn should_return_origin() { @@ -214,15 +216,7 @@ mod repo_details { } } pub mod given { - use std::path::{Path, PathBuf}; - - use crate::{self as git, repository::open::MockOpenRepositoryLike}; - use config::{ - BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, RepoAlias, RepoBranches, - RepoConfig, ServerRepoConfig, - }; - use git::{tests::given, RepoDetails}; - use git_next_config as config; + use super::*; pub fn repo_branches() -> RepoBranches { RepoBranches::new( @@ -264,7 +258,7 @@ pub mod given { pub fn a_git_dir(fs: &kxio::fs::FileSystem) -> GitDir { let dir_name = a_name(); let dir = fs.base().join(dir_name); - GitDir::new(dir, config::git_dir::StoragePathType::Internal) + GitDir::new(dir, StoragePathType::Internal) } pub fn a_forge_config() -> ForgeConfig { @@ -292,7 +286,7 @@ pub mod given { } pub fn a_repo_config() -> RepoConfig { - RepoConfig::new(given::repo_branches(), config::RepoConfigSource::Repo) + RepoConfig::new(given::repo_branches(), RepoConfigSource::Repo) } pub fn a_commit() -> git::Commit { @@ -315,35 +309,17 @@ pub mod given { git::commit::Sha::new(a_name()) } - pub fn a_webhook_push( - sha: &git::commit::Sha, - message: &git::commit::Message, - ) -> config::webhook::Push { + pub fn a_webhook_push(sha: &git::commit::Sha, message: &git::commit::Message) -> webhook::Push { let branch = a_branch_name(); - config::webhook::Push::new(branch, sha.to_string(), message.to_string()) + webhook::Push::new(branch, sha.to_string(), message.to_string()) } pub fn a_filesystem() -> kxio::fs::FileSystem { kxio::fs::temp().unwrap_or_else(|e| panic!("{}", e)) } - pub fn an_open_repository( - fs: &kxio::fs::FileSystem, - ) -> ( - git::repository::open::MockOpenRepositoryLike, - git::RepoDetails, - ) { - let open_repository = MockOpenRepositoryLike::new(); - let gitdir = given::a_git_dir(fs); - let hostname = given::a_hostname(); - let repo_details = given::repo_details(fs) - .with_gitdir(gitdir) - .with_hostname(hostname); - (open_repository, repo_details) - } - - pub fn a_hostname() -> config::Hostname { - config::Hostname::new(given::a_name()) + pub fn a_hostname() -> Hostname { + Hostname::new(given::a_name()) } pub fn repo_details(fs: &kxio::fs::FileSystem) -> git::RepoDetails { @@ -363,13 +339,6 @@ pub mod given { ) } - pub fn a_git_remote() -> git::GitRemote { - git::GitRemote::new( - config::Hostname::new(given::a_name()), - config::RepoPath::new(given::a_name()), - ) - } - #[allow(clippy::unwrap_used)] pub fn a_bare_repo_with_url(path: &Path, url: &str, fs: &kxio::fs::FileSystem) { // create a basic bare repo @@ -389,17 +358,14 @@ pub mod given { } #[allow(clippy::unwrap_used)] - pub fn a_remote_url() -> git_next_config::RemoteUrl { + pub fn a_remote_url() -> RemoteUrl { let hostname = given::a_hostname(); let owner = given::a_name(); let repo = given::a_name(); - git_next_config::RemoteUrl::parse(format!("git@{hostname}:{owner}/{repo}.git")).unwrap() + RemoteUrl::parse(format!("git@{hostname}:{owner}/{repo}.git")).unwrap() } } pub mod then { - use std::path::{Path, PathBuf}; - - type TestResult = Result<(), Box>; use super::*; @@ -407,8 +373,8 @@ pub mod then { file_name: &Path, contents: &str, fs: &kxio::fs::FileSystem, - gitdir: &config::GitDir, - branch_name: &config::BranchName, + gitdir: &GitDir, + branch_name: &BranchName, ) -> TestResult { // git checkout ${branch_name} git_checkout_new_branch(branch_name, gitdir)?; @@ -429,8 +395,8 @@ pub mod then { pub fn create_a_commit_on_branch( fs: &kxio::fs::FileSystem, - gitdir: &config::GitDir, - branch_name: &config::BranchName, + gitdir: &GitDir, + branch_name: &BranchName, ) -> TestResult { // git checkout ${branch_name} git_checkout_new_branch(branch_name, gitdir)?; @@ -451,8 +417,8 @@ pub mod then { fn push_branch( fs: &kxio::fs::FileSystem, - gitdir: &config::GitDir, - branch_name: &config::BranchName, + gitdir: &GitDir, + branch_name: &BranchName, ) -> TestResult { let gitrefs = fs .base() @@ -468,10 +434,7 @@ pub mod then { Ok(()) } - pub fn git_checkout_new_branch( - branch_name: &git_next_config::BranchName, - gitdir: &git_next_config::GitDir, - ) -> TestResult { + pub fn git_checkout_new_branch(branch_name: &BranchName, gitdir: &GitDir) -> TestResult { exec( format!("git checkout -b {}", branch_name), std::process::Command::new("/usr/bin/git") @@ -482,10 +445,7 @@ pub mod then { Ok(()) } - pub fn git_switch( - branch_name: &git_next_config::BranchName, - gitdir: &git_next_config::GitDir, - ) -> TestResult { + pub fn git_switch(branch_name: &BranchName, gitdir: &GitDir) -> TestResult { exec( format!("git switch {}", branch_name), std::process::Command::new("/usr/bin/git") @@ -517,7 +477,7 @@ pub mod then { } } - fn git_add_file(gitdir: &git_next_config::GitDir, file: &Path) -> TestResult { + fn git_add_file(gitdir: &GitDir, file: &Path) -> TestResult { exec( format!("git add {file:?}"), std::process::Command::new("/usr/bin/git") @@ -527,7 +487,7 @@ pub mod then { ) } - fn git_commit(gitdir: &git_next_config::GitDir, file: &Path) -> TestResult { + fn git_commit(gitdir: &GitDir, file: &Path) -> TestResult { exec( format!(r#"git commit -m"Added {file:?}""#), std::process::Command::new("/usr/bin/git") @@ -540,7 +500,7 @@ pub mod then { ) } - pub fn git_log_all(gitdir: &config::GitDir) -> TestResult { + pub fn git_log_all(gitdir: &GitDir) -> TestResult { exec( "git log --all --oneline --decorate --graph".to_string(), std::process::Command::new("/usr/bin/git") @@ -552,8 +512,8 @@ pub mod then { pub fn get_sha_for_branch( fs: &kxio::fs::FileSystem, - gitdir: &git_next_config::GitDir, - branch_name: &git_next_config::BranchName, + gitdir: &GitDir, + branch_name: &BranchName, ) -> Result> { let main_ref = fs .base() diff --git a/crates/git/src/user_notification.rs b/crates/git/src/user_notification.rs index 624e0f0..73bd857 100644 --- a/crates/git/src/user_notification.rs +++ b/crates/git/src/user_notification.rs @@ -1,5 +1,7 @@ +// use crate::Commit; -use git_next_config::{BranchName, ForgeAlias, RepoAlias}; + +use git_next_core::{BranchName, ForgeAlias, RepoAlias}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum UserNotification { diff --git a/crates/git/src/validation/positions.rs b/crates/git/src/validation/positions.rs index 247b37b..7cef3a2 100644 --- a/crates/git/src/validation/positions.rs +++ b/crates/git/src/validation/positions.rs @@ -1,6 +1,6 @@ // -use crate::{self as git, UserNotification}; -use git_next_config as config; +use crate::{self as git, repository::open::OpenRepositoryLike, RepoDetails, UserNotification}; +use git_next_core::{BranchName, RepoConfig}; pub type Result = core::result::Result; @@ -13,9 +13,9 @@ pub struct Positions { } pub fn validate_positions( - open_repository: &dyn git::repository::OpenRepositoryLike, + open_repository: &dyn OpenRepositoryLike, repo_details: &git::RepoDetails, - repo_config: config::RepoConfig, + repo_config: RepoConfig, ) -> Result { let main_branch = repo_config.branches().main(); let next_branch = repo_config.branches().next(); @@ -77,11 +77,11 @@ pub fn validate_positions( } fn reset_next_to_main( - open_repository: &dyn crate::repository::OpenRepositoryLike, - repo_details: &crate::RepoDetails, - main: &crate::Commit, - next: &crate::Commit, - next_branch: &config::BranchName, + open_repository: &dyn OpenRepositoryLike, + repo_details: &RepoDetails, + main: &git::Commit, + next: &git::Commit, + next_branch: &BranchName, ) -> Result { git::push::reset( open_repository, @@ -105,8 +105,8 @@ fn is_not_based_on(commits: &[crate::commit::Commit], needle: &crate::Commit) -> } fn get_commit_histories( - open_repository: &dyn git::repository::OpenRepositoryLike, - repo_config: &config::RepoConfig, + open_repository: &dyn OpenRepositoryLike, + repo_config: &RepoConfig, ) -> git::commit::log::Result { let main = (open_repository.commit_log(&repo_config.branches().main(), &[]))?; let main_head = [main[0].clone()]; diff --git a/crates/git/src/validation/remotes.rs b/crates/git/src/validation/remotes.rs index fb325dd..45fe76d 100644 --- a/crates/git/src/validation/remotes.rs +++ b/crates/git/src/validation/remotes.rs @@ -1,11 +1,12 @@ -use git_next_config::RemoteUrl; -use tracing::info; +// +use crate::{self as git, repository::open::OpenRepositoryLike}; +use git_next_core::RemoteUrl; -use crate as git; +use tracing::info; #[tracing::instrument(skip_all)] pub fn validate_default_remotes( - open_repository: &dyn git::repository::OpenRepositoryLike, + open_repository: &dyn OpenRepositoryLike, repo_details: &git::RepoDetails, ) -> Result<()> { let push_remote = open_repository diff --git a/crates/git/src/validation/tests.rs b/crates/git/src/validation/tests.rs index 4430fdd..47927f4 100644 --- a/crates/git/src/validation/tests.rs +++ b/crates/git/src/validation/tests.rs @@ -1,19 +1,23 @@ // -use crate as git; - -use git::repository::RepositoryFactory as _; -use git::repository::RepositoryLike as _; -use git::tests::given; -use git_next_config as config; +use crate::{ + self as git, + repository::{ + open::otest::{OnFetch, OnPush}, + Direction, + }, + tests::then, +}; +use git::{ + repository::{factory::RepositoryFactory as _, RepositoryLike as _}, + tests::given, + validation::positions::validate_positions, +}; +use git_next_core::{GitDir, StoragePathType}; use assert2::let_assert; mod repos { - use config::{git_dir::StoragePathType, GitDir}; - - use crate::repository::Direction; - use super::*; #[test] @@ -51,11 +55,6 @@ mod positions { mod validate_positions { - use config::{git_dir::StoragePathType, GitDir}; - use git::validation::positions::validate_positions; - - use git::tests::then; - use super::*; #[test] @@ -211,7 +210,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -261,7 +260,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -285,7 +284,7 @@ mod positions { }, )); // second fetch as prep to push - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -294,7 +293,7 @@ mod positions { git::fetch::Result::Ok(()) }, )); - test_repository.on_push(git::repository::OnPush::new( + test_repository.on_push(OnPush::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -347,7 +346,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -371,7 +370,7 @@ mod positions { }, )); // second fetch as prep to push - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -380,7 +379,7 @@ mod positions { git::fetch::Result::Ok(()) }, )); - test_repository.on_push(git::repository::OnPush::new( + test_repository.on_push(OnPush::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -420,7 +419,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -442,7 +441,7 @@ mod positions { }, )); // second fetch as prep to push - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -451,7 +450,7 @@ mod positions { git::fetch::Result::Ok(()) }, )); - test_repository.on_push(git::repository::OnPush::new( + test_repository.on_push(OnPush::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -504,7 +503,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -526,7 +525,7 @@ mod positions { }, )); // second fetch as prep to push - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -535,7 +534,7 @@ mod positions { git::fetch::Result::Ok(()) }, )); - test_repository.on_push(git::repository::OnPush::new( + test_repository.on_push(OnPush::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), @@ -575,7 +574,7 @@ mod positions { let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); let mut test_repository = git::repository::test(fs.clone()); let repo_config = given::a_repo_config(); - test_repository.on_fetch(git::repository::OnFetch::new( + test_repository.on_fetch(OnFetch::new( repo_config.branches().clone(), gitdir.clone(), fs.clone(), diff --git a/crates/repo-actor/Cargo.toml b/crates/repo-actor/Cargo.toml index b342671..b8f5617 100644 --- a/crates/repo-actor/Cargo.toml +++ b/crates/repo-actor/Cargo.toml @@ -13,7 +13,6 @@ github = [] [dependencies] git-next-core = { workspace = true } -git-next-config = { workspace = true } git-next-git = { workspace = true } git-next-forge = { workspace = true } diff --git a/crates/repo-actor/src/branch.rs b/crates/repo-actor/src/branch.rs index 57c0aff..68a4cea 100644 --- a/crates/repo-actor/src/branch.rs +++ b/crates/repo-actor/src/branch.rs @@ -1,7 +1,7 @@ // use crate::messages::MessageToken; -use git_next_config as config; -use git_next_git as git; +use git_next_core::RepoConfig; +use git_next_git::{self as git, repository::open::OpenRepositoryLike}; use derive_more::Display; use tracing::{info, warn}; @@ -12,8 +12,8 @@ pub fn advance_next( next: &git::Commit, dev_commit_history: &[git::Commit], repo_details: git::RepoDetails, - repo_config: config::RepoConfig, - open_repository: &dyn git::repository::OpenRepositoryLike, + repo_config: RepoConfig, + open_repository: &dyn OpenRepositoryLike, message_token: MessageToken, ) -> Result { let commit = @@ -69,8 +69,8 @@ pub fn find_next_commit_on_dev( pub fn advance_main( next: git::Commit, repo_details: &git::RepoDetails, - repo_config: &config::RepoConfig, - open_repository: &dyn git::repository::OpenRepositoryLike, + repo_config: &RepoConfig, + open_repository: &dyn OpenRepositoryLike, ) -> Result<()> { info!("Advancing main to next"); git::push::reset( diff --git a/crates/repo-actor/src/handlers/advance_main.rs b/crates/repo-actor/src/handlers/advance_main.rs index 9efb10c..0d161cd 100644 --- a/crates/repo-actor/src/handlers/advance_main.rs +++ b/crates/repo-actor/src/handlers/advance_main.rs @@ -1,6 +1,7 @@ // use crate as actor; use actix::prelude::*; +use git_next_core::RepoConfigSource; impl Handler for actor::RepoActor { type Result = (); @@ -31,10 +32,10 @@ impl Handler for actor::RepoActor { tracing::warn!("advance main: {err}"); } Ok(_) => match repo_config.source() { - git_next_config::RepoConfigSource::Repo => { + RepoConfigSource::Repo => { actor::do_send(addr, actor::messages::LoadConfigFromRepo, self.log.as_ref()); } - git_next_config::RepoConfigSource::Server => { + RepoConfigSource::Server => { actor::do_send( addr, actor::messages::ValidateRepo::new(message_token), diff --git a/crates/repo-actor/src/handlers/webhook_notification.rs b/crates/repo-actor/src/handlers/webhook_notification.rs index 4c6be74..5eb4727 100644 --- a/crates/repo-actor/src/handlers/webhook_notification.rs +++ b/crates/repo-actor/src/handlers/webhook_notification.rs @@ -2,10 +2,9 @@ use actix::prelude::*; use crate::{self as actor, messages::WebhookNotification, RepoActorLog}; -use git_next_config::WebhookAuth; -use git_next_config::{ +use git_next_core::{ webhook::{push::Branch, Push}, - BranchName, + BranchName, WebhookAuth, }; use git_next_git::{self as git, Commit, ForgeLike}; diff --git a/crates/repo-actor/src/lib.rs b/crates/repo-actor/src/lib.rs index 37767d7..959d97b 100644 --- a/crates/repo-actor/src/lib.rs +++ b/crates/repo-actor/src/lib.rs @@ -1,3 +1,19 @@ +// +use actix::prelude::*; + +use derive_more::Deref; +use kxio::network::Network; +use messages::NotifyUser; +use std::time::Duration; +use tracing::{info, warn, Instrument}; + +use git_next_core::{server, WebhookAuth, WebhookId}; +use git_next_git::{ + self as git, + repository::{factory::RepositoryFactory, open::OpenRepositoryLike}, + UserNotification, +}; + mod branch; pub mod handlers; mod load; @@ -7,18 +23,6 @@ mod notifications; #[cfg(test)] mod tests; -use std::time::Duration; - -use actix::prelude::*; - -use derive_more::Deref; -use git_next_config as config; -use git_next_git::{self as git, UserNotification}; -use messages::NotifyUser; - -use kxio::network::Network; -use tracing::{info, warn, Instrument}; - #[derive(Clone, Debug, Default)] pub struct RepoActorLog(std::sync::Arc>>); impl Deref for RepoActorLog { @@ -39,14 +43,14 @@ pub struct RepoActor { generation: git::Generation, message_token: messages::MessageToken, repo_details: git::RepoDetails, - webhook: config::server::InboundWebhook, - webhook_id: Option, // INFO: if [None] then no webhook is configured - webhook_auth: Option, // INFO: if [None] then no webhook is configured + webhook: server::InboundWebhook, + webhook_id: Option, // INFO: if [None] then no webhook is configured + webhook_auth: Option, // INFO: if [None] then no webhook is configured last_main_commit: Option, last_next_commit: Option, last_dev_commit: Option, - repository_factory: Box, - open_repository: Option>, + repository_factory: Box, + open_repository: Option>, net: Network, forge: Box, log: Option, @@ -57,10 +61,10 @@ impl RepoActor { pub fn new( repo_details: git::RepoDetails, forge: Box, - webhook: config::server::InboundWebhook, + webhook: server::InboundWebhook, generation: git::Generation, net: Network, - repository_factory: Box, + repository_factory: Box, sleep_duration: std::time::Duration, notify_user_recipient: Option>, ) -> Self { diff --git a/crates/repo-actor/src/load.rs b/crates/repo-actor/src/load.rs index 989bd00..640a589 100644 --- a/crates/repo-actor/src/load.rs +++ b/crates/repo-actor/src/load.rs @@ -1,21 +1,22 @@ // -use derive_more::Display; -use std::path::PathBuf; -use tracing::info; +use git_next_core::{server, BranchName, RepoConfig}; +use git_next_git::{self as git, repository::open::OpenRepositoryLike}; -use git_next_config as config; -use git_next_git as git; +use std::path::PathBuf; + +use derive_more::Display; +use tracing::info; /// Loads the [RepoConfig] from the `.git-next.toml` file in the repository #[tracing::instrument(skip_all, fields(branch = %repo_details.branch))] pub async fn config_from_repository( repo_details: git::RepoDetails, - open_repository: &dyn git::repository::OpenRepositoryLike, -) -> Result { + open_repository: &dyn OpenRepositoryLike, +) -> Result { info!("Loading .git-next.toml from repo"); let contents = open_repository.read_file(&repo_details.branch, &PathBuf::from(".git-next.toml"))?; - let config = config::RepoConfig::parse(&contents)?; + let config = RepoConfig::parse(&contents)?; let branches = open_repository.remote_branches()?; required_branch(&config.branches().main(), &branches)?; required_branch(&config.branches().next(), &branches)?; @@ -23,10 +24,7 @@ pub async fn config_from_repository( Ok(config) } -fn required_branch( - branch_name: &config::BranchName, - branches: &[config::BranchName], -) -> Result<()> { +fn required_branch(branch_name: &BranchName, branches: &[BranchName]) -> Result<()> { branches .iter() .find(|branch| *branch == branch_name) @@ -41,7 +39,7 @@ pub enum Error { File(#[from] git::file::Error), #[display("config")] - Config(#[from] config::server::Error), + Config(#[from] server::Error), #[display("toml")] Toml(#[from] toml::de::Error), @@ -50,5 +48,5 @@ pub enum Error { Push(#[from] git::push::Error), #[display("branch not found: {}", 0)] - BranchNotFound(config::BranchName), + BranchNotFound(BranchName), } diff --git a/crates/repo-actor/src/messages.rs b/crates/repo-actor/src/messages.rs index 4fe760b..663a89f 100644 --- a/crates/repo-actor/src/messages.rs +++ b/crates/repo-actor/src/messages.rs @@ -1,15 +1,16 @@ // -use config::newtype; use derive_more::Display; use git::UserNotification; -use git_next_config as config; -use git_next_core::message; use git_next_git as git; +use git_next_core::{ + message, newtype, webhook, RegisteredWebhook, RepoConfig, WebhookAuth, WebhookId, +}; + message!(LoadConfigFromRepo: "Request to load the `git-next.toml` from the git repo."); message!(CloneRepo: "Request to clone (or open) the git repo."); -message!(ReceiveRepoConfig: config::RepoConfig: r#"Notification that the `git-next.toml` file has been loaded from the repo and parsed. +message!(ReceiveRepoConfig: RepoConfig: r#"Notification that the `git-next.toml` file has been loaded from the repo and parsed. Contains the parsed contents of the `git-next.toml` file."#); message!(ValidateRepo: MessageToken: r#"Request that the state of the branches in the git repo be assessed and generate any followup actions. @@ -19,20 +20,20 @@ This is the main function of `git-next` where decisions are made on what branche Contains a [MessageToken] to reduce duplicate messages being sent. Only messages with the latest [MessageToken] are handled, all others are dropped."#); -message!(WebhookRegistered: (config::WebhookId, config::WebhookAuth): r#"Notification that a webhook has been registered with a forge. +message!(WebhookRegistered: (WebhookId, WebhookAuth): r#"Notification that a webhook has been registered with a forge. Contains a tuple of the ID for the webhook returned from the forge, and the unique authorisation token that incoming messages from the forge must provide."#); impl WebhookRegistered { - pub const fn webhook_id(&self) -> &config::WebhookId { + pub const fn webhook_id(&self) -> &WebhookId { &self.0 .0 } - pub const fn webhook_auth(&self) -> &config::WebhookAuth { + pub const fn webhook_auth(&self) -> &WebhookAuth { &self.0 .1 } } -impl From for WebhookRegistered { - fn from(value: config::RegisteredWebhook) -> Self { +impl From for WebhookRegistered { + fn from(value: RegisteredWebhook) -> Self { let webhook_id = value.id().clone(); let webhook_auth = value.auth().clone(); Self::from((webhook_id, webhook_auth)) @@ -63,5 +64,5 @@ message!(ReceiveCIStatus: (git::Commit, git::forge::commit::Status): r#"Notifica Contains a tuple of the commit that was checked (the tip of the `next` branch) and the status."#); // commit and it's status message!(AdvanceNext: (git::Commit, Vec): "Request to advance the `next` branch on to the next commit on the `dev branch."); // next commit and the dev commit history message!(AdvanceMain: git::Commit: "Request to advance the `main` branch on to same commit as the `next` branch."); // next commit -message!(WebhookNotification: config::webhook::forge_notification::ForgeNotification: "Notification of a webhook message from the forge."); +message!(WebhookNotification: webhook::forge_notification::ForgeNotification: "Notification of a webhook message from the forge."); message!(NotifyUser: UserNotification: "Request to send the message payload to the notification webhook"); diff --git a/crates/repo-actor/src/tests/expect.rs b/crates/repo-actor/src/tests/expect.rs index c63b64a..055d1d2 100644 --- a/crates/repo-actor/src/tests/expect.rs +++ b/crates/repo-actor/src/tests/expect.rs @@ -1,9 +1,6 @@ // use super::*; -use git::repository::factory::MockRepositoryFactory; -use git_next_git::repository::open::MockOpenRepositoryLike; - pub fn fetch_ok(open_repository: &mut MockOpenRepositoryLike) { expect::fetch(open_repository, Ok(())); } @@ -38,7 +35,7 @@ pub fn open_repository( pub fn main_commit_log( validation_repo: &mut MockOpenRepositoryLike, - main_branch: config::BranchName, + main_branch: BranchName, ) -> git::Commit { let main_commit = given::a_commit(); let main_branch_log = vec![main_commit.clone()]; diff --git a/crates/repo-actor/src/tests/given.rs b/crates/repo-actor/src/tests/given.rs index 44a8aa8..319f370 100644 --- a/crates/repo-actor/src/tests/given.rs +++ b/crates/repo-actor/src/tests/given.rs @@ -1,6 +1,3 @@ -use config::git_dir::StoragePathType; -use git_next_config::RemoteUrl; - // use super::*; @@ -53,11 +50,8 @@ pub fn a_network() -> kxio::network::MockNetwork { kxio::network::MockNetwork::new() } -pub fn a_webhook_url( - forge_alias: &ForgeAlias, - repo_alias: &RepoAlias, -) -> git_next_config::server::WebhookUrl { - config::server::InboundWebhook::new(a_name()).url(forge_alias, repo_alias) +pub fn a_webhook_url(forge_alias: &ForgeAlias, repo_alias: &RepoAlias) -> WebhookUrl { + InboundWebhook::new(a_name()).url(forge_alias, repo_alias) } pub fn a_name() -> String { @@ -112,7 +106,7 @@ pub fn a_server_repo_config() -> ServerRepoConfig { } pub fn a_repo_config() -> RepoConfig { - RepoConfig::new(given::repo_branches(), config::RepoConfigSource::Repo) + RepoConfig::new(given::repo_branches(), RepoConfigSource::Repo) } pub fn a_named_commit(name: impl Into) -> git::Commit { @@ -189,7 +183,7 @@ pub fn a_forge() -> Box { pub fn a_repo_actor( repo_details: git::RepoDetails, - repository_factory: Box, + repository_factory: Box, forge: Box, net: kxio::network::Network, ) -> (actor::RepoActor, RepoActorLog) { @@ -216,16 +210,16 @@ pub fn a_repo_actor( ) } -pub fn a_hostname() -> config::Hostname { - config::Hostname::new(given::a_name()) +pub fn a_hostname() -> Hostname { + Hostname::new(given::a_name()) } pub fn a_registered_webhook() -> RegisteredWebhook { RegisteredWebhook::new(given::a_webhook_id(), given::a_webhook_auth()) } -pub fn a_push() -> config::webhook::Push { - config::webhook::Push::new( +pub fn a_push() -> webhook::Push { + webhook::Push::new( given::a_branch_name("push"), given::a_name(), given::a_name(), diff --git a/crates/repo-actor/src/tests/handlers/advance_main.rs b/crates/repo-actor/src/tests/handlers/advance_main.rs index c044388..e8f8e72 100644 --- a/crates/repo-actor/src/tests/handlers/advance_main.rs +++ b/crates/repo-actor/src/tests/handlers/advance_main.rs @@ -10,7 +10,7 @@ async fn when_repo_config_should_fetch_then_push_then_revalidate() -> TestResult // config from repo #[allow(clippy::unwrap_used)] let repo_config = repo_details.repo_config.take().unwrap(); - repo_details.repo_config = Some(repo_config.with_source(config::RepoConfigSource::Repo)); + repo_details.repo_config = Some(repo_config.with_source(RepoConfigSource::Repo)); let next_commit = given::a_commit_with_message("feat: next".to_string()); @@ -55,7 +55,7 @@ async fn when_server_config_should_fetch_then_push_then_revalidate() -> TestResu // config from server #[allow(clippy::unwrap_used)] let repo_config = repo_details.repo_config.take().unwrap(); - repo_details.repo_config = Some(repo_config.with_source(config::RepoConfigSource::Server)); + repo_details.repo_config = Some(repo_config.with_source(RepoConfigSource::Server)); let next_commit = given::a_commit_with_message("feat: next".to_string()); diff --git a/crates/repo-actor/src/tests/mod.rs b/crates/repo-actor/src/tests/mod.rs index 6c66dd5..e9c1521 100644 --- a/crates/repo-actor/src/tests/mod.rs +++ b/crates/repo-actor/src/tests/mod.rs @@ -1,25 +1,32 @@ // -use crate::{self as actor}; use actix::prelude::*; -use actor::{ + +use crate::{ + self as actor, messages::{CloneRepo, MessageToken}, RepoActor, RepoActorLog, }; -use assert2::let_assert; -use config::{ +use git_next_core::{ + message, server::{InboundWebhook, WebhookUrl}, - webhook::forge_notification::Body, - BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, RegisteredWebhook, - RepoAlias, RepoBranches, RepoConfig, ServerRepoConfig, WebhookAuth, WebhookId, + webhook::{self, forge_notification::Body}, + BranchName, ForgeAlias, ForgeConfig, ForgeNotification, ForgeType, GitDir, Hostname, + RegisteredWebhook, RemoteUrl, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, + ServerRepoConfig, StoragePathType, WebhookAuth, WebhookId, }; -use git::{ - repository::{factory::MockRepositoryFactory, open::MockOpenRepositoryLike, Direction}, +use git_next_git::{ + self as git, + repository::{ + factory::{MockRepositoryFactory, RepositoryFactory}, + open::{MockOpenRepositoryLike, OpenRepositoryLike}, + Direction, + }, Generation, MockForgeLike, RepoDetails, }; -use git_next_config as config; -use git_next_core::message; -use git_next_git as git; + +use assert2::let_assert; use mockall::predicate::eq; + use std::{ collections::{BTreeMap, HashMap}, sync::{Arc, RwLock}, @@ -82,9 +89,9 @@ pub struct RepoActorView { pub generation: git::Generation, pub message_token: MessageToken, pub repo_details: git::RepoDetails, - pub webhook: config::server::InboundWebhook, - pub webhook_id: Option, // INFO: if [None] then no webhook is configured - pub webhook_auth: Option, // INFO: if [None] then no webhook is configured + pub webhook: InboundWebhook, + pub webhook_id: Option, // INFO: if [None] then no webhook is configured + pub webhook_auth: Option, // INFO: if [None] then no webhook is configured pub last_main_commit: Option, pub last_next_commit: Option, pub last_dev_commit: Option, diff --git a/crates/repo-actor/src/tests/when.rs b/crates/repo-actor/src/tests/when.rs index 76a1d61..8f335ef 100644 --- a/crates/repo-actor/src/tests/when.rs +++ b/crates/repo-actor/src/tests/when.rs @@ -1,6 +1,4 @@ // -use git::repository::OpenRepositoryLike; - use super::*; pub fn start_actor( diff --git a/crates/server-actor/Cargo.toml b/crates/server-actor/Cargo.toml index 91d2424..684a1dd 100644 --- a/crates/server-actor/Cargo.toml +++ b/crates/server-actor/Cargo.toml @@ -8,7 +8,6 @@ description = "Server actor for git-next, the trunk-based development manager" [dependencies] git-next-core = { workspace = true } -git-next-config = { workspace = true } git-next-git = { workspace = true } git-next-forge = { workspace = true } git-next-repo-actor = { workspace = true } diff --git a/crates/server-actor/src/handlers/file_updated.rs b/crates/server-actor/src/handlers/file_updated.rs index 8eda627..1069552 100644 --- a/crates/server-actor/src/handlers/file_updated.rs +++ b/crates/server-actor/src/handlers/file_updated.rs @@ -1,6 +1,7 @@ //- use actix::prelude::*; -use git_next_config::server::ServerConfig; + +use git_next_core::server::ServerConfig; use git_next_file_watcher_actor::FileUpdated; use crate::{messages::ReceiveServerConfig, ServerActor}; diff --git a/crates/server-actor/src/handlers/notify_user.rs b/crates/server-actor/src/handlers/notify_user.rs index 118cd42..641c4ae 100644 --- a/crates/server-actor/src/handlers/notify_user.rs +++ b/crates/server-actor/src/handlers/notify_user.rs @@ -1,12 +1,13 @@ // use actix::prelude::*; -use git_next_config::server::{Notification, NotificationType}; -use git_next_repo_actor::messages::NotifyUser; + use secrecy::ExposeSecret; use standardwebhooks::Webhook; use tracing::Instrument; use crate::ServerActor; +use git_next_core::server::{self, Notification, NotificationType}; +use git_next_repo_actor::messages::NotifyUser; impl Handler for ServerActor { type Result = (); @@ -48,7 +49,7 @@ async fn send_webhook( async fn do_send_webhook( msg: NotifyUser, webhook: Webhook, - webhook_config: &git_next_config::server::OutboundWebhook, + webhook_config: &server::OutboundWebhook, net: kxio::network::Network, ) { let message_id = format!("msg_{}", ulid::Ulid::new()); diff --git a/crates/server-actor/src/lib.rs b/crates/server-actor/src/lib.rs index a26e838..c8bd0db 100644 --- a/crates/server-actor/src/lib.rs +++ b/crates/server-actor/src/lib.rs @@ -1,28 +1,30 @@ // +use actix::prelude::*; + #[cfg(test)] mod tests; mod handlers; pub mod messages; -use actix::prelude::*; -use git_next_config as config; -use git_next_config::server::{InboundWebhook, ServerConfig, ServerStorage}; -use git_next_config::{ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig}; -use git_next_git::{Generation, RepoDetails}; +use git_next_core::{ + server::{self, InboundWebhook, ServerConfig, ServerStorage}, + ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig, StoragePathType, +}; +use git_next_git::{repository::factory::RepositoryFactory, Generation, RepoDetails}; use git_next_repo_actor::messages::NotifyUser; use git_next_repo_actor::{messages::CloneRepo, RepoActor}; -use git_next_webhook_actor as webhook; + +use git_next_webhook_actor::WebhookActor; use kxio::{fs::FileSystem, network::Network}; + use std::{ collections::BTreeMap, path::PathBuf, sync::{Arc, RwLock}, }; -use tracing::{error, info}; -use webhook::WebhookActor; -pub use git_next_git::repository::{factory::real as repository_factory, RepositoryFactory}; +use tracing::{error, info}; use messages::ReceiveServerConfig; @@ -36,7 +38,7 @@ pub enum Error { path: PathBuf, }, - Config(config::server::Error), + Config(server::Error), Io(std::io::Error), } @@ -159,7 +161,7 @@ impl ServerActor { .path() .join(forge_name.to_string()) .join(repo_alias.to_string()), - config::git_dir::StoragePathType::Internal, + StoragePathType::Internal, ) }, |gitdir| gitdir, diff --git a/crates/server-actor/src/messages.rs b/crates/server-actor/src/messages.rs index 4e321c3..d4dfe0c 100644 --- a/crates/server-actor/src/messages.rs +++ b/crates/server-actor/src/messages.rs @@ -1,7 +1,11 @@ //- use derive_more::Constructor; -use git_next_config::server::{ServerConfig, ServerStorage}; -use git_next_core::message; + +use git_next_core::{ + message, + server::{ServerConfig, ServerStorage}, +}; + use std::net::SocketAddr; // receive server config diff --git a/crates/server-actor/src/tests/receive_server_config.rs b/crates/server-actor/src/tests/receive_server_config.rs index c6164f0..eeafefb 100644 --- a/crates/server-actor/src/tests/receive_server_config.rs +++ b/crates/server-actor/src/tests/receive_server_config.rs @@ -1,7 +1,9 @@ // -use crate::{tests::given, ReceiveServerConfig, ServerActor}; use actix::prelude::*; -use git_next_config::server::{Http, InboundWebhook, Notification, ServerConfig, ServerStorage}; + +use crate::{tests::given, ReceiveServerConfig, ServerActor}; +use git_next_core::server::{Http, InboundWebhook, Notification, ServerConfig, ServerStorage}; + use std::{ collections::BTreeMap, sync::{Arc, RwLock}, diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index a6115b9..a944a28 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -7,7 +7,8 @@ repository = { workspace = true } description = "server for git-next, the trunk-based development manager" [dependencies] -git-next-config = { workspace = true } +git-next-core = { workspace = true } +git-next-git = { workspace = true } git-next-file-watcher-actor = { workspace = true } git-next-server-actor = { workspace = true } diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index ce967fe..9599303 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -1,12 +1,14 @@ // use actix::prelude::*; + use git_next_file_watcher_actor::{FileUpdated, FileWatcher}; +use git_next_git::RepositoryFactory; use git_next_server_actor::ServerActor; + use kxio::{fs::FileSystem, network::Network}; -use std::path::PathBuf; use tracing::{error, info, level_filters::LevelFilter}; -pub use git_next_server_actor::{repository_factory, RepositoryFactory}; +use std::path::PathBuf; pub fn init(fs: FileSystem) { let file_name = "git-next-server.toml"; diff --git a/crates/webhook-actor/Cargo.toml b/crates/webhook-actor/Cargo.toml index 31c23b7..0dc613f 100644 --- a/crates/webhook-actor/Cargo.toml +++ b/crates/webhook-actor/Cargo.toml @@ -8,7 +8,6 @@ description = "webhook actor for git-next, the trunk-based development manager" [dependencies] git-next-core = { workspace = true } -git-next-config = { workspace = true } git-next-repo-actor = { workspace = true } # logging diff --git a/crates/webhook-actor/src/router.rs b/crates/webhook-actor/src/router.rs index 8f16376..3a23242 100644 --- a/crates/webhook-actor/src/router.rs +++ b/crates/webhook-actor/src/router.rs @@ -1,12 +1,13 @@ // -use std::collections::BTreeMap; - use actix::prelude::*; + use derive_more::Constructor; -use git_next_config::{ForgeAlias, RepoAlias}; -use git_next_repo_actor::messages::WebhookNotification; +use std::collections::BTreeMap; use tracing::info; +use git_next_core::{ForgeAlias, RepoAlias}; +use git_next_repo_actor::messages::WebhookNotification; + pub struct WebhookRouter { span: tracing::Span, recipients: BTreeMap>>, diff --git a/crates/webhook-actor/src/server.rs b/crates/webhook-actor/src/server.rs index a6bd13e..6867fb5 100644 --- a/crates/webhook-actor/src/server.rs +++ b/crates/webhook-actor/src/server.rs @@ -1,14 +1,13 @@ // -use std::{collections::BTreeMap, net::SocketAddr}; - use actix::prelude::*; -use config::{ForgeAlias, RepoAlias}; -use git_next_config as config; +use std::{collections::BTreeMap, net::SocketAddr}; -use git_next_repo_actor::messages::WebhookNotification; use tracing::{info, warn}; +use git_next_core::{webhook, ForgeAlias, ForgeNotification, RepoAlias}; +use git_next_repo_actor::messages::WebhookNotification; + pub async fn start( socket_addr: SocketAddr, address: actix::prelude::Recipient, @@ -33,7 +32,7 @@ pub async fn start( let forge_alias = ForgeAlias::new(forge_alias); let repo_alias = RepoAlias::new(repo_alias); let bytes = body.to_vec(); - let body = config::webhook::forge_notification::Body::new( + let body = webhook::forge_notification::Body::new( String::from_utf8_lossy(&bytes).to_string(), ); let headers = headers @@ -42,7 +41,7 @@ pub async fn start( k.map(|k| (k.to_string(), v.to_str().unwrap_or_default().to_string())) }) .collect::>(); - let message = WebhookNotification::new(config::ForgeNotification::new( + let message = WebhookNotification::new(ForgeNotification::new( forge_alias, repo_alias, headers,