// 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; #[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, } => format!("CI Check Failed: {forge_alias}/{repo_alias}: {commit}"), UserNotification::RepoConfigLoadFailure { forge_alias, repo_alias, reason: _, } => format!("Invalid Repo Config: {forge_alias}/{repo_alias}"), UserNotification::WebhookRegistration { forge_alias, repo_alias, reason: _, } => format!("Failed Webhook Registration: {forge_alias}/{repo_alias}"), UserNotification::DevNotBasedOnMain { forge_alias, repo_alias, dev_branch: _, main_branch: _, dev_commit: _, main_commit: _, } => format!("Dev not based on Main: {forge_alias}/{repo_alias}"), }; format!("[git-next] {tail}") } fn full_message(user_notification: &UserNotification) -> String { match user_notification { UserNotification::CICheckFailed { forge_alias, repo_alias, commit, } => { 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}"), ] .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, } => { let dev_sha = dev_commit.sha(); let dev_message = dev_commit.message(); let main_sha = main_commit.sha(); let main_message = main_commit.message(); [ 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}"), format!("{dev_branch}:\n - {dev_sha}\n - {dev_message}"), format!("{main_branch}:\n - {main_sha}\n - {main_message}"), ] .join("\n\n") } } }