From c0d4269d614cc77a3812c4c6f0f3e2cfbf5578bb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 21 Jul 2024 13:44:44 +0100 Subject: [PATCH] WIP: feat: post webhook to user --- crates/git/src/commit.rs | 2 +- .../server-actor/src/handlers/notify_user.rs | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/git/src/commit.rs b/crates/git/src/commit.rs index 045d223..a715e95 100644 --- a/crates/git/src/commit.rs +++ b/crates/git/src/commit.rs @@ -38,7 +38,7 @@ impl From for Commit { } newtype!(Sha: String, Display, Hash,PartialOrd, Ord: "The unique SHA for a git commit."); -newtype!(Message: String, Hash, PartialOrd, Ord: "The commit message for a git commit."); +newtype!(Message: String, Display, Hash, PartialOrd, Ord: "The commit message for a git commit."); #[derive(Clone, Debug)] pub struct Histories { diff --git a/crates/server-actor/src/handlers/notify_user.rs b/crates/server-actor/src/handlers/notify_user.rs index 23ee70f..cbd9cd1 100644 --- a/crates/server-actor/src/handlers/notify_user.rs +++ b/crates/server-actor/src/handlers/notify_user.rs @@ -1,5 +1,7 @@ // use actix::prelude::*; +use derive_more::Deref; +use git_next_git::UserNotification; use git_next_repo_actor::messages::NotifyUser; use crate::ServerActor; @@ -7,7 +9,33 @@ use crate::ServerActor; impl Handler for ServerActor { type Result = (); - fn handle(&mut self, _msg: NotifyUser, _ctx: &mut Self::Context) -> Self::Result { + fn handle(&mut self, msg: NotifyUser, _ctx: &mut Self::Context) -> Self::Result { + let _message = match msg.deref() { + UserNotification::CICheckFailed { + forge_alias, + repo_alias, + commit, + } => format!( + "HELP ME!: {forge_alias}/{repo_alias}: CI Checks failed for commit: [{}] {}",commit.sha(), commit.message() + ), + UserNotification::RepoConfigLoadFailure { + forge_alias, + repo_alias, + reason, + } => format!("HELP ME!: {forge_alias}/{repo_alias}: Failed to load config: {reason}"), + UserNotification::WebhookRegistration { + forge_alias, + repo_alias, + reason, + } => format!("HELP ME!: {forge_alias}/{repo_alias}: Failed to register webhook: {reason}"), + UserNotification::DevNotBasedOnMain { + forge_alias, + repo_alias, + dev_branch, + main_branch, + } => format!("HELP ME!: {forge_alias}/{repo_alias}: Dev branch '{dev_branch}' is not based on main branch '{main_branch}'"), + }; + tracing::info!(_message); // TODO: (#95) should notify user // send post to notification webhook url }