diff --git a/Cargo.toml b/Cargo.toml index aa65f52a..98d5cae7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,11 +15,11 @@ documentation = "https://git.kemitix.net/kemitix/git-next/src/branch/main/README keywords = ["git", "cli", "server", "tool"] categories = ["development-tools"] -[workspace.lints.clippy] -nursery = { level = "warn", priority = -1 } -# pedantic = "warn" -unwrap_used = "warn" -expect_used = "warn" +# [workspace.lints.clippy] +# pedantic = { level = "warn", priority = -1 } +# nursery = { level = "warn", priority = -1 } +# unwrap_used = "warn" +# expect_used = "warn" [workspace.dependencies] git-next-core = { path = "crates/core", version = "0.13" } diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index c74f1a2a..e068f14f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -76,7 +76,7 @@ mockall = { workspace = true } [lints.clippy] nursery = { level = "warn", priority = -1 } -# pedantic = "warn" +pedantic = { level = "warn", priority = -1 } unwrap_used = "warn" expect_used = "warn" diff --git a/crates/cli/src/alerts/email.rs b/crates/cli/src/alerts/email.rs index 2dfadbfc..2f12cbdb 100644 --- a/crates/cli/src/alerts/email.rs +++ b/crates/cli/src/alerts/email.rs @@ -23,11 +23,11 @@ pub(super) fn send_email(user_notification: &UserNotification, email_config: &Em }; match email_config.smtp() { Some(smtp) => send_email_smtp(email_message, smtp), - None => send_email_sendmail(email_message), + None => send_email_sendmail(&email_message), } } -fn send_email_sendmail(email_message: EmailMessage) { +fn send_email_sendmail(email_message: &EmailMessage) { use sendmail::email; match email::send( &email_message.from, @@ -35,7 +35,7 @@ fn send_email_sendmail(email_message: EmailMessage) { &email_message.subject, &email_message.body, ) { - Ok(_) => tracing::info!("Email sent successfully!"), + Ok(()) => tracing::info!("Email sent successfully!"), Err(e) => tracing::warn!("Could not send email: {:?}", e), } } @@ -62,7 +62,7 @@ fn do_send_email_smtp(email_message: EmailMessage, smtp: &SmtpConfig) -> Result< .map(|response| { response .message() - .map(|s| s.to_string()) + .map(ToString::to_string) .collect::>() }) .map(|response| { diff --git a/crates/cli/src/alerts/history.rs b/crates/cli/src/alerts/history.rs index 99fe61f9..de15a95f 100644 --- a/crates/cli/src/alerts/history.rs +++ b/crates/cli/src/alerts/history.rs @@ -16,7 +16,7 @@ pub struct History { /// Maps a user notification to when it was last seen. /// - /// The user notification will not be sent until after max_age_seconds from last seen. + /// The user notification will not be sent until after `max_age_seconds` from last seen. /// /// Each time we see a given user notification, the last seen time will be updated. items: HashMap, @@ -44,7 +44,7 @@ impl History { pub fn prune(&mut self, now: &Instant) { if let Some(threshold) = now.checked_sub(self.max_age_seconds) { - self.items.retain(|_, last_seen| *last_seen > threshold) + self.items.retain(|_, last_seen| *last_seen > threshold); }; } } diff --git a/crates/cli/src/alerts/mod.rs b/crates/cli/src/alerts/mod.rs index d2980535..18ae6b3f 100644 --- a/crates/cli/src/alerts/mod.rs +++ b/crates/cli/src/alerts/mod.rs @@ -17,6 +17,7 @@ mod webhook; #[cfg(test)] mod tests; +#[allow(clippy::module_name_repetitions)] #[derive(Debug, Constructor)] pub struct AlertsActor { shout: Option, // config for sending alerts to users diff --git a/crates/cli/src/alerts/webhook.rs b/crates/cli/src/alerts/webhook.rs index 3d7cdec7..75647e79 100644 --- a/crates/cli/src/alerts/webhook.rs +++ b/crates/cli/src/alerts/webhook.rs @@ -1,5 +1,6 @@ // use git_next_core::{git::UserNotification, server::OutboundWebhook}; +use kxio::network::{NetRequest, NetUrl, RequestBody, ResponseType}; use secrecy::ExposeSecret as _; use standardwebhooks::Webhook; @@ -35,7 +36,7 @@ async fn do_send_webhook( .expect("signature"); tracing::info!(?signature, ""); let url = webhook_config.url(); - use kxio::network::{NetRequest, NetUrl, RequestBody, ResponseType}; + let net_url = NetUrl::new(url.to_string()); let request = NetRequest::post(net_url) .body(RequestBody::Json(payload)) diff --git a/crates/cli/src/init.rs b/crates/cli/src/init.rs index fde940b9..a13a10a1 100644 --- a/crates/cli/src/init.rs +++ b/crates/cli/src/init.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use kxio::fs::FileSystem; -pub fn run(fs: FileSystem) -> Result<()> { +pub fn run(fs: &FileSystem) -> Result<()> { let pathbuf = fs.base().join(".git-next.toml"); if fs .path_exists(&pathbuf) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index c5ceb23e..8b8f021a 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -44,11 +44,11 @@ fn main() -> Result<()> { match commands.command { Command::Init => { - init::run(fs)?; + init::run(&fs)?; } Command::Server(server) => match server { Server::Init => { - server::init(fs)?; + server::init(&fs)?; } Server::Start => { let sleep_duration = std::time::Duration::from_secs(10); diff --git a/crates/cli/src/repo/branch.rs b/crates/cli/src/repo/branch.rs index 55b8ecd1..3bd4cde6 100644 --- a/crates/cli/src/repo/branch.rs +++ b/crates/cli/src/repo/branch.rs @@ -66,7 +66,7 @@ pub fn find_next_commit_on_dev( ) -> (Option, Force) { let mut next_commit: Option<&Commit> = None; let mut force = Force::No; - for commit in dev_commit_history.iter() { + for commit in dev_commit_history { if commit == next { break; }; diff --git a/crates/cli/src/repo/handlers/advance_main.rs b/crates/cli/src/repo/handlers/advance_main.rs index 5831d454..8e250085 100644 --- a/crates/cli/src/repo/handlers/advance_main.rs +++ b/crates/cli/src/repo/handlers/advance_main.rs @@ -36,12 +36,12 @@ impl Handler for RepoActor { Err(err) => { warn!("advance main: {err}"); } - Ok(_) => match repo_config.source() { + Ok(()) => match repo_config.source() { RepoConfigSource::Repo => { - do_send(addr, LoadConfigFromRepo, self.log.as_ref()); + do_send(&addr, LoadConfigFromRepo, self.log.as_ref()); } RepoConfigSource::Server => { - do_send(addr, ValidateRepo::new(message_token), self.log.as_ref()); + do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); } }, } diff --git a/crates/cli/src/repo/handlers/advance_next.rs b/crates/cli/src/repo/handlers/advance_next.rs index cdcd2f99..747db940 100644 --- a/crates/cli/src/repo/handlers/advance_next.rs +++ b/crates/cli/src/repo/handlers/advance_next.rs @@ -41,7 +41,7 @@ impl Handler for RepoActor { Ok(message_token) => { // pause to allow any CI checks to be started std::thread::sleep(self.sleep_duration); - do_send(addr, ValidateRepo::new(message_token), self.log.as_ref()); + do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); } Err(err) => warn!("advance next: {err}"), } diff --git a/crates/cli/src/repo/handlers/check_ci_status.rs b/crates/cli/src/repo/handlers/check_ci_status.rs index 853eba5f..122f0199 100644 --- a/crates/cli/src/repo/handlers/check_ci_status.rs +++ b/crates/cli/src/repo/handlers/check_ci_status.rs @@ -23,7 +23,7 @@ impl Handler for RepoActor { async move { let status = forge.commit_status(&next).await; debug!("got status: {status:?}"); - do_send(addr, ReceiveCIStatus::new((next, status)), log.as_ref()); + do_send(&addr, ReceiveCIStatus::new((next, status)), log.as_ref()); } .in_current_span() .into_actor(self) diff --git a/crates/cli/src/repo/handlers/clone_repo.rs b/crates/cli/src/repo/handlers/clone_repo.rs index 366f2958..a851c694 100644 --- a/crates/cli/src/repo/handlers/clone_repo.rs +++ b/crates/cli/src/repo/handlers/clone_repo.rs @@ -22,14 +22,14 @@ impl Handler for RepoActor { debug!("open okay"); self.open_repository.replace(repository); if self.repo_details.repo_config.is_none() { - do_send(ctx.address(), LoadConfigFromRepo, self.log.as_ref()); + do_send(&ctx.address(), LoadConfigFromRepo, self.log.as_ref()); } else { - do_send(ctx.address(), RegisterWebhook::new(), self.log.as_ref()); + do_send(&ctx.address(), RegisterWebhook::new(), self.log.as_ref()); } } Err(err) => { logger(self.log.as_ref(), "open failed"); - warn!("Could not open repo: {err:?}") + warn!("Could not open repo: {err:?}"); } } debug!("Handler: CloneRepo: finish"); diff --git a/crates/cli/src/repo/handlers/load_config_from_repo.rs b/crates/cli/src/repo/handlers/load_config_from_repo.rs index 5c00ecca..dd3567be 100644 --- a/crates/cli/src/repo/handlers/load_config_from_repo.rs +++ b/crates/cli/src/repo/handlers/load_config_from_repo.rs @@ -28,7 +28,9 @@ impl Handler for RepoActor { let log = self.log.clone(); async move { match load::config_from_repository(repo_details, &*open_repository).await { - Ok(repo_config) => do_send(addr, ReceiveRepoConfig::new(repo_config), log.as_ref()), + Ok(repo_config) => { + do_send(&addr, ReceiveRepoConfig::new(repo_config), log.as_ref()); + } Err(err) => notify_user( notify_user_recipient.as_ref(), UserNotification::RepoConfigLoadFailure { diff --git a/crates/cli/src/repo/handlers/receive_ci_status.rs b/crates/cli/src/repo/handlers/receive_ci_status.rs index 25176621..75c40bd9 100644 --- a/crates/cli/src/repo/handlers/receive_ci_status.rs +++ b/crates/cli/src/repo/handlers/receive_ci_status.rs @@ -26,11 +26,11 @@ impl Handler for RepoActor { debug!(?status, ""); match status { Status::Pass => { - do_send(addr, AdvanceMain::new(next), self.log.as_ref()); + do_send(&addr, AdvanceMain::new(next), self.log.as_ref()); } Status::Pending => { std::thread::sleep(sleep_duration); - do_send(addr, ValidateRepo::new(message_token), self.log.as_ref()); + do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref()); } Status::Fail => { tracing::warn!("Checks have failed"); @@ -44,7 +44,7 @@ impl Handler for RepoActor { log.as_ref(), ); delay_send( - addr, + &addr, sleep_duration, ValidateRepo::new(message_token), self.log.as_ref(), diff --git a/crates/cli/src/repo/handlers/receive_repo_config.rs b/crates/cli/src/repo/handlers/receive_repo_config.rs index 8d2c7152..12934d8e 100644 --- a/crates/cli/src/repo/handlers/receive_repo_config.rs +++ b/crates/cli/src/repo/handlers/receive_repo_config.rs @@ -15,6 +15,6 @@ impl Handler for RepoActor { let repo_config = msg.unwrap(); self.repo_details.repo_config.replace(repo_config); - do_send(ctx.address(), RegisterWebhook::new(), self.log.as_ref()); + do_send(&ctx.address(), RegisterWebhook::new(), self.log.as_ref()); } } diff --git a/crates/cli/src/repo/handlers/register_webhook.rs b/crates/cli/src/repo/handlers/register_webhook.rs index 563024c7..4981918a 100644 --- a/crates/cli/src/repo/handlers/register_webhook.rs +++ b/crates/cli/src/repo/handlers/register_webhook.rs @@ -31,7 +31,7 @@ impl Handler for RepoActor { Ok(registered_webhook) => { debug!(?registered_webhook, ""); do_send( - addr, + &addr, WebhookRegistered::from(registered_webhook), log.as_ref(), ); diff --git a/crates/cli/src/repo/handlers/unregister_webhook.rs b/crates/cli/src/repo/handlers/unregister_webhook.rs index 4163f9a7..8c748aca 100644 --- a/crates/cli/src/repo/handlers/unregister_webhook.rs +++ b/crates/cli/src/repo/handlers/unregister_webhook.rs @@ -14,7 +14,7 @@ impl Handler for RepoActor { debug!("unregistering webhook"); async move { match forge.unregister_webhook(&webhook_id).await { - Ok(_) => debug!("unregistered webhook"), + Ok(()) => debug!("unregistered webhook"), Err(err) => warn!(?err, "unregistering webhook"), } } diff --git a/crates/cli/src/repo/handlers/validate_repo.rs b/crates/cli/src/repo/handlers/validate_repo.rs index 0cb18a6e..92a7ba7a 100644 --- a/crates/cli/src/repo/handlers/validate_repo.rs +++ b/crates/cli/src/repo/handlers/validate_repo.rs @@ -1,7 +1,6 @@ // use actix::prelude::*; -use derive_more::Deref as _; use tracing::{debug, instrument, Instrument as _}; use crate::repo::{ @@ -15,7 +14,7 @@ use git_next_core::git::validation::positions::{validate_positions, Error, Posit impl Handler for RepoActor { type Result = (); - #[instrument(name = "RepoActor::ValidateRepo", skip_all, fields(repo = %self.repo_details, token = %msg.deref()))] + #[instrument(name = "RepoActor::ValidateRepo", skip_all, fields(repo = %self.repo_details, token = %&*msg))] fn handle(&mut self, msg: ValidateRepo, ctx: &mut Self::Context) -> Self::Result { logger(self.log.as_ref(), "start: ValidateRepo"); @@ -64,17 +63,17 @@ impl Handler for RepoActor { }) => { debug!(%main, %next, %dev, "positions"); if next_is_valid && next != main { - do_send(ctx.address(), CheckCIStatus::new(next), self.log.as_ref()); + do_send(&ctx.address(), CheckCIStatus::new(next), self.log.as_ref()); } else if next != dev { do_send( - ctx.address(), + &ctx.address(), AdvanceNext::new(AdvanceNextPayload { next, main, dev_commit_history, }), self.log.as_ref(), - ) + ); } else { // do nothing } @@ -90,7 +89,7 @@ impl Handler for RepoActor { logger(log.as_ref(), "before sleep"); actix_rt::time::sleep(sleep_duration).await; logger(log.as_ref(), "after sleep"); - do_send(addr, ValidateRepo::new(message_token), log.as_ref()); + do_send(&addr, ValidateRepo::new(message_token), log.as_ref()); } .in_current_span() .into_actor(self) diff --git a/crates/cli/src/repo/handlers/webhook_notification.rs b/crates/cli/src/repo/handlers/webhook_notification.rs index f4284536..930d61ea 100644 --- a/crates/cli/src/repo/handlers/webhook_notification.rs +++ b/crates/cli/src/repo/handlers/webhook_notification.rs @@ -6,7 +6,7 @@ use tracing::{info, instrument, warn}; use crate::repo::{ do_send, logger, messages::{ValidateRepo, WebhookNotification}, - RepoActor, RepoActorLog, + ActorLog, RepoActor, }; use git_next_core::{ @@ -54,7 +54,7 @@ impl Handler for RepoActor { Some(Branch::Main) => { if handle_push( push, - config.branches().main(), + &config.branches().main(), &mut self.last_main_commit, self.log.as_ref(), ) @@ -66,7 +66,7 @@ impl Handler for RepoActor { Some(Branch::Next) => { if handle_push( push, - config.branches().next(), + &config.branches().next(), &mut self.last_next_commit, self.log.as_ref(), ) @@ -78,7 +78,7 @@ impl Handler for RepoActor { Some(Branch::Dev) => { if handle_push( push, - config.branches().dev(), + &config.branches().dev(), &mut self.last_dev_commit, self.log.as_ref(), ) @@ -95,7 +95,7 @@ impl Handler for RepoActor { "New commit" ); do_send( - ctx.address(), + &ctx.address(), ValidateRepo::new(message_token), self.log.as_ref(), ); @@ -106,7 +106,7 @@ fn validate_notification( msg: &WebhookNotification, webhook_auth: Option<&WebhookAuth>, forge: &dyn ForgeLike, - log: Option<&RepoActorLog>, + log: Option<&ActorLog>, ) -> Result<(), ()> { let Some(expected_authorization) = webhook_auth else { logger(log, "server has no auth token"); @@ -131,9 +131,9 @@ fn validate_notification( fn handle_push( push: Push, - branch: BranchName, + branch: &BranchName, last_commit: &mut Option, - log: Option<&RepoActorLog>, + log: Option<&ActorLog>, ) -> Result<(), ()> { logger(log, "message is for dev branch"); let commit = Commit::from(push); diff --git a/crates/cli/src/repo/handlers/webhook_registered.rs b/crates/cli/src/repo/handlers/webhook_registered.rs index 6eeb769c..a3a5aaed 100644 --- a/crates/cli/src/repo/handlers/webhook_registered.rs +++ b/crates/cli/src/repo/handlers/webhook_registered.rs @@ -15,7 +15,7 @@ impl Handler for RepoActor { self.webhook_id.replace(msg.webhook_id().clone()); self.webhook_auth.replace(msg.webhook_auth().clone()); do_send( - ctx.address(), + &ctx.address(), ValidateRepo::new(self.message_token), self.log.as_ref(), ); diff --git a/crates/cli/src/repo/messages.rs b/crates/cli/src/repo/messages.rs index 63cb067d..0a2ccf34 100644 --- a/crates/cli/src/repo/messages.rs +++ b/crates/cli/src/repo/messages.rs @@ -46,7 +46,7 @@ Primarily used by [ValidateRepo] to reduce duplicate messages. The token is incr received, marking that message the latest, and causing any previous messages still being processed to be dropped when they next send a [ValidateRepo] message."#); impl MessageToken { - pub const fn next(&self) -> Self { + pub const fn next(self) -> Self { Self(self.0 + 1) } } diff --git a/crates/cli/src/repo/mod.rs b/crates/cli/src/repo/mod.rs index c9cd263b..7a0c3bc5 100644 --- a/crates/cli/src/repo/mod.rs +++ b/crates/cli/src/repo/mod.rs @@ -27,8 +27,8 @@ mod notifications; pub mod tests; #[derive(Clone, Debug, Default)] -pub struct RepoActorLog(std::sync::Arc>>); -impl Deref for RepoActorLog { +pub struct ActorLog(std::sync::Arc>>); +impl Deref for ActorLog { type Target = std::sync::Arc>>; fn deref(&self) -> &Self::Target { @@ -38,7 +38,8 @@ impl Deref for RepoActorLog { /// An actor that represents a Git Repository. /// -/// When this actor is started it is sent the [CloneRepo] message. +/// When this actor is started it is sent the `CloneRepo` message. +#[allow(clippy::module_name_repetitions)] #[derive(Debug, derive_more::Display, derive_with::With)] #[display("{}:{}:{}", generation, repo_details.forge.forge_alias(), repo_details.repo_alias)] pub struct RepoActor { @@ -56,7 +57,7 @@ pub struct RepoActor { open_repository: Option>, net: Network, forge: Box, - log: Option, + log: Option, notify_user_recipient: Option>, } impl RepoActor { @@ -118,33 +119,35 @@ impl Actor for RepoActor { } } -pub fn delay_send(addr: Addr, delay: Duration, msg: M, log: Option<&RepoActorLog>) +pub fn delay_send(addr: &Addr, delay: Duration, msg: M, log: Option<&ActorLog>) where M: actix::Message + Send + 'static + std::fmt::Debug, RepoActor: actix::Handler, ::Result: Send, { - let log_message = format!("send-after-delay: {:?}", msg); + let log_message = format!("send-after-delay: {msg:?}"); tracing::debug!(log_message); logger(log, log_message); std::thread::sleep(delay); - do_send(addr, msg, log) + do_send(addr, msg, log); } -pub fn do_send(_addr: Addr, msg: M, log: Option<&RepoActorLog>) +pub fn do_send(addr: &Addr, msg: M, log: Option<&ActorLog>) where M: actix::Message + Send + 'static + std::fmt::Debug, RepoActor: actix::Handler, ::Result: Send, { - let log_message = format!("send: {:?}", msg); + let log_message = format!("send: {msg:?}"); tracing::debug!(log_message); logger(log, log_message); - #[cfg(not(test))] - _addr.do_send(msg) + if cfg!(not(test)) { + // #[cfg(not(test))] + addr.do_send(msg); + } } -pub fn logger(log: Option<&RepoActorLog>, message: impl Into) { +pub fn logger(log: Option<&ActorLog>, message: impl Into) { if let Some(log) = log { let message: String = message.into(); tracing::debug!(message); @@ -154,10 +157,10 @@ pub fn logger(log: Option<&RepoActorLog>, message: impl Into) { pub fn notify_user( recipient: Option<&Recipient>, user_notification: UserNotification, - log: Option<&RepoActorLog>, + log: Option<&ActorLog>, ) { let msg = NotifyUser::from(user_notification); - let log_message = format!("send: {:?}", msg); + let log_message = format!("send: {msg:?}"); tracing::debug!(log_message); logger(log, log_message); if let Some(recipient) = &recipient { diff --git a/crates/cli/src/repo/notifications.rs b/crates/cli/src/repo/notifications.rs index 1ec3bc2b..c54e612a 100644 --- a/crates/cli/src/repo/notifications.rs +++ b/crates/cli/src/repo/notifications.rs @@ -1,5 +1,4 @@ // -use derive_more::Deref as _; use crate::repo::messages::NotifyUser; @@ -10,7 +9,7 @@ use serde_json::json; impl NotifyUser { pub fn as_json(&self, timestamp: time::OffsetDateTime) -> serde_json::Value { let timestamp = timestamp.unix_timestamp().to_string(); - match self.deref() { + match &**self { UserNotification::CICheckFailed { forge_alias, repo_alias, diff --git a/crates/cli/src/repo/tests/branch/advance_next.rs b/crates/cli/src/repo/tests/branch/advance_next.rs index 32c443ca..cddc8865 100644 --- a/crates/cli/src/repo/tests/branch/advance_next.rs +++ b/crates/cli/src/repo/tests/branch/advance_next.rs @@ -4,8 +4,9 @@ use super::*; mod when_at_dev { // next and dev branches are the same use super::*; + #[test] - fn should_not_push() -> TestResult { + fn should_not_push() { let next = given::a_commit(); let main = &next; let dev_commit_history = &[next.clone()]; @@ -27,7 +28,6 @@ mod when_at_dev { ); tracing::debug!("Got: {err}"); assert!(matches!(err, branch::Error::NextAtDev)); - Ok(()) } } @@ -40,7 +40,7 @@ mod can_advance { use super::*; #[test] - fn should_not_push() -> TestResult { + fn should_not_push() { let next = given::a_commit(); let main = &next; let dev = given::a_commit_with_message("wip: test: message".to_string()); @@ -63,7 +63,6 @@ mod can_advance { ); tracing::debug!("Got: {err}"); assert!(matches!(err, branch::Error::IsWorkInProgress)); - Ok(()) } } @@ -72,7 +71,7 @@ mod can_advance { use super::*; #[test] - fn should_not_push_and_error() -> TestResult { + fn should_not_push_and_error() { let next = given::a_commit(); let main = &next; let dev = given::a_commit(); @@ -99,7 +98,6 @@ mod can_advance { branch::Error::InvalidCommitMessage{reason} if reason == "Missing type in the commit summary, expected `type: description`" )); - Ok(()) } } @@ -112,7 +110,7 @@ mod can_advance { use super::*; #[test] - fn should_error() -> TestResult { + fn should_error() { let next = given::a_commit(); let main = &next; let dev = given::a_commit_with_message("test: message".to_string()); @@ -136,7 +134,6 @@ mod can_advance { ); tracing::debug!("Got: {err:?}"); assert!(matches!(err, branch::Error::Push(git::push::Error::Lock))); - Ok(()) } } @@ -145,7 +142,7 @@ mod can_advance { use super::*; #[test] - fn should_ok() -> TestResult { + fn should_ok() { let next = given::a_commit(); let main = &next; let dev = given::a_commit_with_message("test: message".to_string()); @@ -169,7 +166,6 @@ mod can_advance { ); tracing::debug!("Got: {mt:?}"); assert_eq!(mt, message_token); - Ok(()) } } } diff --git a/crates/cli/src/repo/tests/expect.rs b/crates/cli/src/repo/tests/expect.rs index 1050aec6..16fe8828 100644 --- a/crates/cli/src/repo/tests/expect.rs +++ b/crates/cli/src/repo/tests/expect.rs @@ -15,7 +15,7 @@ pub fn fetch(open_repository: &mut MockOpenRepositoryLike, result: Result<(), fe } pub fn push_ok(open_repository: &mut MockOpenRepositoryLike) { - expect::push(open_repository, Ok(())) + expect::push(open_repository, Ok(())); } pub fn push( diff --git a/crates/cli/src/repo/tests/given.rs b/crates/cli/src/repo/tests/given.rs index 22f7985e..e8da64ea 100644 --- a/crates/cli/src/repo/tests/given.rs +++ b/crates/cli/src/repo/tests/given.rs @@ -20,12 +20,12 @@ pub fn has_remote_defaults( open_repository: &mut MockOpenRepositoryLike, remotes: HashMap>, ) { - remotes.into_iter().for_each(|(direction, remote)| { + for (direction, remote) in remotes { open_repository .expect_find_default_remote() .with(eq(direction)) .return_once(|_| remote); - }); + } } pub fn a_webhook_auth() -> WebhookAuth { @@ -89,7 +89,7 @@ pub fn a_forge_config() -> ForgeConfig { a_name(), a_name(), a_name(), - Default::default(), // no repos + BTreeMap::default(), // no repos ) } @@ -170,6 +170,7 @@ pub fn a_message_token() -> MessageToken { MessageToken::default() } +#[allow(clippy::unnecessary_box_returns)] pub fn a_forge() -> Box { Box::new(MockForgeLike::new()) } @@ -179,10 +180,10 @@ pub fn a_repo_actor( repository_factory: Box, forge: Box, net: kxio::network::Network, -) -> (RepoActor, RepoActorLog) { +) -> (RepoActor, ActorLog) { let listen_url = given::a_listen_url(); let generation = Generation::default(); - let log = RepoActorLog::default(); + let log = ActorLog::default(); let actors_log = log.clone(); ( RepoActor::new( diff --git a/crates/cli/src/repo/tests/handlers/advance_main.rs b/crates/cli/src/repo/tests/handlers/advance_main.rs index cf999a42..9812c9f7 100644 --- a/crates/cli/src/repo/tests/handlers/advance_main.rs +++ b/crates/cli/src/repo/tests/handlers/advance_main.rs @@ -41,7 +41,7 @@ async fn when_repo_config_should_fetch_then_push_then_revalidate() -> TestResult log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: LoadConfigFromRepo"))) + .any(|message| message.contains("send: LoadConfigFromRepo"))); })?; Ok(()) } @@ -86,7 +86,7 @@ async fn when_server_config_should_fetch_then_push_then_revalidate() -> TestResu log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: ValidateRepo"))) + .any(|message| message.contains("send: ValidateRepo"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/advance_next.rs b/crates/cli/src/repo/tests/handlers/advance_next.rs index f068de3b..f5168e3b 100644 --- a/crates/cli/src/repo/tests/handlers/advance_next.rs +++ b/crates/cli/src/repo/tests/handlers/advance_next.rs @@ -48,7 +48,7 @@ async fn should_fetch_then_push_then_revalidate() -> TestResult { log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: ValidateRepo"))) + .any(|message| message.contains("send: ValidateRepo"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/check_ci_status.rs b/crates/cli/src/repo/tests/handlers/check_ci_status.rs index f7a6ea38..c682b084 100644 --- a/crates/cli/src/repo/tests/handlers/check_ci_status.rs +++ b/crates/cli/src/repo/tests/handlers/check_ci_status.rs @@ -31,7 +31,7 @@ async fn should_passthrough_to_receive_ci_status() -> TestResult { log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: ReceiveCIStatus"))) + .any(|message| message.contains("send: ReceiveCIStatus"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/loaded_config.rs b/crates/cli/src/repo/tests/handlers/loaded_config.rs index 6ff18bea..c5c2ee41 100644 --- a/crates/cli/src/repo/tests/handlers/loaded_config.rs +++ b/crates/cli/src/repo/tests/handlers/loaded_config.rs @@ -57,7 +57,7 @@ async fn should_register_webhook() -> TestResult { log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: RegisterWebhook"))) + .any(|message| message.contains("send: RegisterWebhook"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/receive_ci_status.rs b/crates/cli/src/repo/tests/handlers/receive_ci_status.rs index 3c1479ec..d564349d 100644 --- a/crates/cli/src/repo/tests/handlers/receive_ci_status.rs +++ b/crates/cli/src/repo/tests/handlers/receive_ci_status.rs @@ -24,9 +24,9 @@ async fn when_pass_should_advance_main_to_next() -> TestResult { //then tracing::debug!(?log, ""); log.read().map_err(|e| e.to_string()).map(|l| { - let expected = format!("send: AdvanceMain({:?})", next_commit); + let expected = format!("send: AdvanceMain({next_commit:?})"); tracing::debug!(%expected,""); - assert!(l.iter().any(|message| message.contains(&expected))) + assert!(l.iter().any(|message| message.contains(&expected))); })?; Ok(()) } @@ -56,7 +56,7 @@ async fn when_pending_should_recheck_ci_status() -> TestResult { log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: ValidateRepo"))) + .any(|message| message.contains("send: ValidateRepo"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/register_webhook.rs b/crates/cli/src/repo/tests/handlers/register_webhook.rs index 58674438..46105eee 100644 --- a/crates/cli/src/repo/tests/handlers/register_webhook.rs +++ b/crates/cli/src/repo/tests/handlers/register_webhook.rs @@ -31,7 +31,7 @@ async fn when_registered_ok_should_send_webhook_registered() -> TestResult { log.read().map_err(|e| e.to_string()).map(|l| { assert!(l .iter() - .any(|message| message.contains("send: WebhookRegistered"))) + .any(|message| message.contains("send: WebhookRegistered"))); })?; Ok(()) } diff --git a/crates/cli/src/repo/tests/handlers/webhook_notification.rs b/crates/cli/src/repo/tests/handlers/webhook_notification.rs index b3d74de2..9f6994af 100644 --- a/crates/cli/src/repo/tests/handlers/webhook_notification.rs +++ b/crates/cli/src/repo/tests/handlers/webhook_notification.rs @@ -9,7 +9,7 @@ async fn when_no_expected_auth_token_drop_notification() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let (actor, log) = given::a_repo_actor( @@ -43,7 +43,7 @@ async fn when_no_repo_config_drop_notification() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let (actor, log) = given::a_repo_actor( @@ -77,7 +77,7 @@ async fn when_message_auth_is_invalid_drop_notification() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let mut forge = given::a_forge(); @@ -115,7 +115,7 @@ async fn when_message_is_ignorable_drop_notification() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let mut forge = given::a_forge(); @@ -157,7 +157,7 @@ async fn when_message_is_not_a_push_drop_notification() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let mut forge = given::a_forge(); @@ -200,7 +200,7 @@ async fn when_message_is_push_on_unknown_branch_drop_notification() -> TestResul let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let commit = given::a_commit(); @@ -248,7 +248,7 @@ async fn when_message_is_push_already_seen_commit_to_main() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let commit = given::a_commit(); @@ -297,7 +297,7 @@ async fn when_message_is_push_already_seen_commit_to_next() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let commit = given::a_commit(); @@ -346,7 +346,7 @@ async fn when_message_is_push_already_seen_commit_to_dev() -> TestResult { let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let commit = given::a_commit(); @@ -395,7 +395,7 @@ async fn when_message_is_push_new_commit_to_main_should_stash_and_validate_repo( let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let push_commit = given::a_commit(); @@ -443,7 +443,7 @@ async fn when_message_is_push_new_commit_to_next_should_stash_and_validate_repo( let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let push_commit = given::a_commit(); @@ -491,7 +491,7 @@ async fn when_message_is_push_new_commit_to_dev_should_stash_and_validate_repo() let forge_alias = given::a_forge_alias(); let repo_alias = given::a_repo_alias(); let headers = BTreeMap::new(); - let body = Body::new("".to_string()); + let body = Body::new(String::new()); let forge_notification = ForgeNotification::new(forge_alias, repo_alias, headers, body); let repository_factory = MockRepositoryFactory::new(); let push_commit = given::a_commit(); diff --git a/crates/cli/src/repo/tests/mod.rs b/crates/cli/src/repo/tests/mod.rs index cf789197..5781b77f 100644 --- a/crates/cli/src/repo/tests/mod.rs +++ b/crates/cli/src/repo/tests/mod.rs @@ -5,7 +5,7 @@ use crate::{ git, repo::{ messages::{CloneRepo, MessageToken}, - RepoActor, RepoActorLog, + ActorLog, RepoActor, }, }; @@ -45,7 +45,7 @@ mod handlers; mod load; mod when; -impl RepoActorLog { +impl ActorLog { pub fn no_message_contains(&self, needle: impl AsRef + std::fmt::Display) -> TestResult { if self.find_in_messages(needle.as_ref())? { error!(?self, ""); diff --git a/crates/cli/src/repo/tests/when.rs b/crates/cli/src/repo/tests/when.rs index 8bf3a6ca..e00341a3 100644 --- a/crates/cli/src/repo/tests/when.rs +++ b/crates/cli/src/repo/tests/when.rs @@ -5,7 +5,7 @@ pub fn start_actor( repository_factory: MockRepositoryFactory, repo_details: RepoDetails, forge: Box, -) -> (actix::Addr, RepoActorLog) { +) -> (actix::Addr, ActorLog) { let (actor, log) = given::a_repo_actor( repo_details, Box::new(repository_factory), @@ -19,7 +19,7 @@ pub fn start_actor_with_open_repository( open_repository: Box, repo_details: RepoDetails, forge: Box, -) -> (actix::Addr, RepoActorLog) { +) -> (actix::Addr, ActorLog) { let (actor, log) = given::a_repo_actor(repo_details, mock(), forge, given::a_network().into()); let actor = actor.with_open_repository(Some(open_repository)); (actor.start(), log) diff --git a/crates/cli/src/server/actor/handlers/file_updated.rs b/crates/cli/src/server/actor/handlers/file_updated.rs index d5c2af8a..499bac8b 100644 --- a/crates/cli/src/server/actor/handlers/file_updated.rs +++ b/crates/cli/src/server/actor/handlers/file_updated.rs @@ -14,7 +14,7 @@ impl Handler for ServerActor { fn handle(&mut self, _msg: FileUpdated, ctx: &mut Self::Context) -> Self::Result { match ServerConfig::load(&self.fs) { Ok(server_config) => self.do_send(ReceiveServerConfig::new(server_config), ctx), - Err(err) => self.abort(ctx, format!("Failed to load config file. Error: {}", err)), + Err(err) => self.abort(ctx, format!("Failed to load config file. Error: {err}")), }; } } 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 53ce8465..8df18241 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,17 +1,19 @@ // use actix::prelude::*; +use git_next_core::{ForgeAlias, RepoAlias}; use tracing::info; use crate::{ alerts::messages::UpdateShout, + repo::{messages::CloneRepo, RepoActor}, server::actor::{ messages::{ReceiveValidServerConfig, ValidServerConfig}, ServerActor, }, webhook::{ messages::ShutdownWebhook, - router::{AddWebhookRecipient, WebhookRouter}, + router::{AddWebhookRecipient, WebhookRouterActor}, WebhookActor, }, }; @@ -32,9 +34,9 @@ impl Handler for ServerActor { self.generation.inc(); // Webhook Server info!("Starting Webhook Server..."); - let webhook_router = WebhookRouter::default().start(); + let webhook_router = WebhookRouterActor::default().start(); let listen_url = server_config.listen().url(); - let alerts = self.alerts.clone(); + let notify_user_recipient = self.alerts.clone().recipient(); // Forge Actors for (forge_alias, forge_config) in server_config.forges() { let repo_actors = self @@ -43,10 +45,10 @@ impl Handler for ServerActor { forge_alias.clone(), &server_storage, listen_url, - alerts.clone().recipient(), + ¬ify_user_recipient, ) .into_iter() - .map(|a| self.start_actor(a)) + .map(start_repo_actor) .collect::>(); repo_actors .iter() @@ -58,10 +60,10 @@ impl Handler for ServerActor { ) }) .for_each(|msg| webhook_router.do_send(msg)); - repo_actors.into_iter().for_each(|(repo_alias, addr)| { + for (repo_alias, addr) in repo_actors { self.repo_actors .insert((forge_alias.clone(), repo_alias), addr); - }); + } } let webhook_actor_addr = WebhookActor::new(socket_address, webhook_router.recipient()).start(); @@ -71,3 +73,13 @@ impl Handler for ServerActor { self.alerts.do_send(UpdateShout::new(shout)); } } + +fn start_repo_actor(actor: (ForgeAlias, RepoAlias, RepoActor)) -> (RepoAlias, Addr) { + let (forge_name, repo_alias, actor) = actor; + let span = tracing::info_span!("start_repo_actor", forge = %forge_name, repo = %repo_alias); + let _guard = span.enter(); + let addr = actor.start(); + addr.do_send(CloneRepo); + tracing::info!("Started"); + (repo_alias, addr) +} diff --git a/crates/cli/src/server/actor/mod.rs b/crates/cli/src/server/actor/mod.rs index 26e71792..54722b71 100644 --- a/crates/cli/src/server/actor/mod.rs +++ b/crates/cli/src/server/actor/mod.rs @@ -10,10 +10,7 @@ mod handlers; pub mod messages; use crate::{ - alerts::messages::NotifyUser, - alerts::AlertsActor, - forge::Forge, - repo::{messages::CloneRepo, RepoActor}, + alerts::messages::NotifyUser, alerts::AlertsActor, forge::Forge, repo::RepoActor, webhook::WebhookActor, }; @@ -47,6 +44,7 @@ pub enum Error { } type Result = core::result::Result; +#[allow(clippy::module_name_repetitions)] #[derive(derive_with::With)] #[with(message_log)] pub struct ServerActor { @@ -116,7 +114,7 @@ impl ServerActor { forge_name: ForgeAlias, server_storage: &ServerStorage, listen_url: &ListenUrl, - notify_user_recipient: Recipient, + notify_user_recipient: &Recipient, ) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> { let span = tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config); @@ -198,19 +196,6 @@ impl ServerActor { } } - fn start_actor( - &self, - actor: (ForgeAlias, RepoAlias, RepoActor), - ) -> (RepoAlias, Addr) { - let (forge_name, repo_alias, actor) = actor; - let span = tracing::info_span!("start_actor", forge = %forge_name, repo = %repo_alias); - let _guard = span.enter(); - let addr = actor.start(); - addr.do_send(CloneRepo); - tracing::info!("Started"); - (repo_alias, addr) - } - fn server_storage(&self, server_config: &ReceiveServerConfig) -> Option { let server_storage = server_config.storage().clone(); let dir = server_storage.path(); @@ -232,25 +217,26 @@ impl ServerActor { } /// Attempts to gracefully shutdown the server before stopping the system. - fn abort(&self, ctx: &mut ::Context, message: impl Into) { + fn abort(&self, ctx: &::Context, message: impl Into) { tracing::error!("Aborting: {}", message.into()); self.do_send(crate::server::actor::messages::Shutdown, ctx); System::current().stop_with_code(1); } - fn do_send(&self, msg: M, _ctx: &mut ::Context) + fn do_send(&self, msg: M, ctx: &::Context) where M: actix::Message + Send + 'static + std::fmt::Debug, Self: actix::Handler, ::Result: Send, { if let Some(message_log) = &self.message_log { - let log_message = format!("send: {:?}", msg); + let log_message = format!("send: {msg:?}"); if let Ok(mut log) = message_log.write() { log.push(log_message); } } - #[cfg(not(test))] - _ctx.address().do_send(msg); + if cfg!(not(test)) { + ctx.address().do_send(msg); + } } } diff --git a/crates/cli/src/server/mod.rs b/crates/cli/src/server/mod.rs index 537b5553..1d517ead 100644 --- a/crates/cli/src/server/mod.rs +++ b/crates/cli/src/server/mod.rs @@ -21,7 +21,7 @@ use std::{path::PathBuf, time::Duration}; const A_DAY: Duration = Duration::from_secs(24 * 60 * 60); -pub fn init(fs: FileSystem) -> Result<()> { +pub fn init(fs: &FileSystem) -> Result<()> { let file_name = "git-next-server.toml"; let pathbuf = PathBuf::from(file_name); if fs diff --git a/crates/cli/src/server/tests.rs b/crates/cli/src/server/tests.rs index 215cc92d..2060ade2 100644 --- a/crates/cli/src/server/tests.rs +++ b/crates/cli/src/server/tests.rs @@ -37,7 +37,7 @@ fn gitdir_should_display_as_pathbuf() { //given let gitdir = GitDir::new("foo/dir".into(), StoragePathType::External); //when - let result = format!("{}", gitdir); + let result = format!("{gitdir}"); //then assert_eq!(result, "foo/dir"); } @@ -59,7 +59,7 @@ fn repo_details_find_default_push_remote_finds_correct_remote() -> Result<()> { repo_details.forge = repo_details .forge .with_user(User::new("git".to_string())) - .with_token(ApiToken::new(Secret::new("".to_string()))) + .with_token(ApiToken::new(Secret::new(String::new()))) .with_hostname(Hostname::new("git.kemitix.net")); repo_details.repo_path = RepoPath::new("kemitix/git-next".to_string()); let open_repository = git::repository::factory::real().open(&repo_details)?; @@ -92,7 +92,7 @@ fn gitdir_validate_should_pass_a_valid_git_repo() -> Result<()> { repo_details.forge = repo_details .forge .with_user(User::new("git".to_string())) - .with_token(ApiToken::new(Secret::new("".to_string()))) + .with_token(ApiToken::new(Secret::new(String::new()))) .with_hostname(Hostname::new("git.kemitix.net")); tracing::debug!("opening..."); let_assert!( @@ -124,7 +124,7 @@ fn gitdir_validate_should_fail_a_git_repo_with_wrong_remote() -> Result<()> { repo_details.forge = repo_details .forge .with_user(User::new("git".to_string())) - .with_token(ApiToken::new(Secret::new("".to_string()))) + .with_token(ApiToken::new(Secret::new(String::new()))) .with_hostname(Hostname::new("git.kemitix.net")); let repository = git::repository::factory::real().open(&repo_details)?; let mut repo_details = repo_details.clone(); diff --git a/crates/cli/src/tests.rs b/crates/cli/src/tests.rs index 88c4f8b4..627c3784 100644 --- a/crates/cli/src/tests.rs +++ b/crates/cli/src/tests.rs @@ -8,7 +8,7 @@ mod init { let file = fs.base().join(".git-next.toml"); fs.file_write(&file, "contents")?; - crate::init::run(fs.clone())?; + crate::init::run(&fs)?; assert_eq!( fs.file_read_to_string(&file)?, @@ -23,7 +23,7 @@ mod init { fn should_create_default_file_if_not_exists() -> TestResult { let fs = kxio::fs::temp()?; - crate::init::run(fs.clone())?; + crate::init::run(&fs)?; let file = fs.base().join(".git-next.toml"); diff --git a/crates/cli/src/webhook/mod.rs b/crates/cli/src/webhook/mod.rs index 79ac39a6..64a580c6 100644 --- a/crates/cli/src/webhook/mod.rs +++ b/crates/cli/src/webhook/mod.rs @@ -12,6 +12,7 @@ use std::net::SocketAddr; use tracing::Instrument; +#[allow(clippy::module_name_repetitions)] #[derive(Debug)] pub struct WebhookActor { socket_addr: SocketAddr, diff --git a/crates/cli/src/webhook/router.rs b/crates/cli/src/webhook/router.rs index cf682518..2d180dea 100644 --- a/crates/cli/src/webhook/router.rs +++ b/crates/cli/src/webhook/router.rs @@ -10,29 +10,29 @@ use crate::repo::messages::WebhookNotification; use git_next_core::{ForgeAlias, RepoAlias}; -pub struct WebhookRouter { +pub struct WebhookRouterActor { span: tracing::Span, recipients: BTreeMap>>, } -impl Default for WebhookRouter { +impl Default for WebhookRouterActor { fn default() -> Self { Self::new() } } -impl WebhookRouter { +impl WebhookRouterActor { pub fn new() -> Self { let span = tracing::info_span!("WebhookRouter"); Self { span, - recipients: Default::default(), + recipients: BTreeMap::default(), } } } -impl Actor for WebhookRouter { +impl Actor for WebhookRouterActor { type Context = Context; } -impl Handler for WebhookRouter { +impl Handler for WebhookRouterActor { type Result = (); fn handle(&mut self, msg: WebhookNotification, _ctx: &mut Self::Context) -> Self::Result { @@ -59,7 +59,7 @@ pub struct AddWebhookRecipient { pub repo_alias: RepoAlias, pub recipient: Recipient, } -impl Handler for WebhookRouter { +impl Handler for WebhookRouterActor { type Result = (); fn handle(&mut self, msg: AddWebhookRecipient, _ctx: &mut Self::Context) -> Self::Result { diff --git a/crates/cli/src/webhook/server.rs b/crates/cli/src/webhook/server.rs index 78d6b480..6df3809e 100644 --- a/crates/cli/src/webhook/server.rs +++ b/crates/cli/src/webhook/server.rs @@ -50,7 +50,7 @@ pub async fn start( )); recipient .try_send(message) - .map(|_| { + .map(|()| { info!("Message sent ok"); warp::reply::with_status("OK", warp::http::StatusCode::OK) })