forked from kemitix/git-next
73 lines
2.3 KiB
Rust
73 lines
2.3 KiB
Rust
|
use derive_more::Deref as _;
|
||
|
use git_next_git::UserNotification;
|
||
|
use serde_json::json;
|
||
|
|
||
|
use crate::messages::NotifyUser;
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
}),
|
||
|
}
|
||
|
}
|
||
|
}
|