From 2850fb9887dbc3699f0c74152d1fc4c86dd8307f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 27 Jul 2024 19:05:18 +0100 Subject: [PATCH] refactor: merge webhook-actor crate into cli crate --- crates/cli/Cargo.toml | 3 +- crates/cli/README.md | 4 -- crates/cli/src/main.rs | 1 + .../handlers/receive_valid_server_config.rs | 15 ++++-- .../cli/src/server/actor/handlers/shutdown.rs | 9 ++-- crates/cli/src/server/actor/mod.rs | 8 ++-- .../src => cli/src/webhook}/handlers/mod.rs | 0 .../src/webhook}/handlers/shutdown_webhook.rs | 2 +- .../src => cli/src/webhook}/messages.rs | 0 crates/cli/src/webhook/mod.rs | 42 +++++++++++++++++ .../src => cli/src/webhook}/router.rs | 0 .../src => cli/src/webhook}/server.rs | 0 crates/webhook-actor/Cargo.toml | 29 +----------- crates/webhook-actor/README.md | 2 + crates/webhook-actor/src/lib.rs | 46 +------------------ 15 files changed, 72 insertions(+), 89 deletions(-) rename crates/{webhook-actor/src => cli/src/webhook}/handlers/mod.rs (100%) rename crates/{webhook-actor/src => cli/src/webhook}/handlers/shutdown_webhook.rs (80%) rename crates/{webhook-actor/src => cli/src/webhook}/messages.rs (100%) create mode 100644 crates/cli/src/webhook/mod.rs rename crates/{webhook-actor/src => cli/src/webhook}/router.rs (100%) rename crates/{webhook-actor/src => cli/src/webhook}/server.rs (100%) diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 8016d22..2aa6dbd 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -16,7 +16,6 @@ git-next-core = { workspace = true } git-next-server-actor = { workspace = true } git-next-forge = { workspace = true } git-next-repo-actor = { workspace = true } -git-next-webhook-actor = { workspace = true } # CLI parsing clap = { workspace = true } @@ -45,6 +44,8 @@ ulid = { workspace = true } time = { workspace = true } secrecy = { workspace = true } standardwebhooks = { workspace = true } +bytes = { workspace = true } +warp = { workspace = true } # file watcher (linux) inotify = { workspace = true } diff --git a/crates/cli/README.md b/crates/cli/README.md index f6cbee1..5a6e95d 100644 --- a/crates/cli/README.md +++ b/crates/cli/README.md @@ -522,7 +522,6 @@ stateDiagram-v2 cli --> core cli --> forge cli --> repo_actor - cli --> webhook_actor forge --> core forge --> forge_forgejo @@ -534,9 +533,6 @@ stateDiagram-v2 repo_actor --> core repo_actor --> forge - - webhook_actor --> core - webhook_actor --> repo_actor ``` ## License diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 724a8bc..804f8cf 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -2,6 +2,7 @@ mod file_watcher; mod init; mod server; +mod webhook; #[cfg(test)] mod tests; diff --git a/crates/cli/src/server/actor/handlers/receive_valid_server_config.rs b/crates/cli/src/server/actor/handlers/receive_valid_server_config.rs index 17fbb2d..1ecb0d1 100644 --- a/crates/cli/src/server/actor/handlers/receive_valid_server_config.rs +++ b/crates/cli/src/server/actor/handlers/receive_valid_server_config.rs @@ -1,9 +1,16 @@ +// use actix::prelude::*; -use git_next_webhook_actor::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter}; -use crate::server::actor::{ - messages::{ReceiveValidServerConfig, ValidServerConfig}, - ServerActor, +use crate::{ + server::actor::{ + messages::{ReceiveValidServerConfig, ValidServerConfig}, + ServerActor, + }, + webhook::{ + messages::ShutdownWebhook, + router::{AddWebhookRecipient, WebhookRouter}, + WebhookActor, + }, }; impl Handler for ServerActor { diff --git a/crates/cli/src/server/actor/handlers/shutdown.rs b/crates/cli/src/server/actor/handlers/shutdown.rs index 92b05f1..a4c639f 100644 --- a/crates/cli/src/server/actor/handlers/shutdown.rs +++ b/crates/cli/src/server/actor/handlers/shutdown.rs @@ -1,8 +1,11 @@ //- -use actix::prelude::*; -use git_next_webhook_actor::ShutdownWebhook; -use crate::server::actor::{messages::Shutdown, ServerActor}; +use actix::prelude::*; + +use crate::{ + server::actor::{messages::Shutdown, ServerActor}, + webhook::messages::ShutdownWebhook, +}; impl Handler for ServerActor { type Result = (); diff --git a/crates/cli/src/server/actor/mod.rs b/crates/cli/src/server/actor/mod.rs index fbaca2c..10f594d 100644 --- a/crates/cli/src/server/actor/mod.rs +++ b/crates/cli/src/server/actor/mod.rs @@ -7,14 +7,16 @@ mod tests; mod handlers; pub mod messages; +use crate::webhook::WebhookActor; use git_next_core::{ git::{repository::factory::RepositoryFactory, Generation, RepoDetails}, server::{self, InboundWebhook, ServerConfig, ServerStorage}, ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig, StoragePathType, }; -use git_next_repo_actor::messages::NotifyUser; -use git_next_repo_actor::{messages::CloneRepo, RepoActor}; -use git_next_webhook_actor::WebhookActor; +use git_next_repo_actor::{ + messages::{CloneRepo, NotifyUser}, + RepoActor, +}; use kxio::{fs::FileSystem, network::Network}; diff --git a/crates/webhook-actor/src/handlers/mod.rs b/crates/cli/src/webhook/handlers/mod.rs similarity index 100% rename from crates/webhook-actor/src/handlers/mod.rs rename to crates/cli/src/webhook/handlers/mod.rs diff --git a/crates/webhook-actor/src/handlers/shutdown_webhook.rs b/crates/cli/src/webhook/handlers/shutdown_webhook.rs similarity index 80% rename from crates/webhook-actor/src/handlers/shutdown_webhook.rs rename to crates/cli/src/webhook/handlers/shutdown_webhook.rs index 79a1705..8789572 100644 --- a/crates/webhook-actor/src/handlers/shutdown_webhook.rs +++ b/crates/cli/src/webhook/handlers/shutdown_webhook.rs @@ -1,7 +1,7 @@ // use actix::prelude::*; -use crate::{ShutdownWebhook, WebhookActor}; +use crate::webhook::{messages::ShutdownWebhook, WebhookActor}; impl Handler for WebhookActor { type Result = (); diff --git a/crates/webhook-actor/src/messages.rs b/crates/cli/src/webhook/messages.rs similarity index 100% rename from crates/webhook-actor/src/messages.rs rename to crates/cli/src/webhook/messages.rs diff --git a/crates/cli/src/webhook/mod.rs b/crates/cli/src/webhook/mod.rs new file mode 100644 index 0000000..95b5d92 --- /dev/null +++ b/crates/cli/src/webhook/mod.rs @@ -0,0 +1,42 @@ +// +use actix::prelude::*; + +mod handlers; +pub mod messages; +pub mod router; +mod server; + +use git_next_repo_actor::messages::WebhookNotification; + +use std::net::SocketAddr; + +use tracing::Instrument; + +#[derive(Debug)] +pub struct WebhookActor { + socket_addr: SocketAddr, + span: tracing::Span, + spawn_handle: Option, + message_receiver: Recipient, +} +impl WebhookActor { + pub fn new(socket_addr: SocketAddr, message_receiver: Recipient) -> Self { + let span = tracing::info_span!("WebhookActor"); + Self { + socket_addr, + span, + message_receiver, + spawn_handle: None, + } + } +} +impl Actor for WebhookActor { + type Context = actix::Context; + fn started(&mut self, ctx: &mut Self::Context) { + let _gaurd = self.span.enter(); + let address: Recipient = self.message_receiver.clone(); + let server = server::start(self.socket_addr, address); + let spawn_handle = ctx.spawn(server.in_current_span().into_actor(self)); + self.spawn_handle.replace(spawn_handle); + } +} diff --git a/crates/webhook-actor/src/router.rs b/crates/cli/src/webhook/router.rs similarity index 100% rename from crates/webhook-actor/src/router.rs rename to crates/cli/src/webhook/router.rs diff --git a/crates/webhook-actor/src/server.rs b/crates/cli/src/webhook/server.rs similarity index 100% rename from crates/webhook-actor/src/server.rs rename to crates/cli/src/webhook/server.rs diff --git a/crates/webhook-actor/Cargo.toml b/crates/webhook-actor/Cargo.toml index 0dc613f..4c1b32c 100644 --- a/crates/webhook-actor/Cargo.toml +++ b/crates/webhook-actor/Cargo.toml @@ -4,31 +4,4 @@ version = { workspace = true } edition = { workspace = true } license = { workspace = true } repository = { workspace = true } -description = "webhook actor for git-next, the trunk-based development manager" - -[dependencies] -git-next-core = { 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" +description = "[deprecated crate] webhook actor for git-next, the trunk-based development manager" diff --git a/crates/webhook-actor/README.md b/crates/webhook-actor/README.md index ddc70e2..b90af45 100644 --- a/crates/webhook-actor/README.md +++ b/crates/webhook-actor/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](https://crates.io/git-next). diff --git a/crates/webhook-actor/src/lib.rs b/crates/webhook-actor/src/lib.rs index cf670cf..92f16f8 100644 --- a/crates/webhook-actor/src/lib.rs +++ b/crates/webhook-actor/src/lib.rs @@ -1,45 +1 @@ -// -use actix::prelude::*; - -mod handlers; -pub mod messages; -mod router; -mod server; - -use git_next_repo_actor::messages::WebhookNotification; -pub use messages::ShutdownWebhook; - -use std::net::SocketAddr; - -pub use router::AddWebhookRecipient; -pub use router::WebhookRouter; -use tracing::Instrument; - -#[derive(Debug)] -pub struct WebhookActor { - socket_addr: SocketAddr, - span: tracing::Span, - spawn_handle: Option, - message_receiver: Recipient, -} -impl WebhookActor { - pub fn new(socket_addr: SocketAddr, message_receiver: Recipient) -> Self { - let span = tracing::info_span!("WebhookActor"); - Self { - socket_addr, - span, - message_receiver, - spawn_handle: None, - } - } -} -impl Actor for WebhookActor { - type Context = actix::Context; - fn started(&mut self, ctx: &mut Self::Context) { - let _gaurd = self.span.enter(); - let address: Recipient = self.message_receiver.clone(); - let server = server::start(self.socket_addr, address); - let spawn_handle = ctx.spawn(server.in_current_span().into_actor(self)); - self.spawn_handle.replace(spawn_handle); - } -} +// moved to /crates/cli/src/webhook