1use serde::{Deserialize, Serialize};
3use strum_macros::{EnumDiscriminants, EnumString};
4use uuid::Uuid;
5
6#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
7pub struct GithubPayload {
8 pub guid: Uuid,
9 pub signature_sha1: Option<String>,
10 pub signature_sha256: Option<String>,
11 pub event: Event,
12}
13
14pub type Organization = Option<serde_json::Value>;
15pub type Repository = Option<serde_json::Value>;
16pub type Installation = Option<serde_json::Value>;
17pub type Enterprise = Option<serde_json::Value>;
18pub type Sender = serde_json::Value;
19
20#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, EnumString, EnumDiscriminants)]
21#[serde(rename_all = "snake_case")]
22#[strum(serialize_all = "snake_case")]
23#[strum_discriminants(
24 derive(EnumString, Serialize, Deserialize),
25 strum(serialize_all = "snake_case"),
26 serde(rename_all = "snake_case")
27)]
28pub enum Event {
29 BranchProtectionRule {
30 action: String,
31 enterprise: Enterprise,
32 repository: Repository,
33 installation: Installation,
34 organization: Organization,
35 rule: BranchProtectionRule,
36 sender: Sender,
37 changes: Option<serde_json::Value>,
38 },
39 CheckRun {},
40 CheckSuite {},
41 CodeScanningAlert {},
42 CommitComment {},
43 Create {},
44 Delete {},
45 DependabotAlert {},
46 DeployKey {},
47 Deployment {},
48 DeploymentStatus {},
49 Discussion {},
50 DiscussionComment {},
51 Fork {},
52 GithubAppAuthorization {},
53 Gollum {},
54 Installation {},
55 InstallationRepositories {},
56 InstallationTarget {},
57 IssueComment {},
58 Issues {},
59 Label {},
60 MarketplacePurchase {},
61 Member {},
62 Membership {},
63 MergeGroup {},
64 Meta {},
65 Milestone {},
66 OrgBlock {},
67 Organization {},
68 Package {},
69 PageBuild {},
70 Ping {
71 hook: Option<Hook>,
72 hook_id: Option<i64>,
73 organization: Organization,
74 repository: Repository,
75 sender: Sender,
76 zen: String,
77 },
78 ProjectCard {},
79 Project {},
80 ProjectColumn {},
81 ProjectsV2 {},
82 ProjectsV2Item {},
83 Public {},
84 PullRequest {},
85 PullRequestReviewComments {},
86 PullRequestReview {},
87 PullRequestReviewThread {},
88 Push {
89 after: String,
90 base_ref: Option<String>,
91 before: String,
92 commits: Vec<Commit>,
93 compare: String,
94 created: bool,
95 deleted: bool,
96 enterprise: Enterprise,
97 forced: bool,
98 head_commit: Box<HeadCommit>,
100 installation: Installation,
101 organization: Organization,
102 pusher: Pusher,
103 r#ref: String,
104 repository: serde_json::Value,
105 sender: Sender,
106 },
107 RegistryPackage {},
108 Release {},
109 Repository {},
110 RepositoryDispatch {},
111 RepositoryImport {},
112 RepositoryVulnerabilityAlert {},
113 SecretScanningAlert {},
114 SecretScanningAlertLocation {},
115 SecretAdvisory {},
116 SecurityAndAnalysis {},
117 Sponsorship {},
118 Star {},
119 Status {},
120 TeamAdd {},
121 Team {},
122 Watch {},
123 WorkflowDispatch {},
124 WorkflowJob {},
125 WorkflowRun {},
126}
127
128impl Default for Event {
129 fn default() -> Self {
130 Self::Ping {
131 hook: Default::default(),
132 hook_id: Default::default(),
133 organization: Default::default(),
134 repository: Default::default(),
135 sender: Default::default(),
136 zen: Default::default(),
137 }
138 }
139}
140
141#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
142pub struct BranchProtectionRule {
143 pub admin_enforced: bool,
144 pub allow_deletions_enforcement_level: String,
145 pub authorized_actor_names: Vec<String>,
146 pub authorized_actors_only: bool,
147 pub authorized_dismissal_actors_only: bool,
148 pub create_protected: bool,
149 pub created_at: String,
150 pub dismiss_stale_reviews_on_push: bool,
151 pub id: i64,
152 pub ignore_approvals_from_contributors: bool,
153 pub linear_history_requirement_enforcement_level: EnforcementLevel,
154 pub merge_queue_enforcement_level: EnforcementLevel,
155 pub name: String,
156 pub pull_request_revies_enforcement_level: EnforcementLevel,
157 pub repository_id: i64,
158 pub require_code_owner_review: bool,
159 pub required_approving_review_count: i64,
160 pub required_conversation_resolution_level: EnforcementLevel,
161 pub required_deployments_enforcement_level: EnforcementLevel,
162 pub required_status_checks: Vec<String>,
163 pub required_status_checks_enforcement_level: EnforcementLevel,
164 pub signature_requirement_enforcement_level: EnforcementLevel,
165 pub strict_required_status_checks_policy: bool,
166 pub updated_at: String,
167}
168
169#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
170#[serde(rename_all = "snake_case")]
171pub enum EnforcementLevel {
172 #[default]
173 Off,
174 NonAdmins,
175 Everyone,
176}
177
178#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
179pub struct Hook {
180 active: bool,
181 app_id: Option<i64>,
182 config: Config,
183 created_at: String,
184 deliveries_url: Option<String>,
185 events: Vec<String>,
186 id: i64,
187 last_response: Option<LastResponse>,
188 name: Web,
189 ping_url: Option<String>,
190 test_url: Option<String>,
191 r#type: String,
192 updated_at: String,
193 url: Option<String>,
194}
195
196#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
197pub struct Config {
198 content_type: ContentType,
199 insecure_ssl: NumberOrString,
200 secret: String,
201 url: String,
202}
203
204#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
205#[serde(rename_all = "snake_case")]
206pub enum ContentType {
207 Json,
208 #[default]
209 Form,
210}
211
212#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
213#[serde(untagged, rename_all = "snake_case")]
214pub enum NumberOrString {
215 Number(f64),
216 String(String),
217}
218
219impl Default for NumberOrString {
220 fn default() -> Self {
221 Self::String("".into())
222 }
223}
224
225#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
226pub struct LastResponse {
227 code: Option<i64>,
228 status: Option<String>,
229 message: Option<String>,
230}
231
232#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
233#[serde(rename_all = "snake_case")]
234pub enum Web {
235 #[default]
236 Web,
237}
238
239#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
240pub struct Commit {
241 added: Option<Vec<String>>,
242 author: Author,
243 committer: Committer,
244 distinct: bool,
245 id: String,
246 message: String,
247 modified: Option<Vec<String>>,
248 removed: Option<Vec<String>>,
249 timestamp: String,
250 tree_id: String,
251 url: String,
252}
253
254#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
255pub struct Author {
256 date: Option<String>,
257 email: String,
258 name: String,
259 username: Option<String>,
260}
261
262#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
263pub struct Committer {
264 date: Option<String>,
265 email: Option<String>,
266 name: String,
267 username: Option<String>,
268}
269
270#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
271pub struct HeadCommit {
272 added: Option<Vec<String>>,
273 author: Author,
274 committer: Committer,
275 distinct: bool,
276 id: String,
277 message: String,
278 modified: Option<Vec<String>>,
279 removed: Option<Vec<String>>,
280 timestamp: String,
281 tree_id: String,
282 url: String,
283}
284
285#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
286pub struct Pusher {
287 date: Option<String>,
288 email: Option<String>,
289 name: String,
290 username: Option<String>,
291}