use derive_more::Deref as _; use crate::messages::NotifyUser; use git_next_core::git::UserNotification; use serde_json::json; 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 } } }), } } }