2024-07-21 13:44:44 +01:00
|
|
|
use derive_more::Deref as _;
|
|
|
|
|
|
|
|
use crate::messages::NotifyUser;
|
2024-07-26 06:49:09 +01:00
|
|
|
use git_next_core::git::UserNotification;
|
|
|
|
|
|
|
|
use serde_json::json;
|
2024-07-21 13:44:44 +01:00
|
|
|
|
|
|
|
impl NotifyUser {
|
|
|
|
pub fn as_json(self, timestamp: time::OffsetDateTime) -> serde_json::Value {
|
|
|
|
let timestamp = timestamp.unix_timestamp().to_string();
|
|
|
|
match self.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|