2024-08-01 19:48:59 +01:00
|
|
|
//
|
2024-08-03 12:53:59 +01:00
|
|
|
use actix::prelude::*;
|
|
|
|
|
|
|
|
use derive_more::derive::Constructor;
|
|
|
|
|
|
|
|
use git_next_core::{git::UserNotification, server::Shout};
|
|
|
|
|
|
|
|
pub use history::History;
|
|
|
|
|
2024-08-02 22:56:03 +01:00
|
|
|
mod desktop;
|
2024-08-01 19:48:59 +01:00
|
|
|
mod email;
|
2024-08-03 12:53:59 +01:00
|
|
|
mod handlers;
|
|
|
|
mod history;
|
|
|
|
pub mod messages;
|
2024-08-01 19:48:59 +01:00
|
|
|
mod webhook;
|
|
|
|
|
2024-08-03 22:31:17 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2024-08-03 12:53:59 +01:00
|
|
|
#[derive(Debug, Constructor)]
|
|
|
|
pub struct AlertsActor {
|
|
|
|
shout: Option<Shout>, // config for sending alerts to users
|
2024-08-03 22:31:17 +01:00
|
|
|
history: History, // record of alerts sent recently (e.g. 24 hours)
|
2024-08-03 12:53:59 +01:00
|
|
|
net: kxio::network::Network,
|
|
|
|
}
|
2024-08-01 19:48:59 +01:00
|
|
|
|
2024-08-03 12:53:59 +01:00
|
|
|
impl Actor for AlertsActor {
|
|
|
|
type Context = Context<Self>;
|
2024-08-01 19:48:59 +01:00
|
|
|
}
|
2024-08-02 22:56:03 +01:00
|
|
|
|
2024-08-03 22:31:17 +01:00
|
|
|
fn short_message(user_notification: &UserNotification) -> String {
|
|
|
|
let tail = match user_notification {
|
2024-08-02 22:56:03 +01:00
|
|
|
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}")
|
|
|
|
}
|
|
|
|
|
2024-08-03 22:31:17 +01:00
|
|
|
fn full_message(user_notification: &UserNotification) -> String {
|
|
|
|
match user_notification {
|
2024-08-02 22:56:03 +01:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|