Compare commits
1 commit
31859a0c69
...
0adfcff93d
Author | SHA1 | Date | |
---|---|---|---|
0adfcff93d |
11 changed files with 99 additions and 8 deletions
|
@ -78,6 +78,7 @@ git-conventional = "0.12"
|
||||||
bytes = "1.6"
|
bytes = "1.6"
|
||||||
ulid = "1.1"
|
ulid = "1.1"
|
||||||
warp = "0.3"
|
warp = "0.3"
|
||||||
|
time = "0.3"
|
||||||
|
|
||||||
# boilerplate
|
# boilerplate
|
||||||
derive_more = { version = "1.0.0-beta.6", features = [
|
derive_more = { version = "1.0.0-beta.6", features = [
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
crate::newtype!(BranchName: String, derive_more::Display, Default: "The name of a Git branch");
|
use serde::Serialize;
|
||||||
|
|
||||||
|
crate::newtype!(BranchName: String, derive_more::Display, Default, Serialize: "The name of a Git branch");
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
crate::newtype!(ForgeAlias: String, Hash, PartialOrd, Ord, derive_more::Display, Default: "The name of a Forge to connect to");
|
use serde::Serialize;
|
||||||
|
|
||||||
|
crate::newtype!(ForgeAlias: String, Hash, PartialOrd, Ord, derive_more::Display, Default, Serialize: "The name of a Forge to connect to");
|
||||||
impl From<&ForgeAlias> for std::path::PathBuf {
|
impl From<&ForgeAlias> for std::path::PathBuf {
|
||||||
fn from(value: &ForgeAlias) -> Self {
|
fn from(value: &ForgeAlias) -> Self {
|
||||||
Self::from(&value.0)
|
Self::from(&value.0)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::newtype;
|
use crate::newtype;
|
||||||
|
|
||||||
newtype!(RepoAlias: String, Display, Default, PartialOrd, Ord: r#"The alias of a repo.
|
newtype!(RepoAlias: String, Display, Default, PartialOrd, Ord, Serialize: r#"The alias of a repo.
|
||||||
|
|
||||||
This is the alias for the repo within `git-next-server.toml`."#);
|
This is the alias for the repo within `git-next-server.toml`."#);
|
||||||
|
|
|
@ -25,11 +25,13 @@ async-trait = { workspace = true }
|
||||||
# fs/network
|
# fs/network
|
||||||
kxio = { workspace = true }
|
kxio = { workspace = true }
|
||||||
|
|
||||||
# # TOML parsing
|
# TOML parsing
|
||||||
# serde = { workspace = true }
|
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
# toml = { workspace = true }
|
# toml = { workspace = true }
|
||||||
|
|
||||||
|
# webhooks - user notification
|
||||||
|
serde = { workspace = true }
|
||||||
|
|
||||||
# Secrets and Password
|
# Secrets and Password
|
||||||
secrecy = { workspace = true }
|
secrecy = { workspace = true }
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ use config::newtype;
|
||||||
use derive_more::Display;
|
use derive_more::Display;
|
||||||
//
|
//
|
||||||
use git_next_config as config;
|
use git_next_config as config;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -13,6 +14,7 @@ use git_next_config as config;
|
||||||
Ord,
|
Ord,
|
||||||
derive_more::Constructor,
|
derive_more::Constructor,
|
||||||
derive_more::Display,
|
derive_more::Display,
|
||||||
|
Serialize,
|
||||||
)]
|
)]
|
||||||
#[display("{}", sha)]
|
#[display("{}", sha)]
|
||||||
pub struct Commit {
|
pub struct Commit {
|
||||||
|
@ -37,8 +39,8 @@ impl From<config::webhook::Push> for Commit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newtype!(Sha: String, Display, Hash,PartialOrd, Ord: "The unique SHA for a git commit.");
|
newtype!(Sha: String, Display, Hash,PartialOrd, Ord, Serialize: "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, Serialize: "The commit message for a git commit.");
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Histories {
|
pub struct Histories {
|
||||||
|
|
|
@ -43,6 +43,7 @@ git-conventional = { workspace = true }
|
||||||
# Webhooks
|
# Webhooks
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
ulid = { workspace = true }
|
ulid = { workspace = true }
|
||||||
|
time = { workspace = true }
|
||||||
|
|
||||||
# boilerplate
|
# boilerplate
|
||||||
derive_more = { workspace = true }
|
derive_more = { workspace = true }
|
||||||
|
|
|
@ -2,6 +2,7 @@ mod branch;
|
||||||
pub mod handlers;
|
pub mod handlers;
|
||||||
mod load;
|
mod load;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
|
mod notifications;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
72
crates/repo-actor/src/notifications.rs
Normal file
72
crates/repo-actor/src/notifications.rs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
use derive_more::Deref as _;
|
||||||
|
use git_next_git::UserNotification;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
use crate::messages::NotifyUser;
|
||||||
|
|
||||||
|
impl From<NotifyUser> for serde_json::Value {
|
||||||
|
fn from(value: NotifyUser) -> Self {
|
||||||
|
let timestamp = time::OffsetDateTime::now_utc().unix_timestamp().to_string();
|
||||||
|
match value.deref() {
|
||||||
|
UserNotification::CICheckFailed {
|
||||||
|
forge_alias,
|
||||||
|
repo_alias,
|
||||||
|
commit,
|
||||||
|
} => json!({
|
||||||
|
"type": "cicheck.failed",
|
||||||
|
"timestamp": timestamp,
|
||||||
|
"data": {
|
||||||
|
"forge_alias": forge_alias,
|
||||||
|
"repo_alias": repo_alias,
|
||||||
|
"commit": {
|
||||||
|
"sha": commit.sha(),
|
||||||
|
"message": commit.message()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
UserNotification::RepoConfigLoadFailure {
|
||||||
|
forge_alias,
|
||||||
|
repo_alias,
|
||||||
|
reason,
|
||||||
|
} => json!({
|
||||||
|
"type": "config.load.failed",
|
||||||
|
"timestamp": timestamp,
|
||||||
|
"data": {
|
||||||
|
"forge_alias": forge_alias,
|
||||||
|
"repo_alias": repo_alias,
|
||||||
|
"reason": reason
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
UserNotification::WebhookRegistration {
|
||||||
|
forge_alias,
|
||||||
|
repo_alias,
|
||||||
|
reason,
|
||||||
|
} => json!({
|
||||||
|
"type": "webhook.registration.failed",
|
||||||
|
"timestamp": timestamp,
|
||||||
|
"data": {
|
||||||
|
"forge_alias": forge_alias,
|
||||||
|
"repo_alias": repo_alias,
|
||||||
|
"reason": reason
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
UserNotification::DevNotBasedOnMain {
|
||||||
|
forge_alias,
|
||||||
|
repo_alias,
|
||||||
|
dev_branch,
|
||||||
|
main_branch,
|
||||||
|
} => json!({
|
||||||
|
"type": "branch.dev.not-on-main",
|
||||||
|
"timestamp": timestamp,
|
||||||
|
"data": {
|
||||||
|
"forge_alias": forge_alias,
|
||||||
|
"repo_alias": repo_alias,
|
||||||
|
"branches": {
|
||||||
|
"dev": dev_branch,
|
||||||
|
"main": main_branch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,10 @@ derive-with = { workspace = true }
|
||||||
# Actors
|
# Actors
|
||||||
actix = { workspace = true }
|
actix = { workspace = true }
|
||||||
|
|
||||||
|
# Webhooks
|
||||||
|
serde = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
# Testing
|
# Testing
|
||||||
# assert2 = { workspace = true }
|
# assert2 = { workspace = true }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use git_next_repo_actor::messages::NotifyUser;
|
use git_next_repo_actor::messages::NotifyUser;
|
||||||
|
|
||||||
|
@ -7,7 +8,9 @@ use crate::ServerActor;
|
||||||
impl Handler<NotifyUser> for ServerActor {
|
impl Handler<NotifyUser> for ServerActor {
|
||||||
type Result = ();
|
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 _payload = serde_json::Value::from(msg);
|
||||||
|
tracing::info!("{}", _payload.to_string());
|
||||||
// TODO: (#95) should notify user
|
// TODO: (#95) should notify user
|
||||||
// send post to notification webhook url
|
// send post to notification webhook url
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue