refactor: extract actor-macros crate
This commit is contained in:
parent
eba00a112f
commit
2008afa4dd
11 changed files with 80 additions and 55 deletions
|
@ -10,6 +10,7 @@ members = [
|
|||
"crates/forge-github",
|
||||
"crates/repo-actor",
|
||||
"crates/webhook-actor",
|
||||
"crates/actor-macros",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
|
@ -31,6 +32,7 @@ git-next-forge-forgejo = { path = "crates/forge-forgejo" }
|
|||
git-next-forge-github = { path = "crates/forge-github" }
|
||||
git-next-repo-actor = { path = "crates/repo-actor" }
|
||||
git-next-webhook-actor = { path = "crates/webhook-actor" }
|
||||
git-next-actor-macros = { path = "crates/actor-macros" }
|
||||
|
||||
# CLI parsing
|
||||
clap = { version = "4.5", features = ["cargo", "derive"] }
|
||||
|
|
31
crates/actor-macros/Cargo.toml
Normal file
31
crates/actor-macros/Cargo.toml
Normal file
|
@ -0,0 +1,31 @@
|
|||
[package]
|
||||
name = "git-next-actor-macros"
|
||||
version = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
# git-next-config = { workspace = true }
|
||||
# git-next-repo-actor = { workspace = true }
|
||||
#
|
||||
# # logging
|
||||
# tracing = { workspace = true }
|
||||
#
|
||||
# # Webhooks
|
||||
# bytes = { workspace = true }
|
||||
# warp = { workspace = true }
|
||||
#
|
||||
# # boilerplate
|
||||
# derive_more = { workspace = true }
|
||||
|
||||
# Actors
|
||||
actix = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# Testing
|
||||
# assert2 = { workspace = true }
|
||||
|
||||
[lints.clippy]
|
||||
nursery = { level = "warn", priority = -1 }
|
||||
# pedantic = "warn"
|
||||
unwrap_used = "warn"
|
||||
expect_used = "warn"
|
1
crates/actor-macros/src/lib.rs
Normal file
1
crates/actor-macros/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
mod message;
|
27
crates/actor-macros/src/message.rs
Normal file
27
crates/actor-macros/src/message.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
#[macro_export]
|
||||
macro_rules! message {
|
||||
($name:ident wraps $value:ty) => {
|
||||
git_next_config::newtype!($name is a $value);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = ();
|
||||
}
|
||||
};
|
||||
($name:ident) => {
|
||||
git_next_config::newtype!($name);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = ();
|
||||
}
|
||||
};
|
||||
($name:ident wraps $value:ty => $result:ty) => {
|
||||
git_next_config::newtype!($name is a $value);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = $result;
|
||||
}
|
||||
};
|
||||
($name:ident => $result:ty) => {
|
||||
git_next_config::newtype!($name);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = $result;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -12,6 +12,7 @@ github = []
|
|||
git-next-config = { workspace = true }
|
||||
git-next-git = { workspace = true }
|
||||
git-next-forge = { workspace = true }
|
||||
git-next-actor-macros = { workspace = true }
|
||||
|
||||
# logging
|
||||
tracing = { workspace = true }
|
||||
|
|
|
@ -2,37 +2,10 @@
|
|||
use config::newtype;
|
||||
use derive_more::Display;
|
||||
|
||||
use git_next_actor_macros::message;
|
||||
use git_next_config as config;
|
||||
use git_next_git as git;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! message {
|
||||
($name:ident wraps $value:ty) => {
|
||||
git_next_config::newtype!($name is a $value);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = ();
|
||||
}
|
||||
};
|
||||
($name:ident) => {
|
||||
git_next_config::newtype!($name);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = ();
|
||||
}
|
||||
};
|
||||
($name:ident wraps $value:ty => $result:ty) => {
|
||||
git_next_config::newtype!($name is a $value);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = $result;
|
||||
}
|
||||
};
|
||||
($name:ident => $result:ty) => {
|
||||
git_next_config::newtype!($name);
|
||||
impl actix::prelude::Message for $name {
|
||||
type Result = $result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
message!(LoadConfigFromRepo);
|
||||
message!(CloneRepo);
|
||||
message!(ReceiveRepoConfig wraps config::RepoConfig);
|
||||
|
|
|
@ -24,8 +24,11 @@ async fn should_store_repo_config_in_actor() -> TestResult {
|
|||
//then
|
||||
tracing::debug!(?log, "");
|
||||
|
||||
let repo_config = addr.send(TakeRepoConfig).await?;
|
||||
assert_eq!(repo_config, Some(new_repo_config));
|
||||
let reo_actor_view = addr.send(ExamineActor).await?;
|
||||
assert_eq!(
|
||||
reo_actor_view.repo_details.repo_config,
|
||||
Some(new_repo_config)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -88,16 +91,3 @@ async fn should_register_webhook() -> TestResult {
|
|||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
actor::message!(TakeRepoConfig => Option<RepoConfig>);
|
||||
|
||||
impl Handler<TakeRepoConfig> for actor::RepoActor {
|
||||
type Result = Option<RepoConfig>;
|
||||
|
||||
fn handle(&mut self, _msg: TakeRepoConfig, _ctx: &mut Self::Context) -> Self::Result {
|
||||
tracing::debug!("TakeRepoConfig >>");
|
||||
let repo_config = self.repo_details.repo_config.take();
|
||||
tracing::debug!(?repo_config, "TakeRepoConfig <<");
|
||||
repo_config
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
use crate::{self as actor, message};
|
||||
use crate::{self as actor};
|
||||
use actix::prelude::*;
|
||||
use actor::{
|
||||
messages::{CloneRepo, MessageToken},
|
||||
|
@ -16,6 +16,7 @@ use git::{
|
|||
repository::{open::MockOpenRepositoryLike, Direction, MockRepositoryFactory},
|
||||
Generation, GitRemote, MockForgeLike, RepoDetails,
|
||||
};
|
||||
use git_next_actor_macros::message;
|
||||
use git_next_config as config;
|
||||
use git_next_git as git;
|
||||
use mockall::predicate::eq;
|
||||
|
|
|
@ -8,6 +8,7 @@ git-next-config = { workspace = true }
|
|||
git-next-git = { workspace = true }
|
||||
git-next-forge = { workspace = true }
|
||||
git-next-repo-actor = { workspace = true }
|
||||
git-next-actor-macros = { workspace = true }
|
||||
git-next-webhook-actor = { workspace = true }
|
||||
|
||||
# logging
|
||||
|
|
|
@ -1,4 +1 @@
|
|||
use git_next_config::server::ServerConfig;
|
||||
use git_next_repo_actor::message;
|
||||
|
||||
message!(ReceiveServerConfig wraps ServerConfig);
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
//
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::actors::file_watcher::FileUpdated;
|
||||
use actix::prelude::*;
|
||||
|
||||
use crate::actors::{file_watcher::FileUpdated, messages::ReceiveServerConfig};
|
||||
use config::server::{ServerConfig, ServerStorage, Webhook};
|
||||
use git_next_config::{
|
||||
self as config, ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig,
|
||||
};
|
||||
use git_next_git::{repository::RepositoryFactory, Generation, RepoDetails};
|
||||
use git_next_repo_actor::messages::CloneRepo;
|
||||
use git_next_repo_actor::RepoActor;
|
||||
use config::{ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig};
|
||||
use git::{repository::RepositoryFactory, Generation, RepoDetails};
|
||||
use git_next_actor_macros::message;
|
||||
use git_next_config as config;
|
||||
use git_next_git as git;
|
||||
use git_next_repo_actor::{messages::CloneRepo, RepoActor};
|
||||
use git_next_webhook_actor as webhook;
|
||||
use kxio::{fs::FileSystem, network::Network};
|
||||
use tracing::{error, info, warn};
|
||||
use webhook::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter};
|
||||
|
||||
message!(ReceiveServerConfig wraps ServerConfig);
|
||||
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
pub enum Error {
|
||||
#[display("Failed to create data directories")]
|
||||
|
|
Loading…
Reference in a new issue