Paul Campbell
4160b6d6ee
All checks were successful
Rust / build (push) Successful in 7m19s
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
Release Please / Release-plz (push) Successful in 1m41s
Remove near-duplicate to string implementations.
93 lines
2.6 KiB
Rust
93 lines
2.6 KiB
Rust
//
|
|
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<Shout>, // 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<Self>;
|
|
}
|
|
|
|
fn short_message(user_notification: &UserNotification) -> String {
|
|
let (forge_alias, repo_alias) = user_notification.aliases();
|
|
format!("[git-next] {forge_alias}/{repo_alias}: {user_notification}")
|
|
}
|
|
|
|
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 have 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"),
|
|
}
|
|
}
|