// use actix::prelude::*; use derive_more::derive::Constructor; use git_next_core::{git::UserNotification, server::Shout}; pub use history::History; mod desktop; mod email; mod handlers; mod history; pub mod messages; 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 history: History, // record of alerts sent recently (e.g. 24 hours) net: kxio::network::Network, } impl Actor for AlertsActor { type Context = Context; } fn short_message(user_notification: &UserNotification) -> String { let tail = match user_notification { UserNotification::CICheckFailed { forge_alias, repo_alias, commit, log: _, } => format!("{forge_alias}/{repo_alias}: CI Check Failed: {commit}"), UserNotification::RepoConfigLoadFailure { forge_alias, repo_alias, reason: _, } => format!("{forge_alias}/{repo_alias}: Invalid Repo Config"), UserNotification::WebhookRegistration { forge_alias, repo_alias, reason: _, } => format!("{forge_alias}/{repo_alias}: Failed Webhook Registration"), UserNotification::DevNotBasedOnMain { forge_alias, repo_alias, dev_branch: _, main_branch: _, dev_commit: _, main_commit: _, log: _, } => format!("{forge_alias}/{repo_alias}: Dev not based on Main"), }; format!("[git-next] {tail}") } fn full_message(user_notification: &UserNotification) -> String { match user_notification { UserNotification::CICheckFailed { forge_alias, repo_alias, commit, log, } => { let sha = commit.sha(); let message = commit.message(); [ "CI Checks had Failed".to_string(), format!("Forge: {forge_alias}\nRepo : {repo_alias}"), format!("Commit:\n - {sha}\n - {message}"), "Log:".to_string(), log.join("\n"), ] .join("\n\n") } UserNotification::RepoConfigLoadFailure { forge_alias, repo_alias, reason, } => [ "Failed to read or parse the .git-next.toml file from repo".to_string(), format!(" - {reason}"), format!("Forge: {forge_alias}\nRepo : {repo_alias}"), ] .join("\n\n"), UserNotification::WebhookRegistration { forge_alias, repo_alias, reason, } => [ "Failed to register webhook with the forge".to_string(), format!(" - {reason}"), format!("Forge: {forge_alias}\nRepo : {repo_alias}"), ] .join("\n\n"), UserNotification::DevNotBasedOnMain { forge_alias, repo_alias, dev_branch, main_branch, dev_commit: _, main_commit: _, log, } => [ format!("The branch '{dev_branch}' is not based on the branch '{main_branch}'."), format!("TODO: Rebase '{dev_branch}' onto '{main_branch}'."), format!("Forge: {forge_alias}\nRepo : {repo_alias}"), "Log:".to_string(), log.join("\n"), ] .join("\n\n"), } }