1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
use crate::model::{
    event_types::{macros::repo_origin, RepoEventInfo},
    prelude::*,
    repositories::workflows::{events::nested::*, PageBuild, Workflow},
};

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct WorkflowDispatchEvent {
    pub inputs: Option<Value>,
    #[serde(rename = "ref")]
    pub ref_field: String,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(WorkflowDispatchEvent, RepoEventInfo, event_info);

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run>
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkflowRunEvent {
    pub action: WorkflowRunAction,
    pub workflow_run: WorkflowRun,
    pub workflow: Workflow,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(WorkflowRunEvent, RepoEventInfo, event_info);

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job>
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkflowJobEvent {
    pub action: WorkflowJobAction,
    pub workflow_job: WorkflowJob,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(WorkflowJobEvent, RepoEventInfo, event_info);

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#check_run>
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CheckRunEvent {
    pub action: CheckRunAction,
    pub check_run: CheckRun,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(CheckRunEvent, RepoEventInfo, event_info);

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#check_suite>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CheckSuiteEvent {
    pub action: CheckSuiteAction,
    pub check_suite: CheckSuite,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(CheckSuiteEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum CheckSuiteAction {
    Completed,
    Requested,
    Rerequested,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#page_build>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PageBuildEvent {
    pub id: usize,
    pub build: PageBuild,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(PageBuildEvent, RepoEventInfo, event_info);

pub mod nested {
    use crate::model::{
        prelude::*,
        repositories::{events::nested::HeadCommit, Repository},
        user::SimpleUser,
    };

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
    #[strum(serialize_all = "snake_case")]
    pub enum WorkflowRunAction {
        Requested,
        Completed,
    }

    #[derive(Debug, Clone, Serialize, Deserialize)]
    pub struct WorkflowRun {
        pub id: i64,
        pub name: String,
        pub node_id: String,
        pub head_branch: String,
        pub head_sha: String,
        pub run_number: i64,
        pub event: String,
        pub status: String,
        pub conclusion: Value,
        pub workflow_id: i64,
        pub check_suite_id: i64,
        pub check_suite_node_id: String,
        pub url: String,
        pub html_url: String,
        pub pull_requests: Vec<Value>,
        pub created_at: String,
        pub updated_at: String,
        pub run_attempt: i64,
        pub run_started_at: String,
        pub jobs_url: String,
        pub logs_url: String,
        pub check_suite_url: String,
        pub artifacts_url: String,
        pub cancel_url: String,
        pub rerun_url: String,
        pub previous_attempt_url: Value,
        pub workflow_url: String,
        pub head_commit: HeadCommit,
        pub repository: Repository,
        pub head_repository: Repository,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
    #[strum(serialize_all = "snake_case")]
    pub enum WorkflowJobAction {
        Queued,
        Completed,
        InProgress,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct WorkflowJob {
        pub id: i64,
        pub run_id: i64,
        pub run_url: String,
        pub run_attempt: i64,
        pub node_id: String,
        pub head_sha: String,
        pub url: String,
        pub html_url: String,
        pub status: String,
        pub conclusion: Value,
        pub started_at: String,
        pub completed_at: Value,
        pub name: String,
        pub steps: Vec<Step>,
        pub check_run_url: String,
        pub labels: Vec<String>,
        pub runner_id: i64,
        pub runner_name: String,
        pub runner_group_id: i64,
        pub runner_group_name: String,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
    #[strum(serialize_all = "snake_case")]
    pub enum CheckRunAction {
        Completed,
        Created,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct CheckRun {
        pub id: i64,
        pub name: String,
        pub node_id: String,
        pub head_sha: String,
        pub external_id: String,
        pub url: String,
        pub html_url: String,
        pub details_url: String,
        pub status: String,
        pub conclusion: String,
        pub started_at: String,
        pub completed_at: String,
        pub output: Output,
        pub check_suite: CheckSuite,
        pub app: App,
        pub pull_requests: Vec<Value>,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Step {
        pub name: String,
        pub status: String,
        pub conclusion: Value,
        pub number: i64,
        pub started_at: String,
        pub completed_at: Value,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Output {
        pub title: Value,
        pub summary: Value,
        pub text: Value,
        pub annotations_count: i64,
        pub annotations_url: String,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct CheckSuite {
        pub id: i64,
        pub node_id: String,
        pub head_branch: String,
        pub head_sha: String,
        pub status: String,
        pub conclusion: Value,
        pub url: String,
        pub before: String,
        pub after: String,
        pub pull_requests: Vec<Value>,
        pub app: App,
        pub created_at: String,
        pub updated_at: String,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct App {
        pub id: i64,
        pub slug: String,
        pub node_id: String,
        pub owner: SimpleUser,
        pub name: String,
        pub description: String,
        pub external_url: String,
        pub html_url: String,
        pub created_at: String,
        pub updated_at: String,
        pub permissions: Permissions,
        pub events: Vec<String>,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Permissions {
        pub actions: String,
        pub administration: String,
        pub checks: String,
        pub contents: String,
        pub deployments: String,
        pub discussions: String,
        pub issues: String,
        pub metadata: String,
        pub organization_packages: String,
        pub packages: String,
        pub pages: String,
        pub pull_requests: String,
        pub repository_hooks: String,
        pub repository_projects: String,
        pub security_events: String,
        pub statuses: String,
        pub vulnerability_alerts: String,
    }
}

repo_origin!(WorkflowDispatchEvent);
repo_origin!(WorkflowRunEvent);
repo_origin!(WorkflowJobEvent);
repo_origin!(PageBuildEvent);
repo_origin!(CheckRunEvent);
repo_origin!(CheckSuiteEvent);