From d70e1fd8e5acf53b3016deb844ab28d6443e5949 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 5 Aug 2024 07:39:38 +0100 Subject: [PATCH] WIP: cleanup pedantic clippy --- Cargo.toml | 10 +++--- crates/cli/Cargo.toml | 2 +- crates/cli/src/alerts/email.rs | 8 ++--- crates/cli/src/alerts/history.rs | 4 +-- crates/cli/src/alerts/mod.rs | 1 + crates/cli/src/alerts/webhook.rs | 3 +- crates/cli/src/init.rs | 2 +- crates/cli/src/main.rs | 2 +- crates/cli/src/repo/branch.rs | 2 +- crates/cli/src/repo/handlers/advance_main.rs | 6 ++-- crates/cli/src/repo/handlers/advance_next.rs | 2 +- .../cli/src/repo/handlers/check_ci_status.rs | 2 +- crates/cli/src/repo/handlers/clone_repo.rs | 6 ++-- .../repo/handlers/load_config_from_repo.rs | 4 ++- .../src/repo/handlers/receive_ci_status.rs | 6 ++-- .../src/repo/handlers/receive_repo_config.rs | 2 +- .../cli/src/repo/handlers/register_webhook.rs | 2 +- .../src/repo/handlers/unregister_webhook.rs | 2 +- crates/cli/src/repo/handlers/validate_repo.rs | 11 +++---- .../src/repo/handlers/webhook_notification.rs | 16 +++++----- .../src/repo/handlers/webhook_registered.rs | 2 +- crates/cli/src/repo/messages.rs | 2 +- crates/cli/src/repo/mod.rs | 31 ++++++++++--------- crates/cli/src/repo/notifications.rs | 3 +- crates/cli/src/repo/tests/given.rs | 4 +-- crates/cli/src/repo/tests/mod.rs | 4 +-- crates/cli/src/repo/tests/when.rs | 4 +-- .../src/server/actor/handlers/file_updated.rs | 2 +- .../handlers/receive_valid_server_config.rs | 8 ++--- crates/cli/src/server/actor/mod.rs | 3 +- crates/cli/src/tests.rs | 4 +-- 31 files changed, 83 insertions(+), 77 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa65f52..98d5cae 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 c74f1a2..e068f14 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 2dfadbf..2f12cbd 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 99fe61f..de15a95 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 d298053..18ae6b3 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 3d7cdec..75647e7 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 fde940b..a13a10a 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 c5ceb23..cf63ffc 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -44,7 +44,7 @@ fn main() -> Result<()> { match commands.command { Command::Init => { - init::run(fs)?; + init::run(&fs)?; } Command::Server(server) => match server { Server::Init => { diff --git a/crates/cli/src/repo/branch.rs b/crates/cli/src/repo/branch.rs index 55b8ecd..3bd4cde 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 5831d45..8e25008 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 cdcd2f9..747db94 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 853eba5..122f019 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 366f295..a851c69 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 5c00ecc..dd3567b 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 2517662..75c40bd 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 8d2c715..12934d8 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 563024c..4981918 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 4163f9a..8c748ac 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 0cb18a6..92a7ba7 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 f428453..930d61e 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 6eeb769..a3a5aae 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 63cb067..0a2ccf3 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 c9cd263..7a0c3bc 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 1ec3bc2..c54e612 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/given.rs b/crates/cli/src/repo/tests/given.rs index 22f7985..a5b3fef 100644 --- a/crates/cli/src/repo/tests/given.rs +++ b/crates/cli/src/repo/tests/given.rs @@ -179,10 +179,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/mod.rs b/crates/cli/src/repo/tests/mod.rs index cf78919..5781b77 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 8bf3a6c..e00341a 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 d5c2af8..499bac8 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 53ce846..c6de796 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 @@ -34,7 +34,7 @@ impl Handler for ServerActor { info!("Starting Webhook Server..."); let webhook_router = WebhookRouter::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,7 +43,7 @@ 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)) @@ -58,10 +58,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(); diff --git a/crates/cli/src/server/actor/mod.rs b/crates/cli/src/server/actor/mod.rs index 26e7179..da4ea5b 100644 --- a/crates/cli/src/server/actor/mod.rs +++ b/crates/cli/src/server/actor/mod.rs @@ -47,6 +47,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 +117,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); diff --git a/crates/cli/src/tests.rs b/crates/cli/src/tests.rs index 88c4f8b..627c378 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");