diff --git a/crates/cli/README.md b/crates/cli/README.md index 26e02506..e62276ad 100644 --- a/crates/cli/README.md +++ b/crates/cli/README.md @@ -523,32 +523,22 @@ stateDiagram-v2 cli --> server - cli --> git - forge --> core - forge --> git forge --> forge_forgejo forge --> forge_github forge_forgejo --> core - forge_forgejo --> git forge_github --> core - forge_github --> git - - git --> core repo_actor --> core - repo_actor --> git repo_actor --> forge server --> core - server --> git server --> file_watcher_actor server --> server_actor server_actor --> core - server_actor --> git server_actor --> forge server_actor --> repo_actor server_actor --> file_watcher_actor diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 0d293307..2afbbb04 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -4,6 +4,8 @@ mod init; #[cfg(test)] mod tests; +use git_next_core::git; + use std::path::PathBuf; use clap::Parser; @@ -30,7 +32,7 @@ enum Server { fn main() { let fs = fs::new(PathBuf::default()); let net = Network::new_real(); - let repository_factory = git_next_git::repository::factory::real(); + let repository_factory = git::repository::factory::real(); let commands = Commands::parse(); match commands.command { diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 91f1c798..e380d950 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -34,6 +34,7 @@ secrecy = { workspace = true } # Git gix = { workspace = true } git-url-parse = { workspace = true } +async-trait = { workspace = true } # Webhooks ulid = { workspace = true } @@ -44,11 +45,17 @@ derive-with = { workspace = true } thiserror = { workspace = true } pike = { workspace = true } +# TOML parsing +serde_json = { workspace = true } + +mockall = { workspace = true } + [dev-dependencies] # Testing assert2 = { workspace = true } rand = { workspace = true } test-log = { workspace = true } +pretty_assertions = { workspace = true } [lints.clippy] nursery = { level = "warn", priority = -1 } diff --git a/crates/git/src/commit.rs b/crates/core/src/git/commit.rs similarity index 94% rename from crates/git/src/commit.rs rename to crates/core/src/git/commit.rs index b55f880a..8063abdc 100644 --- a/crates/git/src/commit.rs +++ b/crates/core/src/git/commit.rs @@ -1,5 +1,5 @@ // -use git_next_core::{newtype, webhook}; +use crate::{newtype, webhook}; use derive_more::Display; use serde::Serialize; @@ -50,7 +50,7 @@ pub struct Histories { } pub mod log { - use git_next_core::BranchName; + use crate::BranchName; pub type Result = core::result::Result; diff --git a/crates/git/src/fetch.rs b/crates/core/src/git/fetch.rs similarity index 100% rename from crates/git/src/fetch.rs rename to crates/core/src/git/fetch.rs diff --git a/crates/git/src/file.rs b/crates/core/src/git/file.rs similarity index 97% rename from crates/git/src/file.rs rename to crates/core/src/git/file.rs index ea93e3b2..df5e7962 100644 --- a/crates/git/src/file.rs +++ b/crates/core/src/git/file.rs @@ -28,7 +28,7 @@ pub enum Error { Unknown(String), #[error("commit log: {0}")] - CommitLog(#[from] crate::commit::log::Error), + CommitLog(#[from] crate::git::commit::log::Error), #[error("commit not found")] CommitNotFound, diff --git a/crates/git/src/forge/commit.rs b/crates/core/src/git/forge/commit.rs similarity index 100% rename from crates/git/src/forge/commit.rs rename to crates/core/src/git/forge/commit.rs diff --git a/crates/git/src/forge/like.rs b/crates/core/src/git/forge/like.rs similarity index 91% rename from crates/git/src/forge/like.rs rename to crates/core/src/git/forge/like.rs index 5bd6052f..cdc44dcc 100644 --- a/crates/git/src/forge/like.rs +++ b/crates/core/src/git/forge/like.rs @@ -1,8 +1,6 @@ // -use crate as git; - -use git_next_core::{ - server::WebhookUrl, webhook, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, +use crate::{ + git, server::WebhookUrl, webhook, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, }; #[mockall::automock] diff --git a/crates/git/src/forge/mod.rs b/crates/core/src/git/forge/mod.rs similarity index 100% rename from crates/git/src/forge/mod.rs rename to crates/core/src/git/forge/mod.rs diff --git a/crates/git/src/forge/webhook.rs b/crates/core/src/git/forge/webhook.rs similarity index 100% rename from crates/git/src/forge/webhook.rs rename to crates/core/src/git/forge/webhook.rs diff --git a/crates/git/src/generation.rs b/crates/core/src/git/generation.rs similarity index 91% rename from crates/git/src/generation.rs rename to crates/core/src/git/generation.rs index ed691f4b..f969d9a0 100644 --- a/crates/git/src/generation.rs +++ b/crates/core/src/git/generation.rs @@ -1,5 +1,6 @@ use derive_more::Display; -use git_next_core::newtype; + +use crate::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/core/src/git/git_ref.rs similarity index 83% rename from crates/git/src/git_ref.rs rename to crates/core/src/git/git_ref.rs index f3fcaf3f..5a7c3a64 100644 --- a/crates/git/src/git_ref.rs +++ b/crates/core/src/git/git_ref.rs @@ -1,9 +1,9 @@ // -use git_next_core::newtype; +use crate::newtype; use derive_more::Display; -use crate::{commit::Sha, Commit}; +use crate::git::{commit::Sha, Commit}; newtype!(GitRef: String, Display: "A git reference to a git commit."); impl From for GitRef { diff --git a/crates/git/src/git_remote.rs b/crates/core/src/git/git_remote.rs similarity index 90% rename from crates/git/src/git_remote.rs rename to crates/core/src/git/git_remote.rs index f23cda7c..6a1c2fca 100644 --- a/crates/git/src/git_remote.rs +++ b/crates/core/src/git/git_remote.rs @@ -1,7 +1,7 @@ // use derive_more::{Constructor, Display}; -use git_next_core::{Hostname, RepoPath}; +use crate::{Hostname, RepoPath}; #[derive(Clone, Debug, PartialEq, Eq, Constructor, Display)] #[display("{}:{}", host, repo_path)] diff --git a/crates/core/src/git/mod.rs b/crates/core/src/git/mod.rs new file mode 100644 index 00000000..1dfd9c3c --- /dev/null +++ b/crates/core/src/git/mod.rs @@ -0,0 +1,52 @@ +// +pub mod commit; +pub mod fetch; +pub mod file; +pub mod forge; +mod generation; +mod git_ref; +mod git_remote; +pub mod push; +mod repo_details; +pub mod repository; +mod user_notification; +pub mod validation; + +#[cfg(test)] +mod tests; + +pub use commit::Commit; +pub use forge::like::ForgeLike; +pub use forge::like::MockForgeLike; +pub use generation::Generation; +pub use git_ref::GitRef; +pub use git_remote::GitRemote; +pub use repo_details::RepoDetails; +pub use repository::Repository; +pub use repository::RepositoryFactory; +pub use user_notification::UserNotification; + +use crate::common::branch_name; +use crate::common::repo_alias; +use crate::common::repo_path; +use crate::ForgeDetails; +use crate::GitDir; +use crate::RepoConfig; + +pub fn repo_details( + n: u32, + generation: Generation, + forge: ForgeDetails, + repo_config: Option, + gitdir: GitDir, +) -> RepoDetails { + RepoDetails { + generation, + repo_alias: repo_alias(n), + repo_path: repo_path(n), + gitdir, + branch: branch_name(n), + forge, + repo_config, + } +} diff --git a/crates/git/src/push.rs b/crates/core/src/git/push.rs similarity index 93% rename from crates/git/src/push.rs rename to crates/core/src/git/push.rs index 991da09f..aa2ef28f 100644 --- a/crates/git/src/push.rs +++ b/crates/core/src/git/push.rs @@ -1,6 +1,5 @@ // -use crate::{self as git, repository::open::OpenRepositoryLike}; -use git_next_core::BranchName; +use crate::{git, git::repository::open::OpenRepositoryLike, BranchName}; #[derive(Debug, PartialEq, Eq)] pub enum Force { diff --git a/crates/git/src/repo_details.rs b/crates/core/src/git/repo_details.rs similarity index 94% rename from crates/git/src/repo_details.rs rename to crates/core/src/git/repo_details.rs index 1f163af8..9463d654 100644 --- a/crates/git/src/repo_details.rs +++ b/crates/core/src/git/repo_details.rs @@ -1,9 +1,10 @@ // use crate::{ - repository::open::{oreal::RealOpenRepository, OpenRepositoryLike}, - Generation, GitRemote, -}; -use git_next_core::{ + git::{ + self, + repository::open::{oreal::RealOpenRepository, OpenRepositoryLike}, + Generation, GitRemote, + }, pike, BranchName, ForgeAlias, ForgeConfig, ForgeDetails, GitDir, Hostname, RemoteUrl, RepoAlias, RepoConfig, RepoPath, ServerRepoConfig, StoragePathType, }; @@ -86,7 +87,7 @@ impl RepoDetails { } #[allow(clippy::result_large_err)] - pub fn open(&self) -> Result { + pub fn open(&self) -> Result { let gix_repo = pike! { self |> Self::gitdir @@ -108,7 +109,7 @@ impl RepoDetails { } #[tracing::instrument] - pub fn assert_remote_url(&self, found: Option) -> crate::repository::Result<()> { + pub fn assert_remote_url(&self, found: Option) -> git::repository::Result<()> { let Some(found) = found else { tracing::debug!("No remote url found to assert"); return Ok(()); @@ -122,7 +123,7 @@ impl RepoDetails { match self.gitdir.storage_path_type() { StoragePathType::External => { tracing::debug!("Refusing to update an external repo - user must resolve this"); - return Err(crate::repository::Error::MismatchDefaultFetchRemote { + return Err(git::repository::Error::MismatchDefaultFetchRemote { found: Box::new(found), expected: Box::new(expected), }); diff --git a/crates/git/src/repository/factory.rs b/crates/core/src/git/repository/factory.rs similarity index 94% rename from crates/git/src/repository/factory.rs rename to crates/core/src/git/repository/factory.rs index 0663ec2e..17fc7bda 100644 --- a/crates/git/src/repository/factory.rs +++ b/crates/core/src/git/repository/factory.rs @@ -1,5 +1,6 @@ // -use crate::{ +use crate::git::{ + self, repository::{ open::{oreal::RealOpenRepository, OpenRepositoryLike}, Direction, Result, @@ -34,7 +35,7 @@ impl RepositoryFactory for RealRepositoryFactory { fn open(&self, repo_details: &RepoDetails) -> Result> { let repo = repo_details .open() - .map_err(|e| crate::repository::Error::Open(e.to_string()))?; + .map_err(|e| git::repository::Error::Open(e.to_string()))?; let found = repo.find_default_remote(Direction::Fetch); repo_details.assert_remote_url(found)?; diff --git a/crates/git/src/repository/mod.rs b/crates/core/src/git/repository/mod.rs similarity index 93% rename from crates/git/src/repository/mod.rs rename to crates/core/src/git/repository/mod.rs index 081875b7..dfe4124f 100644 --- a/crates/git/src/repository/mod.rs +++ b/crates/core/src/git/repository/mod.rs @@ -1,13 +1,15 @@ // use crate::{ - repository::{ - open::{OpenRepository, OpenRepositoryLike}, - test::TestRepository, + git::{ + repository::{ + open::{OpenRepository, OpenRepositoryLike}, + test::TestRepository, + }, + validation::remotes::validate_default_remotes, + RepoDetails, }, - validation::remotes::validate_default_remotes, - RepoDetails, + GitDir, RemoteUrl, }; -use git_next_core::{GitDir, RemoteUrl}; use tracing::info; diff --git a/crates/git/src/repository/open/mod.rs b/crates/core/src/git/repository/open/mod.rs similarity index 93% rename from crates/git/src/repository/open/mod.rs rename to crates/core/src/git/repository/open/mod.rs index 621af28e..4018effa 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/core/src/git/repository/open/mod.rs @@ -5,12 +5,14 @@ mod tests; pub mod oreal; pub mod otest; -use crate as git; -use git::repository::{ - open::{oreal::RealOpenRepository, otest::TestOpenRepository}, - Direction, +use crate::{ + git, + git::repository::{ + open::{oreal::RealOpenRepository, otest::TestOpenRepository}, + Direction, + }, + BranchName, GitDir, RemoteUrl, }; -use git_next_core::{BranchName, GitDir, RemoteUrl}; use std::{ path::Path, diff --git a/crates/git/src/repository/open/oreal.rs b/crates/core/src/git/repository/open/oreal.rs similarity index 97% rename from crates/git/src/repository/open/oreal.rs rename to crates/core/src/git/repository/open/oreal.rs index 0269fdcb..85d38aa1 100644 --- a/crates/git/src/repository/open/oreal.rs +++ b/crates/core/src/git/repository/open/oreal.rs @@ -1,7 +1,8 @@ // -use crate::{self as git, repository::OpenRepositoryLike}; - -use git_next_core::{BranchName, Hostname, RemoteUrl, RepoPath}; +use crate::{ + git::{self, repository::OpenRepositoryLike}, + BranchName, Hostname, RemoteUrl, RepoPath, +}; use derive_more::Constructor; use gix::bstr::BStr; @@ -129,7 +130,7 @@ impl super::OpenRepositoryLike for RealOpenRepository { &self, branch_name: &BranchName, find_commits: &[git::Commit], - ) -> Result, git::commit::log::Error> { + ) -> Result, git::commit::log::Error> { let limit = match find_commits.is_empty() { true => 1, false => 50, diff --git a/crates/git/src/repository/open/otest.rs b/crates/core/src/git/repository/open/otest.rs similarity index 95% rename from crates/git/src/repository/open/otest.rs rename to crates/core/src/git/repository/open/otest.rs index 84a727f8..84b38cce 100644 --- a/crates/git/src/repository/open/otest.rs +++ b/crates/core/src/git/repository/open/otest.rs @@ -1,11 +1,12 @@ // use crate::{ - self as git, - repository::open::{OpenRepositoryLike, RealOpenRepository}, + git::{ + self, + repository::open::{OpenRepositoryLike, RealOpenRepository}, + }, + BranchName, GitDir, RemoteUrl, RepoBranches, }; -use git_next_core::{BranchName, GitDir, RemoteUrl, RepoBranches}; - use derive_more::{Constructor, Deref}; use std::{ @@ -126,7 +127,7 @@ impl git::repository::OpenRepositoryLike for TestOpenRepository { &self, branch_name: &BranchName, find_commits: &[git::Commit], - ) -> git::commit::log::Result> { + ) -> git::commit::log::Result> { self.real.commit_log(branch_name, find_commits) } diff --git a/crates/git/src/repository/open/tests/commit_log.rs b/crates/core/src/git/repository/open/tests/commit_log.rs similarity index 100% rename from crates/git/src/repository/open/tests/commit_log.rs rename to crates/core/src/git/repository/open/tests/commit_log.rs diff --git a/crates/git/src/repository/open/tests/fetch.rs b/crates/core/src/git/repository/open/tests/fetch.rs similarity index 83% rename from crates/git/src/repository/open/tests/fetch.rs rename to crates/core/src/git/repository/open/tests/fetch.rs index b423f721..5e24b00a 100644 --- a/crates/git/src/repository/open/tests/fetch.rs +++ b/crates/core/src/git/repository/open/tests/fetch.rs @@ -8,6 +8,6 @@ fn should_fetch_from_repo() { let_assert!(Ok(cwd) = std::env::current_dir()); 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) = crate::git::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/core/src/git/repository/open/tests/find_default_remote.rs similarity index 86% rename from crates/git/src/repository/open/tests/find_default_remote.rs rename to crates/core/src/git/repository/open/tests/find_default_remote.rs index 6841a9a8..75eb1aa4 100644 --- a/crates/git/src/repository/open/tests/find_default_remote.rs +++ b/crates/core/src/git/repository/open/tests/find_default_remote.rs @@ -9,6 +9,6 @@ fn should_find_default_push_remote() { let url = repo_details.url(); given::a_bare_repo_with_url(fs.base(), url.expose_secret(), &fs); let_assert!(Ok(repo) = git::repository::factory::real().open(&repo_details)); - let remote = repo.find_default_remote(crate::repository::Direction::Push); + let remote = repo.find_default_remote(git::repository::Direction::Push); assert!(remote.is_some()); } diff --git a/crates/git/src/repository/open/tests/forge_config.rs b/crates/core/src/git/repository/open/tests/forge_config.rs similarity index 100% rename from crates/git/src/repository/open/tests/forge_config.rs rename to crates/core/src/git/repository/open/tests/forge_config.rs diff --git a/crates/git/src/repository/open/tests/mod.rs b/crates/core/src/git/repository/open/tests/mod.rs similarity index 82% rename from crates/git/src/repository/open/tests/mod.rs rename to crates/core/src/git/repository/open/tests/mod.rs index 12a53f46..39fc23a1 100644 --- a/crates/git/src/repository/open/tests/mod.rs +++ b/crates/core/src/git/repository/open/tests/mod.rs @@ -1,10 +1,10 @@ // use crate::{ - self as git, - repository::RepositoryLike as _, - tests::{given, then}, -}; -use git_next_core::{ + git::{ + self, + repository::RepositoryLike as _, + tests::{given, then}, + }, BranchName, ForgeConfig, ForgeType, GitDir, Hostname, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, RepoPath, ServerRepoConfig, StoragePathType, User, }; diff --git a/crates/git/src/repository/open/tests/read_file.rs b/crates/core/src/git/repository/open/tests/read_file.rs similarity index 100% rename from crates/git/src/repository/open/tests/read_file.rs rename to crates/core/src/git/repository/open/tests/read_file.rs diff --git a/crates/git/src/repository/open/tests/repo_config.rs b/crates/core/src/git/repository/open/tests/repo_config.rs similarity index 100% rename from crates/git/src/repository/open/tests/repo_config.rs rename to crates/core/src/git/repository/open/tests/repo_config.rs diff --git a/crates/git/src/repository/open/tests/server_repo_config.rs b/crates/core/src/git/repository/open/tests/server_repo_config.rs similarity index 100% rename from crates/git/src/repository/open/tests/server_repo_config.rs rename to crates/core/src/git/repository/open/tests/server_repo_config.rs diff --git a/crates/git/src/repository/test.rs b/crates/core/src/git/repository/test.rs similarity index 79% rename from crates/git/src/repository/test.rs rename to crates/core/src/git/repository/test.rs index da1cb522..58e5da4a 100644 --- a/crates/git/src/repository/test.rs +++ b/crates/core/src/git/repository/test.rs @@ -2,17 +2,19 @@ use derive_more::Constructor; use crate::{ - self as git, - repository::{ - open::{ - otest::{OnFetch, OnPush}, - OpenRepository, + git::{ + self, + repository::{ + open::{ + otest::{OnFetch, OnPush}, + OpenRepository, + }, + RepositoryLike, Result, }, - RepositoryLike, Result, + RepoDetails, }, - RepoDetails, + GitDir, }; -use git_next_core::GitDir; #[derive(Clone, Debug, Constructor)] pub struct TestRepository { diff --git a/crates/git/src/repository/tests/factory.rs b/crates/core/src/git/repository/tests/factory.rs similarity index 95% rename from crates/git/src/repository/tests/factory.rs rename to crates/core/src/git/repository/tests/factory.rs index 7c75b407..b31d3cf6 100644 --- a/crates/git/src/repository/tests/factory.rs +++ b/crates/core/src/git/repository/tests/factory.rs @@ -15,7 +15,7 @@ fn open_where_storage_external_auth_matches() -> TestResult { let url = repo_details.url(); let url = url.expose_secret(); given::a_bare_repo_with_url(fs.base(), url, &fs); - let factory = crate::repository::factory::real(); + let factory = git::repository::factory::real(); //when let result = factory.open(&repo_details); @@ -42,7 +42,7 @@ fn open_where_storage_external_auth_differs_error() -> TestResult { let original_url = original_url.expose_secret(); given::a_bare_repo_with_url(fs.base(), original_url, &fs); let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::External); - let factory = crate::repository::factory::real(); + let factory = git::repository::factory::real(); // create new authentication let api_token = ApiToken::new(given::a_name().into()); let forge_details = repo_details.forge.clone().with_token(api_token); @@ -80,7 +80,7 @@ fn open_where_storage_internal_auth_matches() -> TestResult { let url = url.expose_secret(); // create a bare repg with the auth from the forge_config given::a_bare_repo_with_url(fs.base(), url, &fs); - let factory = crate::repository::factory::real(); + let factory = git::repository::factory::real(); //when let result = factory.open(&repo_details); @@ -110,7 +110,7 @@ fn open_where_storage_internal_auth_differs_update_config() -> TestResult { let original_url = original_url.expose_secret(); given::a_bare_repo_with_url(fs.base(), original_url, &fs); let gitdir = GitDir::new(fs.base().to_path_buf(), StoragePathType::Internal); - let factory = crate::repository::factory::real(); + let factory = git::repository::factory::real(); // create new authentication let api_token = ApiToken::new(given::a_name().into()); let forge_details = repo_details.forge.clone().with_token(api_token); diff --git a/crates/git/src/repository/tests/mod.rs b/crates/core/src/git/repository/tests/mod.rs similarity index 54% rename from crates/git/src/repository/tests/mod.rs rename to crates/core/src/git/repository/tests/mod.rs index 64af3e69..bfabde9e 100644 --- a/crates/git/src/repository/tests/mod.rs +++ b/crates/core/src/git/repository/tests/mod.rs @@ -1,6 +1,8 @@ // -use crate::{self as git, tests::given}; -use git_next_core::{ApiToken, GitDir, StoragePathType}; +use crate::{ + git::{self, tests::given}, + ApiToken, GitDir, StoragePathType, +}; use assert2::let_assert; diff --git a/crates/git/src/repository/tests/validate.rs b/crates/core/src/git/repository/tests/validate.rs similarity index 100% rename from crates/git/src/repository/tests/validate.rs rename to crates/core/src/git/repository/tests/validate.rs diff --git a/crates/git/src/tests.rs b/crates/core/src/git/tests.rs similarity index 98% rename from crates/git/src/tests.rs rename to crates/core/src/git/tests.rs index 20181d9b..2c678067 100644 --- a/crates/git/src/tests.rs +++ b/crates/core/src/git/tests.rs @@ -1,9 +1,9 @@ // -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::{ + git::{self, Generation, GitRef, GitRemote, RepoDetails}, + git_dir::StoragePathType, + webhook, BranchName, ForgeAlias, ForgeConfig, ForgeType, GitDir, Hostname, RemoteUrl, + RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, RepoPath, ServerRepoConfig, }; use assert2::let_assert; diff --git a/crates/git/src/user_notification.rs b/crates/core/src/git/user_notification.rs similarity index 88% rename from crates/git/src/user_notification.rs rename to crates/core/src/git/user_notification.rs index 73bd857a..a224705a 100644 --- a/crates/git/src/user_notification.rs +++ b/crates/core/src/git/user_notification.rs @@ -1,7 +1,5 @@ // -use crate::Commit; - -use git_next_core::{BranchName, ForgeAlias, RepoAlias}; +use crate::{git::Commit, BranchName, ForgeAlias, RepoAlias}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum UserNotification { diff --git a/crates/git/src/validation/mod.rs b/crates/core/src/git/validation/mod.rs similarity index 100% rename from crates/git/src/validation/mod.rs rename to crates/core/src/git/validation/mod.rs diff --git a/crates/git/src/validation/positions.rs b/crates/core/src/git/validation/positions.rs similarity index 95% rename from crates/git/src/validation/positions.rs rename to crates/core/src/git/validation/positions.rs index 7cef3a20..3ed8b9ec 100644 --- a/crates/git/src/validation/positions.rs +++ b/crates/core/src/git/validation/positions.rs @@ -1,6 +1,8 @@ // -use crate::{self as git, repository::open::OpenRepositoryLike, RepoDetails, UserNotification}; -use git_next_core::{BranchName, RepoConfig}; +use crate::{ + git::{self, repository::open::OpenRepositoryLike, RepoDetails, UserNotification}, + BranchName, RepoConfig, +}; pub type Result = core::result::Result; @@ -100,7 +102,7 @@ fn reset_next_to_main( ))) } -fn is_not_based_on(commits: &[crate::commit::Commit], needle: &crate::Commit) -> bool { +fn is_not_based_on(commits: &[git::commit::Commit], needle: &git::Commit) -> bool { commits.iter().filter(|commit| *commit == needle).count() == 0 } diff --git a/crates/git/src/validation/remotes.rs b/crates/core/src/git/validation/remotes.rs similarity index 95% rename from crates/git/src/validation/remotes.rs rename to crates/core/src/git/validation/remotes.rs index 45fe76db..d8ee4873 100644 --- a/crates/git/src/validation/remotes.rs +++ b/crates/core/src/git/validation/remotes.rs @@ -1,6 +1,8 @@ // -use crate::{self as git, repository::open::OpenRepositoryLike}; -use git_next_core::RemoteUrl; +use crate::{ + git::{self, repository::open::OpenRepositoryLike}, + RemoteUrl, +}; use tracing::info; diff --git a/crates/git/src/validation/tests.rs b/crates/core/src/git/validation/tests.rs similarity index 98% rename from crates/git/src/validation/tests.rs rename to crates/core/src/git/validation/tests.rs index 47927f40..902324c5 100644 --- a/crates/git/src/validation/tests.rs +++ b/crates/core/src/git/validation/tests.rs @@ -1,18 +1,17 @@ // use crate::{ - self as git, - repository::{ - open::otest::{OnFetch, OnPush}, - Direction, + git::{ + self, + repository::{ + factory::RepositoryFactory as _, + open::otest::{OnFetch, OnPush}, + Direction, RepositoryLike as _, + }, + tests::{given, then}, + validation::positions::validate_positions, }, - tests::then, + GitDir, StoragePathType, }; -use git::{ - repository::{factory::RepositoryFactory as _, RepositoryLike as _}, - tests::given, - validation::positions::validate_positions, -}; -use git_next_core::{GitDir, StoragePathType}; use assert2::let_assert; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 05df97ec..32e6d703 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,4 +1,5 @@ mod config; +pub mod git; mod macros; pub use config::*; diff --git a/crates/forge-forgejo/src/lib.rs b/crates/forge-forgejo/src/lib.rs index c2c22e8a..438a39f6 100644 --- a/crates/forge-forgejo/src/lib.rs +++ b/crates/forge-forgejo/src/lib.rs @@ -4,11 +4,10 @@ mod tests; mod webhook; -use git::forge::commit::Status; use git_next_core::{ - self as core, server, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, + self as core, git, git::forge::commit::Status, server, ForgeNotification, RegisteredWebhook, + WebhookAuth, WebhookId, }; -use git_next_git as git; use kxio::network::{self, Network}; use tracing::warn; diff --git a/crates/forge-forgejo/src/tests.rs b/crates/forge-forgejo/src/tests.rs index 4d215939..775a6134 100644 --- a/crates/forge-forgejo/src/tests.rs +++ b/crates/forge-forgejo/src/tests.rs @@ -1,11 +1,11 @@ // use crate::ForgeJo; use git_next_core::{ + git::{self, forge::commit::Status, ForgeLike as _}, 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}; diff --git a/crates/forge-forgejo/src/webhook/list.rs b/crates/forge-forgejo/src/webhook/list.rs index 3135c1e3..009fa1d2 100644 --- a/crates/forge-forgejo/src/webhook/list.rs +++ b/crates/forge-forgejo/src/webhook/list.rs @@ -1,6 +1,5 @@ // -use git_next_core::{server::WebhookUrl, WebhookId}; -use git_next_git as git; +use git_next_core::{git, server::WebhookUrl, WebhookId}; use kxio::network; diff --git a/crates/forge-forgejo/src/webhook/mod.rs b/crates/forge-forgejo/src/webhook/mod.rs index cb216ae1..74b27552 100644 --- a/crates/forge-forgejo/src/webhook/mod.rs +++ b/crates/forge-forgejo/src/webhook/mod.rs @@ -1,6 +1,5 @@ // -use git_next_core::{webhook, BranchName, WebhookId}; -use git_next_git as git; +use git_next_core::{git, webhook, BranchName, WebhookId}; use std::collections::HashMap; diff --git a/crates/forge-forgejo/src/webhook/parse.rs b/crates/forge-forgejo/src/webhook/parse.rs index a21856c5..25f0c2d8 100644 --- a/crates/forge-forgejo/src/webhook/parse.rs +++ b/crates/forge-forgejo/src/webhook/parse.rs @@ -1,8 +1,7 @@ // use crate as forgejo; -use git_next_core::webhook; -use git_next_git as git; +use git_next_core::{git, webhook}; pub fn parse_body( body: &webhook::forge_notification::Body, diff --git a/crates/forge-forgejo/src/webhook/register.rs b/crates/forge-forgejo/src/webhook/register.rs index cddc32c4..08a49f77 100644 --- a/crates/forge-forgejo/src/webhook/register.rs +++ b/crates/forge-forgejo/src/webhook/register.rs @@ -1,6 +1,5 @@ // -use git_next_core::{server, RegisteredWebhook, WebhookAuth, WebhookId}; -use git_next_git as git; +use git_next_core::{git, server, RegisteredWebhook, WebhookAuth, WebhookId}; use kxio::network; use tracing::{info, warn}; diff --git a/crates/forge-forgejo/src/webhook/unregister.rs b/crates/forge-forgejo/src/webhook/unregister.rs index d2356e7e..f32cd2ee 100644 --- a/crates/forge-forgejo/src/webhook/unregister.rs +++ b/crates/forge-forgejo/src/webhook/unregister.rs @@ -1,6 +1,5 @@ // -use git_next_core::WebhookId; -use git_next_git as git; +use git_next_core::{git, WebhookId}; use kxio::network; diff --git a/crates/forge-github/src/commit.rs b/crates/forge-github/src/commit.rs index 78c6d98f..a5520082 100644 --- a/crates/forge-github/src/commit.rs +++ b/crates/forge-github/src/commit.rs @@ -1,7 +1,6 @@ // use crate::{self as github, GithubState}; -use git::forge::commit::Status; -use git_next_git as git; +use git_next_core::git::{self, forge::commit::Status}; use github::GithubStatus; use kxio::network; diff --git a/crates/forge-github/src/lib.rs b/crates/forge-github/src/lib.rs index 4af21337..84e11a02 100644 --- a/crates/forge-github/src/lib.rs +++ b/crates/forge-github/src/lib.rs @@ -6,11 +6,11 @@ mod commit; mod webhook; use crate as github; -use git::forge::commit::Status; use git_next_core::{ - self as core, server, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, + self as core, + git::{self, forge::commit::Status}, + server, ForgeNotification, RegisteredWebhook, WebhookAuth, WebhookId, }; -use git_next_git as git; use derive_more::Constructor; diff --git a/crates/forge-github/src/tests/mod.rs b/crates/forge-github/src/tests/mod.rs index 6ef01a63..5c9c65b8 100644 --- a/crates/forge-github/src/tests/mod.rs +++ b/crates/forge-github/src/tests/mod.rs @@ -1,13 +1,12 @@ // use crate::{Github, GithubState, GithubStatus}; use git_next_core::{ + git::{self, forge::commit::Status, ForgeLike}, server::{InboundWebhook, WebhookUrl}, - webhook, - webhook::forge_notification::Body, + webhook::{self, 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}; @@ -15,8 +14,7 @@ use rand::RngCore; use serde::Serialize; use serde_json::json; -use std::collections::BTreeMap; -use std::path::PathBuf; +use std::{collections::BTreeMap, path::PathBuf}; mod github { use super::*; diff --git a/crates/forge-github/src/webhook/list.rs b/crates/forge-github/src/webhook/list.rs index 2d86c8cc..e3afd37b 100644 --- a/crates/forge-github/src/webhook/list.rs +++ b/crates/forge-github/src/webhook/list.rs @@ -1,7 +1,6 @@ // use crate as github; -use git_next_core::{server, WebhookId}; -use git_next_git as git; +use git_next_core::{git, server, WebhookId}; use kxio::network; diff --git a/crates/forge-github/src/webhook/mod.rs b/crates/forge-github/src/webhook/mod.rs index 78eee6b8..bbf9709a 100644 --- a/crates/forge-github/src/webhook/mod.rs +++ b/crates/forge-github/src/webhook/mod.rs @@ -1,6 +1,5 @@ // -use git_next_core::{webhook, ApiToken, BranchName}; -use git_next_git as git; +use git_next_core::{git, webhook, ApiToken, BranchName}; mod authorised; mod list; diff --git a/crates/forge-github/src/webhook/parse.rs b/crates/forge-github/src/webhook/parse.rs index d132ee2e..35521ad7 100644 --- a/crates/forge-github/src/webhook/parse.rs +++ b/crates/forge-github/src/webhook/parse.rs @@ -1,8 +1,7 @@ // use crate as github; -use git_next_core::webhook; -use git_next_git as git; +use git_next_core::{git, webhook}; pub fn parse_body( body: &webhook::forge_notification::Body, diff --git a/crates/forge-github/src/webhook/register.rs b/crates/forge-github/src/webhook/register.rs index 60cf9769..a702a250 100644 --- a/crates/forge-github/src/webhook/register.rs +++ b/crates/forge-github/src/webhook/register.rs @@ -1,7 +1,6 @@ // use crate::{self as github, webhook}; -use git_next_core::{server, RegisteredWebhook, WebhookAuth, WebhookId}; -use git_next_git as git; +use git_next_core::{git, server, RegisteredWebhook, WebhookAuth, WebhookId}; use kxio::network; diff --git a/crates/forge-github/src/webhook/unregister.rs b/crates/forge-github/src/webhook/unregister.rs index 8e15cd27..d1ec1779 100644 --- a/crates/forge-github/src/webhook/unregister.rs +++ b/crates/forge-github/src/webhook/unregister.rs @@ -1,8 +1,6 @@ // use crate as github; - -use git_next_core::WebhookId; -use git_next_git as git; +use git_next_core::{git, WebhookId}; use kxio::network; diff --git a/crates/forge/src/lib.rs b/crates/forge/src/lib.rs index 09903f3f..47386dfa 100644 --- a/crates/forge/src/lib.rs +++ b/crates/forge/src/lib.rs @@ -1,6 +1,5 @@ // -use git_next_core::ForgeType; -use git_next_git as git; +use git_next_core::{git, ForgeType}; use kxio::network::Network; #[derive(Clone, Debug)] diff --git a/crates/forge/src/tests.rs b/crates/forge/src/tests.rs index 65719a91..dec6729e 100644 --- a/crates/forge/src/tests.rs +++ b/crates/forge/src/tests.rs @@ -1,8 +1,11 @@ // use super::*; -use git_next_core::{self as core, GitDir, RepoConfigSource, StoragePathType}; -use git_next_git::{self as git, RepoDetails}; +use git_next_core::{ + self as core, + git::{self, RepoDetails}, + GitDir, RepoConfigSource, StoragePathType, +}; #[test] fn test_forgejo_name() { @@ -29,7 +32,7 @@ fn given_fs() -> kxio::fs::FileSystem { fn given_repo_details(forge_type: ForgeType) -> RepoDetails { let fs = given_fs(); - git::common::repo_details( + git::repo_details( 1, git::Generation::default(), core::common::forge_details(1, forge_type), diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.toml index 865df5fa..50f42dc4 100644 --- a/crates/git/Cargo.toml +++ b/crates/git/Cargo.toml @@ -4,47 +4,9 @@ version = { workspace = true } edition = { workspace = true } license = { workspace = true } repository = { workspace = true } -description = "git support for git-next, the trunk-based development manager" +description = "[deprecated crate] git support for git-next, the trunk-based development manager" [dependencies] -git-next-core = { workspace = true } - -# logging -tracing = { workspace = true } - -# git -gix = { workspace = true } -async-trait = { workspace = true } - -# fs/network -kxio = { workspace = true } - -# TOML parsing -serde_json = { workspace = true } - -# webhooks - user notification -serde = { workspace = true } - -# Secrets and Password -secrecy = { workspace = true } - -# error handling -derive_more = { workspace = true } -derive-with = { workspace = true } -thiserror = { workspace = true } - -# Actors -actix = { workspace = true } - -mockall = { 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/git/README.md b/crates/git/README.md index ddc70e2a..f12c15d8 100644 --- a/crates/git/README.md +++ b/crates/git/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/git/src/common.rs b/crates/git/src/common.rs deleted file mode 100644 index 1eedcf94..00000000 --- a/crates/git/src/common.rs +++ /dev/null @@ -1,26 +0,0 @@ -// - -use git_next_core::{ - common::{branch_name, repo_alias, repo_path}, - ForgeDetails, GitDir, RepoConfig, -}; - -use crate::{Generation, RepoDetails}; - -pub fn repo_details( - n: u32, - generation: Generation, - forge: ForgeDetails, - repo_config: Option, - gitdir: GitDir, -) -> RepoDetails { - RepoDetails { - generation, - repo_alias: repo_alias(n), - repo_path: repo_path(n), - gitdir, - branch: branch_name(n), - forge, - repo_config, - } -} diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs index 5393ddac..04a894c1 100644 --- a/crates/git/src/lib.rs +++ b/crates/git/src/lib.rs @@ -1,28 +1 @@ -// -pub mod commit; -pub mod common; -pub mod fetch; -pub mod file; -pub mod forge; -mod generation; -mod git_ref; -mod git_remote; -pub mod push; -mod repo_details; -pub mod repository; -mod user_notification; -pub mod validation; - -#[cfg(test)] -mod tests; - -pub use commit::Commit; -pub use forge::like::ForgeLike; -pub use forge::like::MockForgeLike; -pub use generation::Generation; -pub use git_ref::GitRef; -pub use git_remote::GitRemote; -pub use repo_details::RepoDetails; -pub use repository::Repository; -pub use repository::RepositoryFactory; -pub use user_notification::UserNotification; +// moved to crates/core/src/git/ diff --git a/crates/repo-actor/src/branch.rs b/crates/repo-actor/src/branch.rs index 68a4cead..c1c5449d 100644 --- a/crates/repo-actor/src/branch.rs +++ b/crates/repo-actor/src/branch.rs @@ -1,7 +1,9 @@ // use crate::messages::MessageToken; -use git_next_core::RepoConfig; -use git_next_git::{self as git, repository::open::OpenRepositoryLike}; +use git_next_core::{ + git::{self, repository::open::OpenRepositoryLike}, + RepoConfig, +}; use derive_more::Display; use tracing::{info, warn}; diff --git a/crates/repo-actor/src/handlers/clone_repo.rs b/crates/repo-actor/src/handlers/clone_repo.rs index ddc4efff..37f5663b 100644 --- a/crates/repo-actor/src/handlers/clone_repo.rs +++ b/crates/repo-actor/src/handlers/clone_repo.rs @@ -1,40 +1,39 @@ // use actix::prelude::*; -use crate as actor; -use git_next_git as git; +use git_next_core::git; -impl Handler for actor::RepoActor { +impl Handler for crate::RepoActor { type Result = (); #[tracing::instrument(name = "RepoActor::CloneRepo", skip_all, fields(repo = %self.repo_details /*, gitdir = %self.repo_details.gitdir */))] fn handle( &mut self, - _msg: actor::messages::CloneRepo, + _msg: crate::messages::CloneRepo, ctx: &mut Self::Context, ) -> Self::Result { - actor::logger(self.log.as_ref(), "Handler: CloneRepo: start"); + crate::logger(self.log.as_ref(), "Handler: CloneRepo: start"); tracing::debug!("Handler: CloneRepo: start"); match git::repository::open(&*self.repository_factory, &self.repo_details) { Ok(repository) => { - actor::logger(self.log.as_ref(), "open okay"); + crate::logger(self.log.as_ref(), "open okay"); tracing::debug!("open okay"); self.open_repository.replace(repository); if self.repo_details.repo_config.is_none() { - actor::do_send( + crate::do_send( ctx.address(), - actor::messages::LoadConfigFromRepo, + crate::messages::LoadConfigFromRepo, self.log.as_ref(), ); } else { - actor::do_send( + crate::do_send( ctx.address(), - actor::messages::RegisterWebhook::new(), + crate::messages::RegisterWebhook::new(), self.log.as_ref(), ); } } Err(err) => { - actor::logger(self.log.as_ref(), "open failed"); + crate::logger(self.log.as_ref(), "open failed"); tracing::debug!("err: {err:?}"); tracing::warn!("Could not open repo: {err}") } diff --git a/crates/repo-actor/src/handlers/load_config_from_repo.rs b/crates/repo-actor/src/handlers/load_config_from_repo.rs index bff4c359..963e5d6d 100644 --- a/crates/repo-actor/src/handlers/load_config_from_repo.rs +++ b/crates/repo-actor/src/handlers/load_config_from_repo.rs @@ -1,16 +1,16 @@ // use actix::prelude::*; -use git_next_git::UserNotification; + +use git_next_core::git::UserNotification; + use tracing::Instrument as _; -use crate::{self as actor}; - -impl Handler for actor::RepoActor { +impl Handler for crate::RepoActor { type Result = (); - #[tracing::instrument(name = "RepoActor::LoadConfigFromRepo", skip_all, fields(repo = %self.repo_details))] + #[tracing::instrument(name = "Repocrate::LoadConfigFromRepo", skip_all, fields(repo = %self.repo_details))] fn handle( &mut self, - _msg: actor::messages::LoadConfigFromRepo, + _msg: crate::messages::LoadConfigFromRepo, ctx: &mut Self::Context, ) -> Self::Result { tracing::debug!("Handler: LoadConfigFromRepo: start"); @@ -25,13 +25,13 @@ impl Handler for actor::RepoActor { let notify_user_recipient = self.notify_user_recipient.clone(); let log = self.log.clone(); async move { - match actor::load::config_from_repository(repo_details, &*open_repository).await { - Ok(repo_config) => actor::do_send( + match crate::load::config_from_repository(repo_details, &*open_repository).await { + Ok(repo_config) => crate::do_send( addr, - actor::messages::ReceiveRepoConfig::new(repo_config), + crate::messages::ReceiveRepoConfig::new(repo_config), log.as_ref(), ), - Err(err) => actor::notify_user( + Err(err) => crate::notify_user( notify_user_recipient.as_ref(), UserNotification::RepoConfigLoadFailure { forge_alias, diff --git a/crates/repo-actor/src/handlers/receive_ci_status.rs b/crates/repo-actor/src/handlers/receive_ci_status.rs index 38f44736..5e192f3f 100644 --- a/crates/repo-actor/src/handlers/receive_ci_status.rs +++ b/crates/repo-actor/src/handlers/receive_ci_status.rs @@ -1,19 +1,18 @@ // -use crate::{self as actor}; use actix::prelude::*; -use git::UserNotification; -use git_next_git as git; -impl Handler for actor::RepoActor { +use git_next_core::git::{self, UserNotification}; + +impl Handler for crate::RepoActor { type Result = (); fn handle( &mut self, - msg: actor::messages::ReceiveCIStatus, + msg: crate::messages::ReceiveCIStatus, ctx: &mut Self::Context, ) -> Self::Result { let log = self.log.clone(); - actor::logger(log.as_ref(), "start: ReceiveCIStatus"); + crate::logger(log.as_ref(), "start: ReceiveCIStatus"); let addr = ctx.address(); let (next, status) = msg.unwrap(); let forge_alias = self.repo_details.forge.forge_alias().clone(); @@ -24,23 +23,23 @@ impl Handler for actor::RepoActor { tracing::debug!(?status, ""); match status { git::forge::commit::Status::Pass => { - actor::do_send( + crate::do_send( addr, - actor::messages::AdvanceMain::new(next), + crate::messages::AdvanceMain::new(next), self.log.as_ref(), ); } git::forge::commit::Status::Pending => { std::thread::sleep(sleep_duration); - actor::do_send( + crate::do_send( addr, - actor::messages::ValidateRepo::new(message_token), + crate::messages::ValidateRepo::new(message_token), self.log.as_ref(), ); } git::forge::commit::Status::Fail => { tracing::warn!("Checks have failed"); - actor::notify_user( + crate::notify_user( self.notify_user_recipient.as_ref(), UserNotification::CICheckFailed { forge_alias, @@ -49,10 +48,10 @@ impl Handler for actor::RepoActor { }, log.as_ref(), ); - actor::delay_send( + crate::delay_send( addr, sleep_duration, - actor::messages::ValidateRepo::new(message_token), + crate::messages::ValidateRepo::new(message_token), self.log.as_ref(), ); } diff --git a/crates/repo-actor/src/handlers/register_webhook.rs b/crates/repo-actor/src/handlers/register_webhook.rs index ca2a4e21..0c02e53e 100644 --- a/crates/repo-actor/src/handlers/register_webhook.rs +++ b/crates/repo-actor/src/handlers/register_webhook.rs @@ -2,9 +2,8 @@ use actix::prelude::*; use tracing::Instrument as _; -use crate::{self as actor}; -use actor::{messages::RegisterWebhook, RepoActor}; -use git_next_git::UserNotification; +use crate::{messages::RegisterWebhook, RepoActor}; +use git_next_core::git::UserNotification; impl Handler for RepoActor { type Result = (); @@ -23,14 +22,14 @@ impl Handler for RepoActor { match forge.register_webhook(&webhook_url).await { Ok(registered_webhook) => { tracing::debug!(?registered_webhook, ""); - actor::do_send( + crate::do_send( addr, - actor::messages::WebhookRegistered::from(registered_webhook), + crate::messages::WebhookRegistered::from(registered_webhook), log.as_ref(), ); } Err(err) => { - actor::notify_user( + crate::notify_user( notify_user_recipient.as_ref(), UserNotification::WebhookRegistration { forge_alias, diff --git a/crates/repo-actor/src/handlers/validate_repo.rs b/crates/repo-actor/src/handlers/validate_repo.rs index 4e04bf16..582b64e1 100644 --- a/crates/repo-actor/src/handlers/validate_repo.rs +++ b/crates/repo-actor/src/handlers/validate_repo.rs @@ -1,26 +1,27 @@ // use actix::prelude::*; + use derive_more::Deref as _; use tracing::Instrument as _; -use crate::{self as actor, messages::MessageToken}; -use git_next_git as git; +use crate::messages::MessageToken; +use git_next_core::git; -impl Handler for actor::RepoActor { +impl Handler for crate::RepoActor { type Result = (); #[tracing::instrument(name = "RepoActor::ValidateRepo", skip_all, fields(repo = %self.repo_details, token = %msg.deref()))] fn handle( &mut self, - msg: actor::messages::ValidateRepo, + msg: crate::messages::ValidateRepo, ctx: &mut Self::Context, ) -> Self::Result { - actor::logger(self.log.as_ref(), "start: ValidateRepo"); + crate::logger(self.log.as_ref(), "start: ValidateRepo"); // Message Token - make sure we are only triggered for the latest/current token match self.token_status(msg.unwrap()) { TokenStatus::Current => {} // do nothing TokenStatus::Expired => { - actor::logger( + crate::logger( self.log.as_ref(), format!("discarded: old message token: {}", self.message_token), ); @@ -28,28 +29,28 @@ impl Handler for actor::RepoActor { } TokenStatus::New(message_token) => { self.message_token = message_token; - actor::logger( + crate::logger( self.log.as_ref(), format!("new message token: {}", self.message_token), ); } } - actor::logger( + crate::logger( self.log.as_ref(), format!("accepted token: {}", self.message_token), ); // Repository positions let Some(ref open_repository) = self.open_repository else { - actor::logger(self.log.as_ref(), "no open repository"); + crate::logger(self.log.as_ref(), "no open repository"); return; }; - actor::logger(self.log.as_ref(), "have open repository"); + crate::logger(self.log.as_ref(), "have open repository"); let Some(repo_config) = self.repo_details.repo_config.clone() else { - actor::logger(self.log.as_ref(), "no repo config"); + crate::logger(self.log.as_ref(), "no repo config"); return; }; - actor::logger(self.log.as_ref(), "have repo config"); + crate::logger(self.log.as_ref(), "have repo config"); match git::validation::positions::validate_positions( &**open_repository, @@ -64,15 +65,15 @@ impl Handler for actor::RepoActor { }) => { tracing::debug!(%main, %next, %dev, "positions"); if next != main { - actor::do_send( + crate::do_send( ctx.address(), - actor::messages::CheckCIStatus::new(next), + crate::messages::CheckCIStatus::new(next), self.log.as_ref(), ); } else if next != dev { - actor::do_send( + crate::do_send( ctx.address(), - actor::messages::AdvanceNext::new((next, dev_commit_history)), + crate::messages::AdvanceNext::new((next, dev_commit_history)), self.log.as_ref(), ) } else { @@ -80,19 +81,19 @@ impl Handler for actor::RepoActor { } } Err(git::validation::positions::Error::Retryable(message)) => { - actor::logger(self.log.as_ref(), message); + crate::logger(self.log.as_ref(), message); let addr = ctx.address(); let message_token = self.message_token; let sleep_duration = self.sleep_duration; let log = self.log.clone(); async move { tracing::debug!("sleeping before retrying..."); - actor::logger(log.as_ref(), "before sleep"); + crate::logger(log.as_ref(), "before sleep"); tokio::time::sleep(sleep_duration).await; - actor::logger(log.as_ref(), "after sleep"); - actor::do_send( + crate::logger(log.as_ref(), "after sleep"); + crate::do_send( addr, - actor::messages::ValidateRepo::new(message_token), + crate::messages::ValidateRepo::new(message_token), log.as_ref(), ); } @@ -101,14 +102,14 @@ impl Handler for actor::RepoActor { .wait(ctx); } Err(git::validation::positions::Error::UserIntervention(user_notification)) => { - actor::notify_user( + crate::notify_user( self.notify_user_recipient.as_ref(), user_notification, self.log.as_ref(), ) } Err(git::validation::positions::Error::NonRetryable(message)) => { - actor::logger(self.log.as_ref(), message); + crate::logger(self.log.as_ref(), message); } } } @@ -119,7 +120,7 @@ enum TokenStatus { Expired, New(MessageToken), } -impl actor::RepoActor { +impl crate::RepoActor { fn token_status(&self, new: MessageToken) -> TokenStatus { let current = &self.message_token; if &new > current { diff --git a/crates/repo-actor/src/handlers/webhook_notification.rs b/crates/repo-actor/src/handlers/webhook_notification.rs index 5eb4727f..2c0e42be 100644 --- a/crates/repo-actor/src/handlers/webhook_notification.rs +++ b/crates/repo-actor/src/handlers/webhook_notification.rs @@ -1,22 +1,22 @@ // use actix::prelude::*; -use crate::{self as actor, messages::WebhookNotification, RepoActorLog}; +use crate::{messages::WebhookNotification, RepoActorLog}; use git_next_core::{ + git::{self, Commit, ForgeLike}, webhook::{push::Branch, Push}, BranchName, WebhookAuth, }; -use git_next_git::{self as git, Commit, ForgeLike}; use tracing::{info, warn}; -impl Handler for actor::RepoActor { +impl Handler for crate::RepoActor { type Result = (); #[tracing::instrument(name = "RepoActor::WebhookMessage", skip_all, fields(token = %self.message_token, repo = %self.repo_details))] fn handle(&mut self, msg: WebhookNotification, ctx: &mut Self::Context) -> Self::Result { let Some(config) = &self.repo_details.repo_config else { - actor::logger(self.log.as_ref(), "server has no repo config"); + crate::logger(self.log.as_ref(), "server has no repo config"); warn!("No repo config"); return; }; @@ -33,13 +33,13 @@ impl Handler for actor::RepoActor { let body = msg.body(); match self.forge.parse_webhook_body(body) { Err(err) => { - actor::logger(self.log.as_ref(), "message parse error - not a push"); + crate::logger(self.log.as_ref(), "message parse error - not a push"); warn!(?err, "Not a 'push'"); return; } Ok(push) => match push.branch(config.branches()) { None => { - actor::logger(self.log.as_ref(), "unknown branch"); + crate::logger(self.log.as_ref(), "unknown branch"); warn!( ?push, "Unrecognised branch, we should be filtering to only the ones we want" @@ -89,9 +89,9 @@ impl Handler for actor::RepoActor { token = %message_token, "New commit" ); - actor::do_send( + crate::do_send( ctx.address(), - actor::messages::ValidateRepo::new(message_token), + crate::messages::ValidateRepo::new(message_token), self.log.as_ref(), ); } @@ -104,13 +104,13 @@ fn validate_notification( log: Option<&RepoActorLog>, ) -> Result<(), ()> { let Some(expected_authorization) = webhook_auth else { - actor::logger(log, "server has no auth token"); + crate::logger(log, "server has no auth token"); warn!("Don't know what authorization to expect"); return Err(()); }; if !forge.is_message_authorised(msg, expected_authorization) { - actor::logger(log, "message authorisation is invalid"); + crate::logger(log, "message authorisation is invalid"); warn!( "Invalid authorization - expected {}", expected_authorization @@ -118,7 +118,7 @@ fn validate_notification( return Err(()); } if forge.should_ignore_message(msg) { - actor::logger(log, "forge sent ignorable message"); + crate::logger(log, "forge sent ignorable message"); return Err(()); } Ok(()) @@ -130,10 +130,10 @@ fn handle_push( last_commit: &mut Option, log: Option<&RepoActorLog>, ) -> Result<(), ()> { - actor::logger(log, "message is for dev branch"); + crate::logger(log, "message is for dev branch"); let commit = git::Commit::from(push); if last_commit.as_ref() == Some(&commit) { - actor::logger(log, format!("not a new commit on {branch}")); + crate::logger(log, format!("not a new commit on {branch}")); info!( %branch , %commit, diff --git a/crates/repo-actor/src/lib.rs b/crates/repo-actor/src/lib.rs index 959d97bc..cb7e756b 100644 --- a/crates/repo-actor/src/lib.rs +++ b/crates/repo-actor/src/lib.rs @@ -7,11 +7,13 @@ 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, +use git_next_core::{ + git::{ + self, + repository::{factory::RepositoryFactory, open::OpenRepositoryLike}, + UserNotification, + }, + server, WebhookAuth, WebhookId, }; mod branch; diff --git a/crates/repo-actor/src/load.rs b/crates/repo-actor/src/load.rs index 640a5892..99f81d81 100644 --- a/crates/repo-actor/src/load.rs +++ b/crates/repo-actor/src/load.rs @@ -1,6 +1,8 @@ // -use git_next_core::{server, BranchName, RepoConfig}; -use git_next_git::{self as git, repository::open::OpenRepositoryLike}; +use git_next_core::{ + git::{self, repository::open::OpenRepositoryLike}, + server, BranchName, RepoConfig, +}; use std::path::PathBuf; diff --git a/crates/repo-actor/src/messages.rs b/crates/repo-actor/src/messages.rs index 663a89ff..d975b51e 100644 --- a/crates/repo-actor/src/messages.rs +++ b/crates/repo-actor/src/messages.rs @@ -1,10 +1,8 @@ // use derive_more::Display; -use git::UserNotification; -use git_next_git as git; - use git_next_core::{ + git::{self, UserNotification}, message, newtype, webhook, RegisteredWebhook, RepoConfig, WebhookAuth, WebhookId, }; diff --git a/crates/repo-actor/src/notifications.rs b/crates/repo-actor/src/notifications.rs index b3bfd7d7..6bedfd80 100644 --- a/crates/repo-actor/src/notifications.rs +++ b/crates/repo-actor/src/notifications.rs @@ -1,8 +1,9 @@ use derive_more::Deref as _; -use git_next_git::UserNotification; -use serde_json::json; use crate::messages::NotifyUser; +use git_next_core::git::UserNotification; + +use serde_json::json; impl NotifyUser { pub fn as_json(self, timestamp: time::OffsetDateTime) -> serde_json::Value { diff --git a/crates/repo-actor/src/tests/branch/advance_main.rs b/crates/repo-actor/src/tests/branch/advance_main.rs index 26099b64..1c5daf09 100644 --- a/crates/repo-actor/src/tests/branch/advance_main.rs +++ b/crates/repo-actor/src/tests/branch/advance_main.rs @@ -11,11 +11,11 @@ fn push_is_error_should_error() { expect::push(&mut open_repository, Err(git::push::Error::Lock)); let_assert!( Err(err) = - actor::branch::advance_main(commit, &repo_details, &repo_config, &open_repository) + crate::branch::advance_main(commit, &repo_details, &repo_config, &open_repository) ); assert!(matches!( err, - actor::branch::Error::Push(git::push::Error::Lock) + crate::branch::Error::Push(git::push::Error::Lock) )); } @@ -28,6 +28,6 @@ fn push_is_ok_should_ok() { expect::fetch_ok(&mut open_repository); expect::push_ok(&mut open_repository); assert!( - actor::branch::advance_main(commit, &repo_details, &repo_config, &open_repository).is_ok() + crate::branch::advance_main(commit, &repo_details, &repo_config, &open_repository).is_ok() ); } diff --git a/crates/repo-actor/src/tests/branch/advance_next.rs b/crates/repo-actor/src/tests/branch/advance_next.rs index 02d77367..8a5dfba8 100644 --- a/crates/repo-actor/src/tests/branch/advance_next.rs +++ b/crates/repo-actor/src/tests/branch/advance_next.rs @@ -14,7 +14,7 @@ mod when_at_dev { // no on_push defined - so any call to push will cause an error let message_token = given::a_message_token(); let_assert!( - Err(err) = actor::branch::advance_next( + Err(err) = crate::branch::advance_next( &next, dev_commit_history, repo_details, @@ -24,7 +24,7 @@ mod when_at_dev { ) ); tracing::debug!("Got: {err}"); - assert!(matches!(err, actor::branch::Error::NextAtDev)); + assert!(matches!(err, crate::branch::Error::NextAtDev)); Ok(()) } } @@ -47,7 +47,7 @@ mod can_advance { // no on_push defined - so any call to push will cause an error let message_token = given::a_message_token(); let_assert!( - Err(err) = actor::branch::advance_next( + Err(err) = crate::branch::advance_next( &next, dev_commit_history, repo_details, @@ -57,7 +57,7 @@ mod can_advance { ) ); tracing::debug!("Got: {err}"); - assert!(matches!(err, actor::branch::Error::IsWorkInProgress)); + assert!(matches!(err, crate::branch::Error::IsWorkInProgress)); Ok(()) } } @@ -77,7 +77,7 @@ mod can_advance { // no on_push defined - so any call to push will cause an error let message_token = given::a_message_token(); let_assert!( - Err(err) = actor::branch::advance_next( + Err(err) = crate::branch::advance_next( &next, dev_commit_history, repo_details, @@ -89,7 +89,7 @@ mod can_advance { tracing::debug!("Got: {err}"); assert!(matches!( err, - actor::branch::Error::InvalidCommitMessage{reason} + crate::branch::Error::InvalidCommitMessage{reason} if reason == "Missing type in the commit summary, expected `type: description`" )); Ok(()) @@ -116,7 +116,7 @@ mod can_advance { expect::push(&mut open_repository, Err(git::push::Error::Lock)); let message_token = given::a_message_token(); let_assert!( - Err(err) = actor::branch::advance_next( + Err(err) = crate::branch::advance_next( &next, dev_commit_history, repo_details, @@ -128,7 +128,7 @@ mod can_advance { tracing::debug!("Got: {err:?}"); assert!(matches!( err, - actor::branch::Error::Push(git::push::Error::Lock) + crate::branch::Error::Push(git::push::Error::Lock) )); Ok(()) } @@ -150,7 +150,7 @@ mod can_advance { expect::push_ok(&mut open_repository); let message_token = given::a_message_token(); let_assert!( - Ok(mt) = actor::branch::advance_next( + Ok(mt) = crate::branch::advance_next( &next, dev_commit_history, repo_details, diff --git a/crates/repo-actor/src/tests/branch/mod.rs b/crates/repo-actor/src/tests/branch/mod.rs index a64840d6..3ba7b2ef 100644 --- a/crates/repo-actor/src/tests/branch/mod.rs +++ b/crates/repo-actor/src/tests/branch/mod.rs @@ -15,7 +15,7 @@ async fn test_find_next_commit_on_dev() { given::a_commit(), // parent of next ]; - let next_commit = actor::branch::find_next_commit_on_dev(&next, &dev_commit_history); + let next_commit = crate::branch::find_next_commit_on_dev(&next, &dev_commit_history); assert_eq!(next_commit, Some(expected), "Found the wrong commit"); } diff --git a/crates/repo-actor/src/tests/given.rs b/crates/repo-actor/src/tests/given.rs index 319f3702..c45bc736 100644 --- a/crates/repo-actor/src/tests/given.rs +++ b/crates/repo-actor/src/tests/given.rs @@ -186,7 +186,7 @@ pub fn a_repo_actor( repository_factory: Box, forge: Box, net: kxio::network::Network, -) -> (actor::RepoActor, RepoActorLog) { +) -> (crate::RepoActor, RepoActorLog) { let forge_alias = repo_details.forge.forge_alias(); let repo_alias = &repo_details.repo_alias; let webhook_url = given::a_webhook_url(forge_alias, repo_alias); @@ -195,7 +195,7 @@ pub fn a_repo_actor( let log = RepoActorLog::default(); let actors_log = log.clone(); ( - actor::RepoActor::new( + crate::RepoActor::new( repo_details, forge, webhook, diff --git a/crates/repo-actor/src/tests/handlers/advance_main.rs b/crates/repo-actor/src/tests/handlers/advance_main.rs index e8f8e723..34d413b8 100644 --- a/crates/repo-actor/src/tests/handlers/advance_main.rs +++ b/crates/repo-actor/src/tests/handlers/advance_main.rs @@ -32,7 +32,7 @@ async fn when_repo_config_should_fetch_then_push_then_revalidate() -> TestResult repo_details, given::a_forge(), ); - addr.send(actor::messages::AdvanceMain::new(next_commit.clone())) + addr.send(crate::messages::AdvanceMain::new(next_commit.clone())) .await?; System::current().stop(); @@ -77,7 +77,7 @@ async fn when_server_config_should_fetch_then_push_then_revalidate() -> TestResu repo_details, given::a_forge(), ); - addr.send(actor::messages::AdvanceMain::new(next_commit.clone())) + addr.send(crate::messages::AdvanceMain::new(next_commit.clone())) .await?; System::current().stop(); diff --git a/crates/repo-actor/src/tests/handlers/advance_next.rs b/crates/repo-actor/src/tests/handlers/advance_next.rs index 23683cc7..dd3a2139 100644 --- a/crates/repo-actor/src/tests/handlers/advance_next.rs +++ b/crates/repo-actor/src/tests/handlers/advance_next.rs @@ -31,7 +31,7 @@ async fn should_fetch_then_push_then_revalidate() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::AdvanceNext::new(( + addr.send(crate::messages::AdvanceNext::new(( next_commit.clone(), dev_commit_log, ))) diff --git a/crates/repo-actor/src/tests/handlers/check_ci_status.rs b/crates/repo-actor/src/tests/handlers/check_ci_status.rs index 7741d64b..9a8bea60 100644 --- a/crates/repo-actor/src/tests/handlers/check_ci_status.rs +++ b/crates/repo-actor/src/tests/handlers/check_ci_status.rs @@ -20,7 +20,7 @@ async fn should_passthrough_to_receive_ci_status() -> TestResult { repo_details, Box::new(forge), ); - addr.send(actor::messages::CheckCIStatus::new(next_commit.clone())) + addr.send(crate::messages::CheckCIStatus::new(next_commit.clone())) .await?; System::current().stop(); diff --git a/crates/repo-actor/src/tests/handlers/load_config_from_repo.rs b/crates/repo-actor/src/tests/handlers/load_config_from_repo.rs index 98de1184..86ff0d54 100644 --- a/crates/repo-actor/src/tests/handlers/load_config_from_repo.rs +++ b/crates/repo-actor/src/tests/handlers/load_config_from_repo.rs @@ -39,7 +39,7 @@ async fn when_read_file_ok_should_send_config_loaded() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::LoadConfigFromRepo::new()) + addr.send(crate::messages::LoadConfigFromRepo::new()) .await?; System::current().stop(); @@ -70,7 +70,7 @@ async fn when_read_file_err_should_notify_user() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::LoadConfigFromRepo::new()) + addr.send(crate::messages::LoadConfigFromRepo::new()) .await?; System::current().stop(); diff --git a/crates/repo-actor/src/tests/handlers/loaded_config.rs b/crates/repo-actor/src/tests/handlers/loaded_config.rs index 963cade5..bb641e71 100644 --- a/crates/repo-actor/src/tests/handlers/loaded_config.rs +++ b/crates/repo-actor/src/tests/handlers/loaded_config.rs @@ -15,7 +15,7 @@ async fn should_store_repo_config_in_actor() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveRepoConfig::new( + addr.send(crate::messages::ReceiveRepoConfig::new( new_repo_config.clone(), )) .await?; @@ -46,7 +46,7 @@ async fn should_register_webhook() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveRepoConfig::new( + addr.send(crate::messages::ReceiveRepoConfig::new( new_repo_config.clone(), )) .await?; diff --git a/crates/repo-actor/src/tests/handlers/receive_ci_status.rs b/crates/repo-actor/src/tests/handlers/receive_ci_status.rs index 9d8ff1d6..f5323a18 100644 --- a/crates/repo-actor/src/tests/handlers/receive_ci_status.rs +++ b/crates/repo-actor/src/tests/handlers/receive_ci_status.rs @@ -14,7 +14,7 @@ async fn when_pass_should_advance_main_to_next() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveCIStatus::new(( + addr.send(crate::messages::ReceiveCIStatus::new(( next_commit.clone(), git::forge::commit::Status::Pass, ))) @@ -44,7 +44,7 @@ async fn when_pending_should_recheck_ci_status() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveCIStatus::new(( + addr.send(crate::messages::ReceiveCIStatus::new(( next_commit.clone(), git::forge::commit::Status::Pending, ))) @@ -74,7 +74,7 @@ async fn when_fail_should_recheck_after_delay() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveCIStatus::new(( + addr.send(crate::messages::ReceiveCIStatus::new(( next_commit.clone(), git::forge::commit::Status::Fail, ))) @@ -100,7 +100,7 @@ async fn when_fail_should_notify_user() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::ReceiveCIStatus::new(( + addr.send(crate::messages::ReceiveCIStatus::new(( next_commit.clone(), git::forge::commit::Status::Fail, ))) diff --git a/crates/repo-actor/src/tests/handlers/register_webhook.rs b/crates/repo-actor/src/tests/handlers/register_webhook.rs index fea85683..bb577213 100644 --- a/crates/repo-actor/src/tests/handlers/register_webhook.rs +++ b/crates/repo-actor/src/tests/handlers/register_webhook.rs @@ -22,7 +22,7 @@ async fn when_registered_ok_should_send_webhook_registered() -> TestResult { repo_details, Box::new(forge), ); - addr.send(actor::messages::RegisterWebhook::new()).await?; + addr.send(crate::messages::RegisterWebhook::new()).await?; System::current().stop(); //then @@ -57,7 +57,7 @@ async fn when_registered_error_should_send_notify_user() -> TestResult { repo_details, Box::new(forge), ); - addr.send(actor::messages::RegisterWebhook::new()).await?; + addr.send(crate::messages::RegisterWebhook::new()).await?; System::current().stop(); //then diff --git a/crates/repo-actor/src/tests/handlers/webhook_notification.rs b/crates/repo-actor/src/tests/handlers/webhook_notification.rs index c2db1100..b4c6067b 100644 --- a/crates/repo-actor/src/tests/handlers/webhook_notification.rs +++ b/crates/repo-actor/src/tests/handlers/webhook_notification.rs @@ -23,7 +23,7 @@ async fn when_no_expected_auth_token_drop_notification() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -57,7 +57,7 @@ async fn when_no_repo_config_drop_notification() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -95,7 +95,7 @@ async fn when_message_auth_is_invalid_drop_notification() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -137,7 +137,7 @@ async fn when_message_is_ignorable_drop_notification() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -179,7 +179,7 @@ async fn when_message_is_not_a_push_drop_notification() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -227,7 +227,7 @@ async fn when_message_is_push_on_unknown_branch_drop_notification() -> TestResul //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -276,7 +276,7 @@ async fn when_message_is_push_already_seen_commit_to_main() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -325,7 +325,7 @@ async fn when_message_is_push_already_seen_commit_to_next() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -374,7 +374,7 @@ async fn when_message_is_push_already_seen_commit_to_dev() -> TestResult { //when actor .start() - .send(actor::messages::WebhookNotification::new( + .send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -421,7 +421,7 @@ async fn when_message_is_push_new_commit_to_main_should_stash_and_validate_repo( //when let addr = actor.start(); - addr.send(actor::messages::WebhookNotification::new( + addr.send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -469,7 +469,7 @@ async fn when_message_is_push_new_commit_to_next_should_stash_and_validate_repo( //when let addr = actor.start(); - addr.send(actor::messages::WebhookNotification::new( + addr.send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; @@ -517,7 +517,7 @@ async fn when_message_is_push_new_commit_to_dev_should_stash_and_validate_repo() //when let addr = actor.start(); - addr.send(actor::messages::WebhookNotification::new( + addr.send(crate::messages::WebhookNotification::new( forge_notification, )) .await?; diff --git a/crates/repo-actor/src/tests/handlers/webhook_registered.rs b/crates/repo-actor/src/tests/handlers/webhook_registered.rs index 69d03210..45f04943 100644 --- a/crates/repo-actor/src/tests/handlers/webhook_registered.rs +++ b/crates/repo-actor/src/tests/handlers/webhook_registered.rs @@ -15,7 +15,7 @@ async fn should_store_webhook_details() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::WebhookRegistered::new(( + addr.send(crate::messages::WebhookRegistered::new(( webhook_id.clone(), webhook_auth.clone(), ))) @@ -43,7 +43,7 @@ async fn should_send_validate_repo_message() -> TestResult { repo_details, given::a_forge(), ); - addr.send(actor::messages::WebhookRegistered::new(( + addr.send(crate::messages::WebhookRegistered::new(( webhook_id.clone(), webhook_auth.clone(), ))) diff --git a/crates/repo-actor/src/tests/load.rs b/crates/repo-actor/src/tests/load.rs index e9ed6555..119f437f 100644 --- a/crates/repo-actor/src/tests/load.rs +++ b/crates/repo-actor/src/tests/load.rs @@ -11,13 +11,13 @@ async fn when_file_not_found_should_error() -> TestResult { .returning(|_, _| Err(git::file::Error::FileNotFound)); //when let_assert!( - Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await + Err(err) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); assert!(matches!( err, - actor::load::Error::File(git::file::Error::FileNotFound) + crate::load::Error::File(git::file::Error::FileNotFound) )); Ok(()) } @@ -33,11 +33,11 @@ async fn when_file_format_invalid_should_error() -> TestResult { .return_once(move |_, _| Ok(contents)); //when let_assert!( - Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await + Err(err) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); - assert!(matches!(err, actor::load::Error::Toml(_))); + assert!(matches!(err, crate::load::Error::Toml(_))); Ok(()) } @@ -67,11 +67,11 @@ async fn when_main_branch_is_missing_should_error() -> TestResult { .return_once(move || Ok(branches)); //when let_assert!( - Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await + Err(err) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); - assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == main)); + assert!(matches!(err, crate::load::Error::BranchNotFound(branch) if branch == main)); Ok(()) } @@ -101,11 +101,11 @@ async fn when_next_branch_is_missing_should_error() -> TestResult { .return_once(move || Ok(branches)); //when let_assert!( - Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await + Err(err) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); - assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == next)); + assert!(matches!(err, crate::load::Error::BranchNotFound(branch) if branch == next)); Ok(()) } @@ -135,11 +135,11 @@ async fn when_dev_branch_is_missing_should_error() -> TestResult { .return_once(move || Ok(branches)); //when let_assert!( - Err(err) = actor::load::config_from_repository(repo_details, &open_repository).await + Err(err) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {err:?}"); - assert!(matches!(err, actor::load::Error::BranchNotFound(branch) if branch == dev)); + assert!(matches!(err, crate::load::Error::BranchNotFound(branch) if branch == dev)); Ok(()) } @@ -170,7 +170,7 @@ async fn when_valid_file_should_return_repo_config() -> TestResult { .return_once(move || Ok(branches)); //when let_assert!( - Ok(result) = actor::load::config_from_repository(repo_details, &open_repository).await + Ok(result) = crate::load::config_from_repository(repo_details, &open_repository).await ); //then tracing::debug!("Got: {result:?}"); diff --git a/crates/repo-actor/src/tests/mod.rs b/crates/repo-actor/src/tests/mod.rs index e9c15212..3b376096 100644 --- a/crates/repo-actor/src/tests/mod.rs +++ b/crates/repo-actor/src/tests/mod.rs @@ -2,11 +2,19 @@ use actix::prelude::*; use crate::{ - self as actor, messages::{CloneRepo, MessageToken}, RepoActor, RepoActorLog, }; use git_next_core::{ + git::{ + self, + repository::{ + factory::{MockRepositoryFactory, RepositoryFactory}, + open::{MockOpenRepositoryLike, OpenRepositoryLike}, + Direction, + }, + Generation, MockForgeLike, RepoDetails, + }, message, server::{InboundWebhook, WebhookUrl}, webhook::{self, forge_notification::Body}, @@ -14,15 +22,6 @@ use git_next_core::{ RegisteredWebhook, RemoteUrl, RepoAlias, RepoBranches, RepoConfig, RepoConfigSource, ServerRepoConfig, StoragePathType, WebhookAuth, WebhookId, }; -use git_next_git::{ - self as git, - repository::{ - factory::{MockRepositoryFactory, RepositoryFactory}, - open::{MockOpenRepositoryLike, OpenRepositoryLike}, - Direction, - }, - Generation, MockForgeLike, RepoDetails, -}; use assert2::let_assert; use mockall::predicate::eq; diff --git a/crates/server-actor/src/lib.rs b/crates/server-actor/src/lib.rs index c8bd0db8..d90f1783 100644 --- a/crates/server-actor/src/lib.rs +++ b/crates/server-actor/src/lib.rs @@ -8,14 +8,14 @@ mod handlers; pub mod messages; use git_next_core::{ + git::{repository::factory::RepositoryFactory, Generation, RepoDetails}, 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::WebhookActor; + use kxio::{fs::FileSystem, network::Network}; use std::{ diff --git a/crates/server-actor/src/tests/receive_server_config.rs b/crates/server-actor/src/tests/receive_server_config.rs index eeafefbe..f7cedc2e 100644 --- a/crates/server-actor/src/tests/receive_server_config.rs +++ b/crates/server-actor/src/tests/receive_server_config.rs @@ -2,7 +2,10 @@ use actix::prelude::*; use crate::{tests::given, ReceiveServerConfig, ServerActor}; -use git_next_core::server::{Http, InboundWebhook, Notification, ServerConfig, ServerStorage}; +use git_next_core::{ + git, + server::{Http, InboundWebhook, Notification, ServerConfig, ServerStorage}, +}; use std::{ collections::BTreeMap, @@ -15,7 +18,7 @@ async fn when_webhook_url_has_trailing_slash_should_not_send() { // parameters let fs = given::a_filesystem(); let net = given::a_network(); - let repo = git_next_git::repository::factory::mock(); + let repo = git::repository::factory::mock(); let duration = std::time::Duration::from_millis(1); // sut diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 95993030..906833d4 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -1,8 +1,8 @@ // use actix::prelude::*; +use git_next_core::git::RepositoryFactory; 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};