WIP: cleanup pedantic clippy
All checks were successful
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-08-05 07:39:38 +01:00
parent 281c07c849
commit d70e1fd8e5
31 changed files with 83 additions and 77 deletions

View file

@ -15,11 +15,11 @@ documentation = "https://git.kemitix.net/kemitix/git-next/src/branch/main/README
keywords = ["git", "cli", "server", "tool"] keywords = ["git", "cli", "server", "tool"]
categories = ["development-tools"] categories = ["development-tools"]
[workspace.lints.clippy] # [workspace.lints.clippy]
nursery = { level = "warn", priority = -1 } # pedantic = { level = "warn", priority = -1 }
# pedantic = "warn" # nursery = { level = "warn", priority = -1 }
unwrap_used = "warn" # unwrap_used = "warn"
expect_used = "warn" # expect_used = "warn"
[workspace.dependencies] [workspace.dependencies]
git-next-core = { path = "crates/core", version = "0.13" } git-next-core = { path = "crates/core", version = "0.13" }

View file

@ -76,7 +76,7 @@ mockall = { workspace = true }
[lints.clippy] [lints.clippy]
nursery = { level = "warn", priority = -1 } nursery = { level = "warn", priority = -1 }
# pedantic = "warn" pedantic = { level = "warn", priority = -1 }
unwrap_used = "warn" unwrap_used = "warn"
expect_used = "warn" expect_used = "warn"

View file

@ -23,11 +23,11 @@ pub(super) fn send_email(user_notification: &UserNotification, email_config: &Em
}; };
match email_config.smtp() { match email_config.smtp() {
Some(smtp) => send_email_smtp(email_message, 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; use sendmail::email;
match email::send( match email::send(
&email_message.from, &email_message.from,
@ -35,7 +35,7 @@ fn send_email_sendmail(email_message: EmailMessage) {
&email_message.subject, &email_message.subject,
&email_message.body, &email_message.body,
) { ) {
Ok(_) => tracing::info!("Email sent successfully!"), Ok(()) => tracing::info!("Email sent successfully!"),
Err(e) => tracing::warn!("Could not send email: {:?}", e), 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| { .map(|response| {
response response
.message() .message()
.map(|s| s.to_string()) .map(ToString::to_string)
.collect::<Vec<_>>() .collect::<Vec<_>>()
}) })
.map(|response| { .map(|response| {

View file

@ -16,7 +16,7 @@ pub struct History {
/// Maps a user notification to when it was last seen. /// 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. /// Each time we see a given user notification, the last seen time will be updated.
items: HashMap<UserNotification, Instant>, items: HashMap<UserNotification, Instant>,
@ -44,7 +44,7 @@ impl History {
pub fn prune(&mut self, now: &Instant) { pub fn prune(&mut self, now: &Instant) {
if let Some(threshold) = now.checked_sub(self.max_age_seconds) { 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);
}; };
} }
} }

View file

@ -17,6 +17,7 @@ mod webhook;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Constructor)] #[derive(Debug, Constructor)]
pub struct AlertsActor { pub struct AlertsActor {
shout: Option<Shout>, // config for sending alerts to users shout: Option<Shout>, // config for sending alerts to users

View file

@ -1,5 +1,6 @@
// //
use git_next_core::{git::UserNotification, server::OutboundWebhook}; use git_next_core::{git::UserNotification, server::OutboundWebhook};
use kxio::network::{NetRequest, NetUrl, RequestBody, ResponseType};
use secrecy::ExposeSecret as _; use secrecy::ExposeSecret as _;
use standardwebhooks::Webhook; use standardwebhooks::Webhook;
@ -35,7 +36,7 @@ async fn do_send_webhook(
.expect("signature"); .expect("signature");
tracing::info!(?signature, ""); tracing::info!(?signature, "");
let url = webhook_config.url(); let url = webhook_config.url();
use kxio::network::{NetRequest, NetUrl, RequestBody, ResponseType};
let net_url = NetUrl::new(url.to_string()); let net_url = NetUrl::new(url.to_string());
let request = NetRequest::post(net_url) let request = NetRequest::post(net_url)
.body(RequestBody::Json(payload)) .body(RequestBody::Json(payload))

View file

@ -2,7 +2,7 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use kxio::fs::FileSystem; use kxio::fs::FileSystem;
pub fn run(fs: FileSystem) -> Result<()> { pub fn run(fs: &FileSystem) -> Result<()> {
let pathbuf = fs.base().join(".git-next.toml"); let pathbuf = fs.base().join(".git-next.toml");
if fs if fs
.path_exists(&pathbuf) .path_exists(&pathbuf)

View file

@ -44,7 +44,7 @@ fn main() -> Result<()> {
match commands.command { match commands.command {
Command::Init => { Command::Init => {
init::run(fs)?; init::run(&fs)?;
} }
Command::Server(server) => match server { Command::Server(server) => match server {
Server::Init => { Server::Init => {

View file

@ -66,7 +66,7 @@ pub fn find_next_commit_on_dev(
) -> (Option<Commit>, Force) { ) -> (Option<Commit>, Force) {
let mut next_commit: Option<&Commit> = None; let mut next_commit: Option<&Commit> = None;
let mut force = Force::No; let mut force = Force::No;
for commit in dev_commit_history.iter() { for commit in dev_commit_history {
if commit == next { if commit == next {
break; break;
}; };

View file

@ -36,12 +36,12 @@ impl Handler<AdvanceMain> for RepoActor {
Err(err) => { Err(err) => {
warn!("advance main: {err}"); warn!("advance main: {err}");
} }
Ok(_) => match repo_config.source() { Ok(()) => match repo_config.source() {
RepoConfigSource::Repo => { RepoConfigSource::Repo => {
do_send(addr, LoadConfigFromRepo, self.log.as_ref()); do_send(&addr, LoadConfigFromRepo, self.log.as_ref());
} }
RepoConfigSource::Server => { RepoConfigSource::Server => {
do_send(addr, ValidateRepo::new(message_token), self.log.as_ref()); do_send(&addr, ValidateRepo::new(message_token), self.log.as_ref());
} }
}, },
} }

View file

@ -41,7 +41,7 @@ impl Handler<AdvanceNext> for RepoActor {
Ok(message_token) => { Ok(message_token) => {
// pause to allow any CI checks to be started // pause to allow any CI checks to be started
std::thread::sleep(self.sleep_duration); 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}"), Err(err) => warn!("advance next: {err}"),
} }

View file

@ -23,7 +23,7 @@ impl Handler<CheckCIStatus> for RepoActor {
async move { async move {
let status = forge.commit_status(&next).await; let status = forge.commit_status(&next).await;
debug!("got status: {status:?}"); 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() .in_current_span()
.into_actor(self) .into_actor(self)

View file

@ -22,14 +22,14 @@ impl Handler<CloneRepo> for RepoActor {
debug!("open okay"); debug!("open okay");
self.open_repository.replace(repository); self.open_repository.replace(repository);
if self.repo_details.repo_config.is_none() { 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 { } else {
do_send(ctx.address(), RegisterWebhook::new(), self.log.as_ref()); do_send(&ctx.address(), RegisterWebhook::new(), self.log.as_ref());
} }
} }
Err(err) => { Err(err) => {
logger(self.log.as_ref(), "open failed"); logger(self.log.as_ref(), "open failed");
warn!("Could not open repo: {err:?}") warn!("Could not open repo: {err:?}");
} }
} }
debug!("Handler: CloneRepo: finish"); debug!("Handler: CloneRepo: finish");

View file

@ -28,7 +28,9 @@ impl Handler<LoadConfigFromRepo> for RepoActor {
let log = self.log.clone(); let log = self.log.clone();
async move { async move {
match load::config_from_repository(repo_details, &*open_repository).await { 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( Err(err) => notify_user(
notify_user_recipient.as_ref(), notify_user_recipient.as_ref(),
UserNotification::RepoConfigLoadFailure { UserNotification::RepoConfigLoadFailure {

View file

@ -26,11 +26,11 @@ impl Handler<ReceiveCIStatus> for RepoActor {
debug!(?status, ""); debug!(?status, "");
match status { match status {
Status::Pass => { Status::Pass => {
do_send(addr, AdvanceMain::new(next), self.log.as_ref()); do_send(&addr, AdvanceMain::new(next), self.log.as_ref());
} }
Status::Pending => { Status::Pending => {
std::thread::sleep(sleep_duration); 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 => { Status::Fail => {
tracing::warn!("Checks have failed"); tracing::warn!("Checks have failed");
@ -44,7 +44,7 @@ impl Handler<ReceiveCIStatus> for RepoActor {
log.as_ref(), log.as_ref(),
); );
delay_send( delay_send(
addr, &addr,
sleep_duration, sleep_duration,
ValidateRepo::new(message_token), ValidateRepo::new(message_token),
self.log.as_ref(), self.log.as_ref(),

View file

@ -15,6 +15,6 @@ impl Handler<ReceiveRepoConfig> for RepoActor {
let repo_config = msg.unwrap(); let repo_config = msg.unwrap();
self.repo_details.repo_config.replace(repo_config); 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());
} }
} }

View file

@ -31,7 +31,7 @@ impl Handler<RegisterWebhook> for RepoActor {
Ok(registered_webhook) => { Ok(registered_webhook) => {
debug!(?registered_webhook, ""); debug!(?registered_webhook, "");
do_send( do_send(
addr, &addr,
WebhookRegistered::from(registered_webhook), WebhookRegistered::from(registered_webhook),
log.as_ref(), log.as_ref(),
); );

View file

@ -14,7 +14,7 @@ impl Handler<UnRegisterWebhook> for RepoActor {
debug!("unregistering webhook"); debug!("unregistering webhook");
async move { async move {
match forge.unregister_webhook(&webhook_id).await { match forge.unregister_webhook(&webhook_id).await {
Ok(_) => debug!("unregistered webhook"), Ok(()) => debug!("unregistered webhook"),
Err(err) => warn!(?err, "unregistering webhook"), Err(err) => warn!(?err, "unregistering webhook"),
} }
} }

View file

@ -1,7 +1,6 @@
// //
use actix::prelude::*; use actix::prelude::*;
use derive_more::Deref as _;
use tracing::{debug, instrument, Instrument as _}; use tracing::{debug, instrument, Instrument as _};
use crate::repo::{ use crate::repo::{
@ -15,7 +14,7 @@ use git_next_core::git::validation::positions::{validate_positions, Error, Posit
impl Handler<ValidateRepo> for RepoActor { impl Handler<ValidateRepo> for RepoActor {
type Result = (); 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 { fn handle(&mut self, msg: ValidateRepo, ctx: &mut Self::Context) -> Self::Result {
logger(self.log.as_ref(), "start: ValidateRepo"); logger(self.log.as_ref(), "start: ValidateRepo");
@ -64,17 +63,17 @@ impl Handler<ValidateRepo> for RepoActor {
}) => { }) => {
debug!(%main, %next, %dev, "positions"); debug!(%main, %next, %dev, "positions");
if next_is_valid && next != main { 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 { } else if next != dev {
do_send( do_send(
ctx.address(), &ctx.address(),
AdvanceNext::new(AdvanceNextPayload { AdvanceNext::new(AdvanceNextPayload {
next, next,
main, main,
dev_commit_history, dev_commit_history,
}), }),
self.log.as_ref(), self.log.as_ref(),
) );
} else { } else {
// do nothing // do nothing
} }
@ -90,7 +89,7 @@ impl Handler<ValidateRepo> for RepoActor {
logger(log.as_ref(), "before sleep"); logger(log.as_ref(), "before sleep");
actix_rt::time::sleep(sleep_duration).await; actix_rt::time::sleep(sleep_duration).await;
logger(log.as_ref(), "after sleep"); 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() .in_current_span()
.into_actor(self) .into_actor(self)

View file

@ -6,7 +6,7 @@ use tracing::{info, instrument, warn};
use crate::repo::{ use crate::repo::{
do_send, logger, do_send, logger,
messages::{ValidateRepo, WebhookNotification}, messages::{ValidateRepo, WebhookNotification},
RepoActor, RepoActorLog, ActorLog, RepoActor,
}; };
use git_next_core::{ use git_next_core::{
@ -54,7 +54,7 @@ impl Handler<WebhookNotification> for RepoActor {
Some(Branch::Main) => { Some(Branch::Main) => {
if handle_push( if handle_push(
push, push,
config.branches().main(), &config.branches().main(),
&mut self.last_main_commit, &mut self.last_main_commit,
self.log.as_ref(), self.log.as_ref(),
) )
@ -66,7 +66,7 @@ impl Handler<WebhookNotification> for RepoActor {
Some(Branch::Next) => { Some(Branch::Next) => {
if handle_push( if handle_push(
push, push,
config.branches().next(), &config.branches().next(),
&mut self.last_next_commit, &mut self.last_next_commit,
self.log.as_ref(), self.log.as_ref(),
) )
@ -78,7 +78,7 @@ impl Handler<WebhookNotification> for RepoActor {
Some(Branch::Dev) => { Some(Branch::Dev) => {
if handle_push( if handle_push(
push, push,
config.branches().dev(), &config.branches().dev(),
&mut self.last_dev_commit, &mut self.last_dev_commit,
self.log.as_ref(), self.log.as_ref(),
) )
@ -95,7 +95,7 @@ impl Handler<WebhookNotification> for RepoActor {
"New commit" "New commit"
); );
do_send( do_send(
ctx.address(), &ctx.address(),
ValidateRepo::new(message_token), ValidateRepo::new(message_token),
self.log.as_ref(), self.log.as_ref(),
); );
@ -106,7 +106,7 @@ fn validate_notification(
msg: &WebhookNotification, msg: &WebhookNotification,
webhook_auth: Option<&WebhookAuth>, webhook_auth: Option<&WebhookAuth>,
forge: &dyn ForgeLike, forge: &dyn ForgeLike,
log: Option<&RepoActorLog>, log: Option<&ActorLog>,
) -> Result<(), ()> { ) -> Result<(), ()> {
let Some(expected_authorization) = webhook_auth else { let Some(expected_authorization) = webhook_auth else {
logger(log, "server has no auth token"); logger(log, "server has no auth token");
@ -131,9 +131,9 @@ fn validate_notification(
fn handle_push( fn handle_push(
push: Push, push: Push,
branch: BranchName, branch: &BranchName,
last_commit: &mut Option<Commit>, last_commit: &mut Option<Commit>,
log: Option<&RepoActorLog>, log: Option<&ActorLog>,
) -> Result<(), ()> { ) -> Result<(), ()> {
logger(log, "message is for dev branch"); logger(log, "message is for dev branch");
let commit = Commit::from(push); let commit = Commit::from(push);

View file

@ -15,7 +15,7 @@ impl Handler<WebhookRegistered> for RepoActor {
self.webhook_id.replace(msg.webhook_id().clone()); self.webhook_id.replace(msg.webhook_id().clone());
self.webhook_auth.replace(msg.webhook_auth().clone()); self.webhook_auth.replace(msg.webhook_auth().clone());
do_send( do_send(
ctx.address(), &ctx.address(),
ValidateRepo::new(self.message_token), ValidateRepo::new(self.message_token),
self.log.as_ref(), self.log.as_ref(),
); );

View file

@ -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 received, marking that message the latest, and causing any previous messages still being processed to be dropped when
they next send a [ValidateRepo] message."#); they next send a [ValidateRepo] message."#);
impl MessageToken { impl MessageToken {
pub const fn next(&self) -> Self { pub const fn next(self) -> Self {
Self(self.0 + 1) Self(self.0 + 1)
} }
} }

View file

@ -27,8 +27,8 @@ mod notifications;
pub mod tests; pub mod tests;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct RepoActorLog(std::sync::Arc<std::sync::RwLock<Vec<String>>>); pub struct ActorLog(std::sync::Arc<std::sync::RwLock<Vec<String>>>);
impl Deref for RepoActorLog { impl Deref for ActorLog {
type Target = std::sync::Arc<std::sync::RwLock<Vec<String>>>; type Target = std::sync::Arc<std::sync::RwLock<Vec<String>>>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -38,7 +38,8 @@ impl Deref for RepoActorLog {
/// An actor that represents a Git Repository. /// 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)] #[derive(Debug, derive_more::Display, derive_with::With)]
#[display("{}:{}:{}", generation, repo_details.forge.forge_alias(), repo_details.repo_alias)] #[display("{}:{}:{}", generation, repo_details.forge.forge_alias(), repo_details.repo_alias)]
pub struct RepoActor { pub struct RepoActor {
@ -56,7 +57,7 @@ pub struct RepoActor {
open_repository: Option<Box<dyn OpenRepositoryLike>>, open_repository: Option<Box<dyn OpenRepositoryLike>>,
net: Network, net: Network,
forge: Box<dyn git::ForgeLike>, forge: Box<dyn git::ForgeLike>,
log: Option<RepoActorLog>, log: Option<ActorLog>,
notify_user_recipient: Option<Recipient<NotifyUser>>, notify_user_recipient: Option<Recipient<NotifyUser>>,
} }
impl RepoActor { impl RepoActor {
@ -118,33 +119,35 @@ impl Actor for RepoActor {
} }
} }
pub fn delay_send<M>(addr: Addr<RepoActor>, delay: Duration, msg: M, log: Option<&RepoActorLog>) pub fn delay_send<M>(addr: &Addr<RepoActor>, delay: Duration, msg: M, log: Option<&ActorLog>)
where where
M: actix::Message + Send + 'static + std::fmt::Debug, M: actix::Message + Send + 'static + std::fmt::Debug,
RepoActor: actix::Handler<M>, RepoActor: actix::Handler<M>,
<M as actix::Message>::Result: Send, <M as actix::Message>::Result: Send,
{ {
let log_message = format!("send-after-delay: {:?}", msg); let log_message = format!("send-after-delay: {msg:?}");
tracing::debug!(log_message); tracing::debug!(log_message);
logger(log, log_message); logger(log, log_message);
std::thread::sleep(delay); std::thread::sleep(delay);
do_send(addr, msg, log) do_send(addr, msg, log);
} }
pub fn do_send<M>(_addr: Addr<RepoActor>, msg: M, log: Option<&RepoActorLog>) pub fn do_send<M>(addr: &Addr<RepoActor>, msg: M, log: Option<&ActorLog>)
where where
M: actix::Message + Send + 'static + std::fmt::Debug, M: actix::Message + Send + 'static + std::fmt::Debug,
RepoActor: actix::Handler<M>, RepoActor: actix::Handler<M>,
<M as actix::Message>::Result: Send, <M as actix::Message>::Result: Send,
{ {
let log_message = format!("send: {:?}", msg); let log_message = format!("send: {msg:?}");
tracing::debug!(log_message); tracing::debug!(log_message);
logger(log, log_message); logger(log, log_message);
#[cfg(not(test))] if cfg!(not(test)) {
_addr.do_send(msg) // #[cfg(not(test))]
addr.do_send(msg);
}
} }
pub fn logger(log: Option<&RepoActorLog>, message: impl Into<String>) { pub fn logger(log: Option<&ActorLog>, message: impl Into<String>) {
if let Some(log) = log { if let Some(log) = log {
let message: String = message.into(); let message: String = message.into();
tracing::debug!(message); tracing::debug!(message);
@ -154,10 +157,10 @@ pub fn logger(log: Option<&RepoActorLog>, message: impl Into<String>) {
pub fn notify_user( pub fn notify_user(
recipient: Option<&Recipient<NotifyUser>>, recipient: Option<&Recipient<NotifyUser>>,
user_notification: UserNotification, user_notification: UserNotification,
log: Option<&RepoActorLog>, log: Option<&ActorLog>,
) { ) {
let msg = NotifyUser::from(user_notification); let msg = NotifyUser::from(user_notification);
let log_message = format!("send: {:?}", msg); let log_message = format!("send: {msg:?}");
tracing::debug!(log_message); tracing::debug!(log_message);
logger(log, log_message); logger(log, log_message);
if let Some(recipient) = &recipient { if let Some(recipient) = &recipient {

View file

@ -1,5 +1,4 @@
// //
use derive_more::Deref as _;
use crate::repo::messages::NotifyUser; use crate::repo::messages::NotifyUser;
@ -10,7 +9,7 @@ use serde_json::json;
impl NotifyUser { impl NotifyUser {
pub fn as_json(&self, timestamp: time::OffsetDateTime) -> serde_json::Value { pub fn as_json(&self, timestamp: time::OffsetDateTime) -> serde_json::Value {
let timestamp = timestamp.unix_timestamp().to_string(); let timestamp = timestamp.unix_timestamp().to_string();
match self.deref() { match &**self {
UserNotification::CICheckFailed { UserNotification::CICheckFailed {
forge_alias, forge_alias,
repo_alias, repo_alias,

View file

@ -179,10 +179,10 @@ pub fn a_repo_actor(
repository_factory: Box<dyn RepositoryFactory>, repository_factory: Box<dyn RepositoryFactory>,
forge: Box<dyn ForgeLike>, forge: Box<dyn ForgeLike>,
net: kxio::network::Network, net: kxio::network::Network,
) -> (RepoActor, RepoActorLog) { ) -> (RepoActor, ActorLog) {
let listen_url = given::a_listen_url(); let listen_url = given::a_listen_url();
let generation = Generation::default(); let generation = Generation::default();
let log = RepoActorLog::default(); let log = ActorLog::default();
let actors_log = log.clone(); let actors_log = log.clone();
( (
RepoActor::new( RepoActor::new(

View file

@ -5,7 +5,7 @@ use crate::{
git, git,
repo::{ repo::{
messages::{CloneRepo, MessageToken}, messages::{CloneRepo, MessageToken},
RepoActor, RepoActorLog, ActorLog, RepoActor,
}, },
}; };
@ -45,7 +45,7 @@ mod handlers;
mod load; mod load;
mod when; mod when;
impl RepoActorLog { impl ActorLog {
pub fn no_message_contains(&self, needle: impl AsRef<str> + std::fmt::Display) -> TestResult { pub fn no_message_contains(&self, needle: impl AsRef<str> + std::fmt::Display) -> TestResult {
if self.find_in_messages(needle.as_ref())? { if self.find_in_messages(needle.as_ref())? {
error!(?self, ""); error!(?self, "");

View file

@ -5,7 +5,7 @@ pub fn start_actor(
repository_factory: MockRepositoryFactory, repository_factory: MockRepositoryFactory,
repo_details: RepoDetails, repo_details: RepoDetails,
forge: Box<dyn ForgeLike>, forge: Box<dyn ForgeLike>,
) -> (actix::Addr<RepoActor>, RepoActorLog) { ) -> (actix::Addr<RepoActor>, ActorLog) {
let (actor, log) = given::a_repo_actor( let (actor, log) = given::a_repo_actor(
repo_details, repo_details,
Box::new(repository_factory), Box::new(repository_factory),
@ -19,7 +19,7 @@ pub fn start_actor_with_open_repository(
open_repository: Box<dyn OpenRepositoryLike>, open_repository: Box<dyn OpenRepositoryLike>,
repo_details: RepoDetails, repo_details: RepoDetails,
forge: Box<dyn ForgeLike>, forge: Box<dyn ForgeLike>,
) -> (actix::Addr<RepoActor>, RepoActorLog) { ) -> (actix::Addr<RepoActor>, ActorLog) {
let (actor, log) = given::a_repo_actor(repo_details, mock(), forge, given::a_network().into()); let (actor, log) = given::a_repo_actor(repo_details, mock(), forge, given::a_network().into());
let actor = actor.with_open_repository(Some(open_repository)); let actor = actor.with_open_repository(Some(open_repository));
(actor.start(), log) (actor.start(), log)

View file

@ -14,7 +14,7 @@ impl Handler<FileUpdated> for ServerActor {
fn handle(&mut self, _msg: FileUpdated, ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, _msg: FileUpdated, ctx: &mut Self::Context) -> Self::Result {
match ServerConfig::load(&self.fs) { match ServerConfig::load(&self.fs) {
Ok(server_config) => self.do_send(ReceiveServerConfig::new(server_config), ctx), 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}")),
}; };
} }
} }

View file

@ -34,7 +34,7 @@ impl Handler<ReceiveValidServerConfig> for ServerActor {
info!("Starting Webhook Server..."); info!("Starting Webhook Server...");
let webhook_router = WebhookRouter::default().start(); let webhook_router = WebhookRouter::default().start();
let listen_url = server_config.listen().url(); let listen_url = server_config.listen().url();
let alerts = self.alerts.clone(); let notify_user_recipient = self.alerts.clone().recipient();
// Forge Actors // Forge Actors
for (forge_alias, forge_config) in server_config.forges() { for (forge_alias, forge_config) in server_config.forges() {
let repo_actors = self let repo_actors = self
@ -43,7 +43,7 @@ impl Handler<ReceiveValidServerConfig> for ServerActor {
forge_alias.clone(), forge_alias.clone(),
&server_storage, &server_storage,
listen_url, listen_url,
alerts.clone().recipient(), &notify_user_recipient,
) )
.into_iter() .into_iter()
.map(|a| self.start_actor(a)) .map(|a| self.start_actor(a))
@ -58,10 +58,10 @@ impl Handler<ReceiveValidServerConfig> for ServerActor {
) )
}) })
.for_each(|msg| webhook_router.do_send(msg)); .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 self.repo_actors
.insert((forge_alias.clone(), repo_alias), addr); .insert((forge_alias.clone(), repo_alias), addr);
}); }
} }
let webhook_actor_addr = let webhook_actor_addr =
WebhookActor::new(socket_address, webhook_router.recipient()).start(); WebhookActor::new(socket_address, webhook_router.recipient()).start();

View file

@ -47,6 +47,7 @@ pub enum Error {
} }
type Result<T> = core::result::Result<T, Error>; type Result<T> = core::result::Result<T, Error>;
#[allow(clippy::module_name_repetitions)]
#[derive(derive_with::With)] #[derive(derive_with::With)]
#[with(message_log)] #[with(message_log)]
pub struct ServerActor { pub struct ServerActor {
@ -116,7 +117,7 @@ impl ServerActor {
forge_name: ForgeAlias, forge_name: ForgeAlias,
server_storage: &ServerStorage, server_storage: &ServerStorage,
listen_url: &ListenUrl, listen_url: &ListenUrl,
notify_user_recipient: Recipient<NotifyUser>, notify_user_recipient: &Recipient<NotifyUser>,
) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> { ) -> Vec<(ForgeAlias, RepoAlias, RepoActor)> {
let span = let span =
tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config); tracing::info_span!("create_forge_repos", name = %forge_name, config = %forge_config);

View file

@ -8,7 +8,7 @@ mod init {
let file = fs.base().join(".git-next.toml"); let file = fs.base().join(".git-next.toml");
fs.file_write(&file, "contents")?; fs.file_write(&file, "contents")?;
crate::init::run(fs.clone())?; crate::init::run(&fs)?;
assert_eq!( assert_eq!(
fs.file_read_to_string(&file)?, fs.file_read_to_string(&file)?,
@ -23,7 +23,7 @@ mod init {
fn should_create_default_file_if_not_exists() -> TestResult { fn should_create_default_file_if_not_exists() -> TestResult {
let fs = kxio::fs::temp()?; let fs = kxio::fs::temp()?;
crate::init::run(fs.clone())?; crate::init::run(&fs)?;
let file = fs.base().join(".git-next.toml"); let file = fs.base().join(".git-next.toml");