forked from kemitix/git-next
refactor: merge webhook-actor crate into cli crate
This commit is contained in:
parent
366930bcfc
commit
12ecc308d5
15 changed files with 72 additions and 89 deletions
|
@ -16,7 +16,6 @@ git-next-core = { workspace = true }
|
||||||
git-next-server-actor = { workspace = true }
|
git-next-server-actor = { workspace = true }
|
||||||
git-next-forge = { workspace = true }
|
git-next-forge = { workspace = true }
|
||||||
git-next-repo-actor = { workspace = true }
|
git-next-repo-actor = { workspace = true }
|
||||||
git-next-webhook-actor = { workspace = true }
|
|
||||||
|
|
||||||
# CLI parsing
|
# CLI parsing
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
|
@ -45,6 +44,8 @@ ulid = { workspace = true }
|
||||||
time = { workspace = true }
|
time = { workspace = true }
|
||||||
secrecy = { workspace = true }
|
secrecy = { workspace = true }
|
||||||
standardwebhooks = { workspace = true }
|
standardwebhooks = { workspace = true }
|
||||||
|
bytes = { workspace = true }
|
||||||
|
warp = { workspace = true }
|
||||||
|
|
||||||
# file watcher (linux)
|
# file watcher (linux)
|
||||||
inotify = { workspace = true }
|
inotify = { workspace = true }
|
||||||
|
|
|
@ -522,7 +522,6 @@ stateDiagram-v2
|
||||||
cli --> core
|
cli --> core
|
||||||
cli --> forge
|
cli --> forge
|
||||||
cli --> repo_actor
|
cli --> repo_actor
|
||||||
cli --> webhook_actor
|
|
||||||
|
|
||||||
forge --> core
|
forge --> core
|
||||||
forge --> forge_forgejo
|
forge --> forge_forgejo
|
||||||
|
@ -534,9 +533,6 @@ stateDiagram-v2
|
||||||
|
|
||||||
repo_actor --> core
|
repo_actor --> core
|
||||||
repo_actor --> forge
|
repo_actor --> forge
|
||||||
|
|
||||||
webhook_actor --> core
|
|
||||||
webhook_actor --> repo_actor
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
mod file_watcher;
|
mod file_watcher;
|
||||||
mod init;
|
mod init;
|
||||||
mod server;
|
mod server;
|
||||||
|
mod webhook;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
|
//
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use git_next_webhook_actor::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter};
|
|
||||||
|
|
||||||
use crate::server::actor::{
|
use crate::{
|
||||||
messages::{ReceiveValidServerConfig, ValidServerConfig},
|
server::actor::{
|
||||||
ServerActor,
|
messages::{ReceiveValidServerConfig, ValidServerConfig},
|
||||||
|
ServerActor,
|
||||||
|
},
|
||||||
|
webhook::{
|
||||||
|
messages::ShutdownWebhook,
|
||||||
|
router::{AddWebhookRecipient, WebhookRouter},
|
||||||
|
WebhookActor,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Handler<ReceiveValidServerConfig> for ServerActor {
|
impl Handler<ReceiveValidServerConfig> for ServerActor {
|
||||||
|
|
|
@ -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 {
|
impl Handler<Shutdown> for ServerActor {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
|
@ -7,14 +7,16 @@ mod tests;
|
||||||
mod handlers;
|
mod handlers;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
|
|
||||||
|
use crate::webhook::WebhookActor;
|
||||||
use git_next_core::{
|
use git_next_core::{
|
||||||
git::{repository::factory::RepositoryFactory, Generation, RepoDetails},
|
git::{repository::factory::RepositoryFactory, Generation, RepoDetails},
|
||||||
server::{self, InboundWebhook, ServerConfig, ServerStorage},
|
server::{self, InboundWebhook, ServerConfig, ServerStorage},
|
||||||
ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig, StoragePathType,
|
ForgeAlias, ForgeConfig, GitDir, RepoAlias, ServerRepoConfig, StoragePathType,
|
||||||
};
|
};
|
||||||
use git_next_repo_actor::messages::NotifyUser;
|
use git_next_repo_actor::{
|
||||||
use git_next_repo_actor::{messages::CloneRepo, RepoActor};
|
messages::{CloneRepo, NotifyUser},
|
||||||
use git_next_webhook_actor::WebhookActor;
|
RepoActor,
|
||||||
|
};
|
||||||
|
|
||||||
use kxio::{fs::FileSystem, network::Network};
|
use kxio::{fs::FileSystem, network::Network};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
|
|
||||||
use crate::{ShutdownWebhook, WebhookActor};
|
use crate::webhook::{messages::ShutdownWebhook, WebhookActor};
|
||||||
|
|
||||||
impl Handler<ShutdownWebhook> for WebhookActor {
|
impl Handler<ShutdownWebhook> for WebhookActor {
|
||||||
type Result = ();
|
type Result = ();
|
42
crates/cli/src/webhook/mod.rs
Normal file
42
crates/cli/src/webhook/mod.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,31 +4,4 @@ version = { workspace = true }
|
||||||
edition = { workspace = true }
|
edition = { workspace = true }
|
||||||
license = { workspace = true }
|
license = { workspace = true }
|
||||||
repository = { workspace = true }
|
repository = { workspace = true }
|
||||||
description = "webhook actor for git-next, the trunk-based development manager"
|
description = "[deprecated crate] 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"
|
|
||||||
|
|
|
@ -7,3 +7,5 @@ development workflows where each commit must pass CI before being included in
|
||||||
the main branch.
|
the main branch.
|
||||||
|
|
||||||
See [git-next](https://crates.io/crates/git-next) for more information.
|
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).
|
||||||
|
|
|
@ -1,45 +1 @@
|
||||||
//
|
// moved to /crates/cli/src/webhook
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue