use serde::{Deserialize, Serialize}; use uuid::Uuid; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct RefUpdate { pub name: String, pub old_oid: String, pub new_oid: String, } impl RefUpdate { #[must_use] pub fn is_delete(&self) -> bool { self.new_oid.is_empty() || self.new_oid.chars().all(|c| c == '0') } #[must_use] pub fn ref_kind(&self) -> Option<&'static str> { if self.name.starts_with("refs/tags/") { Some("tag") } else if self.name.starts_with("refs/heads/") { Some("branch") } else { None } } #[must_use] pub fn short_name(&self) -> &str { self.name .strip_prefix("refs/heads/") .or_else(|| self.name.strip_prefix("refs/tags/")) .unwrap_or(self.name.as_str()) } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum PullRequestAction { Opened, Synchronize, Reopened, Merged, Closed, } impl PullRequestAction { #[must_use] pub const fn as_str(self) -> &'static str { match self { Self::Opened => "opened", Self::Synchronize => "synchronize", Self::Reopened => "reopened", Self::Merged => "merged", Self::Closed => "closed", } } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(tag = "kind", rename_all = "snake_case")] pub enum CiEvent { Push(PushEvent), PullRequest(PullRequestEvent), } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PushEvent { pub id: Uuid, pub repo_id: Uuid, pub space_id: Uuid, pub actor_id: Option, pub refs: Vec, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PullRequestEvent { pub id: Uuid, pub repo_id: Uuid, pub space_id: Uuid, pub actor_id: Option, pub number: i64, pub action: PullRequestAction, pub head_sha: String, pub head_ref: String, pub base_sha: String, pub base_ref: String, }