refactor: merge webhook-actor crate into cli crate
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-07-27 19:05:18 +01:00
parent a5b016b527
commit 2850fb9887
15 changed files with 72 additions and 89 deletions

View file

@ -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 }

View file

@ -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

View file

@ -2,6 +2,7 @@
mod file_watcher;
mod init;
mod server;
mod webhook;
#[cfg(test)]
mod tests;

View file

@ -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<ReceiveValidServerConfig> for ServerActor {

View file

@ -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<Shutdown> for ServerActor {
type Result = ();

View file

@ -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};

View file

@ -1,7 +1,7 @@
//
use actix::prelude::*;
use crate::{ShutdownWebhook, WebhookActor};
use crate::webhook::{messages::ShutdownWebhook, WebhookActor};
impl Handler<ShutdownWebhook> for WebhookActor {
type Result = ();

View file

@ -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<actix::SpawnHandle>,
message_receiver: Recipient<WebhookNotification>,
}
impl WebhookActor {
pub fn new(socket_addr: SocketAddr, message_receiver: Recipient<WebhookNotification>) -> Self {
let span = tracing::info_span!("WebhookActor");
Self {
socket_addr,
span,
message_receiver,
spawn_handle: None,
}
}
}
impl Actor for WebhookActor {
type Context = actix::Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
let _gaurd = self.span.enter();
let address: Recipient<WebhookNotification> = 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);
}
}

View file

@ -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"

View file

@ -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).

View file

@ -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<actix::SpawnHandle>,
message_receiver: Recipient<WebhookNotification>,
}
impl WebhookActor {
pub fn new(socket_addr: SocketAddr, message_receiver: Recipient<WebhookNotification>) -> Self {
let span = tracing::info_span!("WebhookActor");
Self {
socket_addr,
span,
message_receiver,
spawn_handle: None,
}
}
}
impl Actor for WebhookActor {
type Context = actix::Context<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
let _gaurd = self.span.enter();
let address: Recipient<WebhookNotification> = 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