2024-07-28 08:58:32 +01:00
|
|
|
//
|
2024-07-21 13:44:44 +01:00
|
|
|
|
2024-07-28 08:58:32 +01:00
|
|
|
use crate::repo::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 {
|
2024-07-28 08:58:32 +01:00
|
|
|
pub fn as_json(&self, timestamp: time::OffsetDateTime) -> serde_json::Value {
|
2024-07-21 13:44:44 +01:00
|
|
|
let timestamp = timestamp.unix_timestamp().to_string();
|
2024-08-05 07:39:38 +01:00
|
|
|
match &**self {
|
2024-07-21 13:44:44 +01:00
|
|
|
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,
|
2024-08-01 19:48:59 +01:00
|
|
|
dev_commit,
|
|
|
|
main_commit,
|
2024-07-21 13:44:44 +01:00
|
|
|
} => 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
|
2024-08-01 19:48:59 +01:00
|
|
|
},
|
|
|
|
"commits": {
|
|
|
|
"dev": {
|
|
|
|
"sha": dev_commit.sha(),
|
|
|
|
"message": dev_commit.message()
|
|
|
|
},
|
|
|
|
"main": {
|
|
|
|
"sha": main_commit.sha(),
|
|
|
|
"message": main_commit.message()
|
|
|
|
}
|
2024-07-21 13:44:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|