refactor: extract webhook actor
All checks were successful
Rust / build (push) Successful in 1m19s
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-06-29 08:20:56 +01:00
parent 6d9eb0ab86
commit eba00a112f
9 changed files with 45 additions and 32 deletions

View file

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

View file

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

View file

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

View file

@ -1,4 +1,3 @@
pub mod file_watcher;
pub mod messages;
pub mod server;
pub mod webhook;

View file

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

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

View file

@ -1,4 +1,4 @@
// crate::server::actors::webhook
//
use actix::prelude::*;
mod router;

View file

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