forked from kemitix/git-next
refactor: extract webhook actor
This commit is contained in:
parent
6d9eb0ab86
commit
eba00a112f
9 changed files with 45 additions and 32 deletions
|
@ -9,6 +9,7 @@ members = [
|
|||
"crates/forge-forgejo",
|
||||
"crates/forge-github",
|
||||
"crates/repo-actor",
|
||||
"crates/webhook-actor",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
|
@ -29,6 +30,7 @@ git-next-forge = { path = "crates/forge" }
|
|||
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" }
|
||||
|
||||
# CLI parsing
|
||||
clap = { version = "4.5", features = ["cargo", "derive"] }
|
||||
|
|
|
@ -67,6 +67,7 @@ pub struct TestOpenRepository {
|
|||
push_counter: Arc<RwLock<usize>>,
|
||||
real: git::repository::RealOpenRepository,
|
||||
}
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl git::repository::OpenRepositoryLike for TestOpenRepository {
|
||||
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>> {
|
||||
self.real.remote_branches()
|
||||
|
|
|
@ -8,37 +8,16 @@ git-next-config = { workspace = true }
|
|||
git-next-git = { workspace = true }
|
||||
git-next-forge = { workspace = true }
|
||||
git-next-repo-actor = { workspace = true }
|
||||
git-next-webhook-actor = { workspace = true }
|
||||
|
||||
# logging
|
||||
console-subscriber = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
||||
# base64 decoding
|
||||
base64 = { workspace = true }
|
||||
|
||||
# git
|
||||
async-trait = { workspace = true }
|
||||
|
||||
# fs/network
|
||||
kxio = { workspace = true }
|
||||
|
||||
# TOML parsing
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
|
||||
# Secrets and Password
|
||||
secrecy = { workspace = true }
|
||||
|
||||
# Conventional Commit check
|
||||
git-conventional = { workspace = true }
|
||||
|
||||
# Webhooks
|
||||
bytes = { workspace = true }
|
||||
ulid = { workspace = true }
|
||||
warp = { workspace = true }
|
||||
|
||||
# boilerplate
|
||||
derive_more = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
@ -49,7 +28,6 @@ inotify = { workspace = true }
|
|||
# Actors
|
||||
actix = { workspace = true }
|
||||
actix-rt = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# Testing
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
pub mod file_watcher;
|
||||
pub mod messages;
|
||||
pub mod server;
|
||||
pub mod webhook;
|
||||
|
|
|
@ -3,6 +3,7 @@ use std::path::PathBuf;
|
|||
|
||||
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,
|
||||
|
@ -10,14 +11,10 @@ use git_next_config::{
|
|||
use git_next_git::{repository::RepositoryFactory, Generation, RepoDetails};
|
||||
use git_next_repo_actor::messages::CloneRepo;
|
||||
use git_next_repo_actor::RepoActor;
|
||||
use git_next_webhook_actor as webhook;
|
||||
use kxio::{fs::FileSystem, network::Network};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
use crate::actors::{
|
||||
file_watcher::FileUpdated,
|
||||
messages::ReceiveServerConfig,
|
||||
webhook::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter},
|
||||
};
|
||||
use webhook::{AddWebhookRecipient, ShutdownWebhook, WebhookActor, WebhookRouter};
|
||||
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
pub enum Error {
|
||||
|
@ -98,7 +95,7 @@ impl Handler<ReceiveServerConfig> for Server {
|
|||
|
||||
// Webhook Server
|
||||
info!("Starting Webhook Server...");
|
||||
let webhook_router = WebhookRouter::new().start();
|
||||
let webhook_router = WebhookRouter::default().start();
|
||||
let webhook = server_config.webhook();
|
||||
|
||||
// Forge Actors
|
||||
|
|
31
crates/webhook-actor/Cargo.toml
Normal file
31
crates/webhook-actor/Cargo.toml
Normal file
|
@ -0,0 +1,31 @@
|
|||
[package]
|
||||
name = "git-next-webhook-actor"
|
||||
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,4 +1,4 @@
|
|||
// crate::server::actors::webhook
|
||||
//
|
||||
use actix::prelude::*;
|
||||
|
||||
mod router;
|
|
@ -11,6 +11,11 @@ pub struct WebhookRouter {
|
|||
span: tracing::Span,
|
||||
recipients: BTreeMap<ForgeAlias, BTreeMap<RepoAlias, Recipient<WebhookNotification>>>,
|
||||
}
|
||||
impl Default for WebhookRouter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
impl WebhookRouter {
|
||||
pub fn new() -> Self {
|
||||
let span = tracing::info_span!("WebhookRouter");
|
Loading…
Reference in a new issue