use crate::model::{organizations::SimpleOrganization, prelude::*, repositories::Repository, user::SimpleUser};
#[derive(Deserialize, EnumString, EnumVariantNames, Debug)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum EventTypes {
GithubAppAuthorization,
Installation,
InstallationRepositories,
Gollum,
DeployKey,
Member,
Milestone,
Public,
Release,
Repository,
RepositoryDispatch,
RepositoryImport,
RepositoryVulnerabilityAlert,
SecretScanningAlert,
SecurityAdvisory,
Star,
Watch,
PullRequest,
PullRequestReview,
PullRequestReviewComment,
CommitComment,
Push,
Status,
IssueComment,
Issues,
Label,
Discussion,
DiscussionComment,
BranchProtectionRule,
Create,
Delete,
Fork,
CheckRun,
CheckSuite,
CodeScanningAlert,
Deployment,
DeploymentStatus,
PageBuild,
WorkflowDispatch,
WorkflowJob,
WorkflowRun,
Membership,
OrgBlock,
Organization,
Team,
TeamAdd,
Project,
ProjectCard,
ProjectColumn,
MarketplacePurchase,
Meta,
Package,
Ping,
Sponsorship,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct RepoEventInfo {
pub repository: Repository,
pub organization: Option<SimpleOrganization>,
pub installation: Option<Value>,
pub sender: SimpleUser,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct OrgEventInfo {
pub organization: SimpleOrganization,
pub installation: Option<Value>,
pub sender: SimpleUser,
}
pub trait Event<'de>: Serialize + Deserialize<'de> {
type Origin: Serialize + Deserialize<'de>;
fn origin(&self) -> Option<Self::Origin> {
None
}
}
pub(crate) mod macros {
macro_rules! repo_origin {
($ev:ident) => {
impl crate::model::event_types::Event<'_> for $ev {
type Origin = crate::model::repositories::Repository;
fn origin(&self) -> Option<Self::Origin> {
Some(self.event_info.repository.clone())
}
}
};
}
macro_rules! org_origin {
($ev:ident) => {
impl crate::model::event_types::Event<'_> for $ev {
type Origin = crate::model::organizations::Organization;
}
};
}
pub(crate) use org_origin;
pub(crate) use repo_origin;
}