From 8dbe98a7a45f1324149c08154a750cff8d8133e0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 25 Jul 2024 09:02:43 +0100 Subject: [PATCH] WIP: merge config into core --- crates/config/Cargo.toml | 66 +++++++++---------- crates/config/src/lib.rs | 52 +-------------- crates/config/src/registered_webhook.rs | 16 ----- crates/core/Cargo.toml | 25 +++++++ .../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/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/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/webhook/authorised.rs | 9 +-- 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/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/push.rs | 9 +-- crates/git/src/repo_details.rs | 19 +++--- crates/git/src/repository/mod.rs | 22 +++---- crates/git/src/repository/open/mod.rs | 22 +++---- crates/git/src/repository/open/oreal.rs | 26 +++----- crates/git/src/repository/open/otest.rs | 43 ++++++------ crates/git/src/repository/test.rs | 4 +- crates/git/src/user_notification.rs | 4 +- crates/git/src/validation/positions.rs | 9 +-- crates/git/src/validation/remotes.rs | 8 ++- 69 files changed, 358 insertions(+), 357 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/config/Cargo.toml b/crates/config/Cargo.toml index 3ed140a..c60db60 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -12,39 +12,39 @@ 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 } +# # 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/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..c44b2ab 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,6 +24,26 @@ 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 } 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/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/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/webhook/authorised.rs b/crates/forge-github/src/webhook/authorised.rs index ccf2d9d..b3a7b4c 100644 --- a/crates/forge-github/src/webhook/authorised.rs +++ b/crates/forge-github/src/webhook/authorised.rs @@ -1,7 +1,7 @@ // -use git_next_config as config; +use git_next_core::{webhook, ForgeNotification, WebhookAuth}; -pub fn is_authorised(msg: &config::ForgeNotification, webhook_auth: &config::WebhookAuth) -> bool { +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,10 +20,11 @@ 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, + webhook_auth: &WebhookAuth, + body: &webhook::forge_notification::Body, ) -> std::option::Option { let payload = body.as_str(); + use hmac::Mac; type HmacSha256 = hmac::Hmac; let mut hmac = HmacSha256::new_from_slice(webhook_auth.to_string().as_bytes()).ok()?; 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/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/push.rs b/crates/git/src/push.rs index adf1096..d3e9931 100644 --- a/crates/git/src/push.rs +++ b/crates/git/src/push.rs @@ -1,11 +1,12 @@ -use super::GitRef; +use git_next_core::BranchName; + +// use crate as git; -use git_next_config as config; #[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 { @@ -49,7 +50,7 @@ pub enum Error { pub fn reset( open_repository: &dyn git::repository::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..d1617e9 100644 --- a/crates/git/src/repo_details.rs +++ b/crates/git/src/repo_details.rs @@ -1,15 +1,16 @@ +// use std::sync::{Arc, RwLock}; -use config::{ - BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, RepoAlias, RepoConfig, RepoPath, - ServerRepoConfig, StoragePathType, +use git_next_core::{ + pike, BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, Hostname, RemoteUrl, + 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}; +use crate::{ + repository::{OpenRepositoryLike, RealOpenRepository}, + Generation, GitRemote, +}; /// The derived information about a repo, used to interact with it #[derive(Clone, Debug, derive_more::Display, derive_with::With)] @@ -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/mod.rs b/crates/git/src/repository/mod.rs index 7a1ba7f..02385c3 100644 --- a/crates/git/src/repository/mod.rs +++ b/crates/git/src/repository/mod.rs @@ -1,14 +1,14 @@ // -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; +pub use crate::repository::open::{ + otest::{OnFetch, OnPush}, + OpenRepository, OpenRepositoryLike, RealOpenRepository, +}; +use crate::{ + repository::test::TestRepository, validation::remotes::validate_default_remotes, RepoDetails, +}; + +use git_next_core::{GitDir, RemoteUrl}; + use tracing::info; pub mod factory; @@ -85,7 +85,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..b15f086 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -5,16 +5,16 @@ mod tests; pub mod oreal; pub mod otest; +use git_next_core::{BranchName, GitDir, RemoteUrl}; + 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; +pub use git::repository::open::oreal::RealOpenRepository; +use git::repository::{open::otest::TestOpenRepository, Direction}; #[derive(Clone, Debug)] pub enum OpenRepository { @@ -41,7 +41,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 +52,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 +66,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..95a63fa 100644 --- a/crates/git/src/repository/open/otest.rs +++ b/crates/git/src/repository/open/otest.rs @@ -1,19 +1,22 @@ // -use crate::{self as git, repository::OpenRepositoryLike}; +use crate as git; + +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<()>; +use super::OpenRepositoryLike; + +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 +28,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 +46,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<()> { @@ -69,7 +72,7 @@ pub struct TestOpenRepository { } #[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 +99,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 +123,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 +139,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, @@ -158,7 +157,7 @@ impl TestOpenRepository { } } - 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/test.rs b/crates/git/src/repository/test.rs index e9f0e5a..d08f268 100644 --- a/crates/git/src/repository/test.rs +++ b/crates/git/src/repository/test.rs @@ -1,9 +1,9 @@ // use derive_more::Constructor; +use git_next_core::GitDir; use crate as git; use git::repository::RepositoryLike; -use git_next_config as config; #[derive(Clone, Debug, Constructor)] pub struct TestRepository { @@ -21,7 +21,7 @@ impl TestRepository { } } impl RepositoryLike for TestRepository { - fn open(&self, gitdir: &config::GitDir) -> super::Result { + fn open(&self, gitdir: &GitDir) -> super::Result { Ok(git::repository::open::test( gitdir, self.fs.clone(), 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..2b56909 100644 --- a/crates/git/src/validation/positions.rs +++ b/crates/git/src/validation/positions.rs @@ -1,6 +1,7 @@ // use crate::{self as git, UserNotification}; -use git_next_config as config; + +use git_next_core::{BranchName, RepoConfig}; pub type Result = core::result::Result; @@ -15,7 +16,7 @@ pub struct Positions { pub fn validate_positions( open_repository: &dyn git::repository::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(); @@ -81,7 +82,7 @@ fn reset_next_to_main( repo_details: &crate::RepoDetails, main: &crate::Commit, next: &crate::Commit, - next_branch: &config::BranchName, + next_branch: &BranchName, ) -> Result { git::push::reset( open_repository, @@ -106,7 +107,7 @@ 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, + 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..d525646 100644 --- a/crates/git/src/validation/remotes.rs +++ b/crates/git/src/validation/remotes.rs @@ -1,8 +1,10 @@ -use git_next_config::RemoteUrl; -use tracing::info; - +// use crate as git; +use git_next_core::RemoteUrl; + +use tracing::info; + #[tracing::instrument(skip_all)] pub fn validate_default_remotes( open_repository: &dyn git::repository::OpenRepositoryLike,