gh_workflow/
event.rs

1#![allow(clippy::needless_update)]
2
3use std::collections::HashMap;
4
5use derive_setters::Setters;
6use merge::Merge;
7use serde::{Deserialize, Serialize};
8
9use crate::is_default;
10
11/// Represents all possible webhook events that can trigger a workflow
12/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
13#[derive(Default, Debug, Clone, Deserialize, Serialize, Merge, Setters, PartialEq, Eq)]
14#[setters(strip_option, into)]
15pub struct Event {
16    #[serde(skip_serializing_if = "Option::is_none")]
17    #[merge(strategy = merge::option::overwrite_none)]
18    pub branch_protection_rule: Option<BranchProtectionRule>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    #[merge(strategy = merge::option::overwrite_none)]
21    pub check_run: Option<CheckRun>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    #[merge(strategy = merge::option::overwrite_none)]
24    pub check_suite: Option<CheckSuite>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[merge(strategy = merge::option::overwrite_none)]
27    pub create: Option<Create>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    #[merge(strategy = merge::option::overwrite_none)]
30    pub delete: Option<Delete>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    #[merge(strategy = merge::option::overwrite_none)]
33    pub deployment: Option<Deployment>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    #[merge(strategy = merge::option::overwrite_none)]
36    pub deployment_status: Option<DeploymentStatus>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[merge(strategy = merge::option::overwrite_none)]
39    pub discussion: Option<Discussion>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[merge(strategy = merge::option::overwrite_none)]
42    pub discussion_comment: Option<DiscussionComment>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[merge(strategy = merge::option::overwrite_none)]
45    pub fork: Option<bool>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[merge(strategy = merge::option::overwrite_none)]
48    pub gollum: Option<bool>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    #[merge(strategy = merge::option::overwrite_none)]
51    pub issue_comment: Option<IssueComment>,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[merge(strategy = merge::option::overwrite_none)]
54    pub issues: Option<Issues>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[merge(strategy = merge::option::overwrite_none)]
57    pub label: Option<Label>,
58    #[serde(skip_serializing_if = "Option::is_none")]
59    #[merge(strategy = merge::option::overwrite_none)]
60    pub merge_group: Option<MergeGroup>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[merge(strategy = merge::option::overwrite_none)]
63    pub milestone: Option<Milestone>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    #[merge(strategy = merge::option::overwrite_none)]
66    pub page_build: Option<bool>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    #[merge(strategy = merge::option::overwrite_none)]
69    pub public: Option<bool>,
70    #[serde(skip_serializing_if = "Option::is_none")]
71    #[merge(strategy = merge::option::overwrite_none)]
72    pub pull_request: Option<PullRequest>,
73    #[serde(skip_serializing_if = "Option::is_none")]
74    #[merge(strategy = merge::option::overwrite_none)]
75    pub pull_request_review: Option<PullRequestReview>,
76    #[serde(skip_serializing_if = "Option::is_none")]
77    #[merge(strategy = merge::option::overwrite_none)]
78    pub pull_request_review_comment: Option<PullRequestReviewComment>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    #[merge(strategy = merge::option::overwrite_none)]
81    pub pull_request_target: Option<PullRequestTarget>,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    #[merge(strategy = merge::option::overwrite_none)]
84    pub push: Option<Push>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    #[merge(strategy = merge::option::overwrite_none)]
87    pub registry_package: Option<RegistryPackage>,
88    #[serde(skip_serializing_if = "Option::is_none")]
89    #[merge(strategy = merge::option::overwrite_none)]
90    pub release: Option<Release>,
91    #[serde(skip_serializing_if = "Option::is_none")]
92    #[merge(strategy = merge::option::overwrite_none)]
93    pub repository_dispatch: Option<RepositoryDispatch>,
94    #[serde(skip_serializing_if = "Option::is_none")]
95    #[merge(strategy = merge::option::overwrite_none)]
96    pub schedule: Option<Vec<Schedule>>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    #[merge(strategy = merge::option::overwrite_none)]
99    pub status: Option<bool>,
100    #[serde(skip_serializing_if = "Option::is_none")]
101    #[merge(strategy = merge::option::overwrite_none)]
102    pub watch: Option<Watch>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    #[merge(strategy = merge::option::overwrite_none)]
105    pub workflow_call: Option<WorkflowCall>,
106    #[serde(skip_serializing_if = "Option::is_none")]
107    #[merge(strategy = merge::option::overwrite_none)]
108    pub workflow_dispatch: Option<WorkflowDispatch>,
109    #[serde(skip_serializing_if = "Option::is_none")]
110    #[merge(strategy = merge::option::overwrite_none)]
111    pub workflow_run: Option<WorkflowRun>,
112}
113
114impl Event {
115    pub fn add_schedule(mut self, schedule: impl Into<Schedule>) -> Self {
116        if let Some(list) = self.schedule.as_mut() {
117            list.push(schedule.into());
118        } else {
119            self.schedule = Some(vec![schedule.into()])
120        }
121
122        self
123    }
124
125    pub fn add_cron_schedule(self, cron: impl ToString) -> Self {
126        self.add_schedule(Schedule::new(cron))
127    }
128}
129
130/// Types of branch protection rule events
131/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#branch_protection_rule
132#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
133#[serde(rename_all = "snake_case")]
134pub enum BranchProtectionRuleType {
135    /// A branch protection rule was created
136    Created,
137    /// A branch protection rule was edited
138    Edited,
139    /// A branch protection rule was deleted
140    Deleted,
141}
142
143/// Configuration for branch protection rule events
144#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
145#[setters(strip_option, into)]
146pub struct BranchProtectionRule {
147    #[serde(default, skip_serializing_if = "Vec::is_empty")]
148    pub types: Vec<BranchProtectionRuleType>,
149}
150
151impl BranchProtectionRule {
152    /// Adds a branch protection rule event type to filter on
153    pub fn add_type(mut self, type_: BranchProtectionRuleType) -> Self {
154        self.types.push(type_);
155        self
156    }
157}
158
159/// Types of check run events
160/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#check_run
161#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
162#[serde(rename_all = "snake_case")]
163pub enum CheckRunType {
164    /// A check run was created
165    Created,
166    /// A check run was requested to be re-run
167    Rerequested,
168    /// A check run was completed
169    Completed,
170    /// A user requested an action from the check run
171    RequestedAction,
172}
173
174#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
175#[setters(strip_option, into)]
176pub struct CheckRun {
177    #[serde(default, skip_serializing_if = "Vec::is_empty")]
178    pub types: Vec<CheckRunType>,
179}
180
181impl CheckRun {
182    /// Adds a check run event type to filter on
183    pub fn add_type(mut self, type_: CheckRunType) -> Self {
184        self.types.push(type_);
185        self
186    }
187}
188
189/// Types of check suite events
190/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#check_suite
191#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
192#[serde(rename_all = "snake_case")]
193pub enum CheckSuiteType {
194    /// A check suite has completed
195    Completed,
196}
197
198/// Configuration for check suite events
199
200#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
201#[setters(strip_option, into)]
202pub struct CheckSuite {
203    #[serde(default, skip_serializing_if = "Vec::is_empty")]
204    pub types: Vec<CheckSuiteType>,
205}
206
207impl CheckSuite {
208    /// Adds a check suite event type to filter on
209    pub fn add_type(mut self, type_: CheckSuiteType) -> Self {
210        self.types.push(type_);
211        self
212    }
213}
214
215/// Configuration for create events (branch or tag creation)
216/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#create
217#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
218#[setters(strip_option, into)]
219pub struct Create {
220    /// Filter on specific branch names
221    #[serde(default, skip_serializing_if = "Vec::is_empty")]
222    pub branches: Vec<String>,
223    /// Filter on specific tag names
224    #[serde(default, skip_serializing_if = "Vec::is_empty")]
225    pub tags: Vec<String>,
226}
227
228impl Create {
229    /// Adds a branch name to filter on
230    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
231        self.branches.push(branch.into());
232        self
233    }
234
235    /// Adds a tag name to filter on
236    pub fn add_tag<S: Into<String>>(mut self, tag: S) -> Self {
237        self.tags.push(tag.into());
238        self
239    }
240}
241
242/// Configuration for delete events (branch or tag deletion)
243/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#delete
244#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
245#[setters(strip_option, into)]
246pub struct Delete {
247    /// Filter on specific branch names
248    #[serde(default, skip_serializing_if = "Vec::is_empty")]
249    pub branches: Vec<String>,
250    /// Filter on specific tag names
251    #[serde(default, skip_serializing_if = "Vec::is_empty")]
252    pub tags: Vec<String>,
253}
254
255impl Delete {
256    /// Adds a branch name to filter on
257    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
258        self.branches.push(branch.into());
259        self
260    }
261
262    /// Adds a tag name to filter on
263    pub fn add_tag<S: Into<String>>(mut self, tag: S) -> Self {
264        self.tags.push(tag.into());
265        self
266    }
267}
268
269/// Types of deployment events
270/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#deployment
271
272#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
273#[setters(strip_option, into)]
274pub struct Deployment {
275    /// Filter on specific branch names
276    #[serde(default, skip_serializing_if = "Vec::is_empty")]
277    pub branches: Vec<String>,
278}
279
280impl Deployment {
281    /// Adds a branch name to filter on
282    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
283        self.branches.push(branch.into());
284        self
285    }
286}
287
288/// Types of deployment status events
289/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#deployment_status
290
291#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
292#[setters(strip_option, into)]
293pub struct DeploymentStatus {
294    /// Filter on specific deployment states
295    #[serde(default, skip_serializing_if = "Vec::is_empty")]
296    pub states: Vec<String>,
297}
298
299impl DeploymentStatus {
300    /// Adds a deployment state to filter on
301    pub fn add_state<S: Into<String>>(mut self, state: S) -> Self {
302        self.states.push(state.into());
303        self
304    }
305}
306
307/// Types of discussion events
308/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#discussion
309#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
310#[serde(rename_all = "snake_case")]
311pub enum DiscussionType {
312    /// A discussion was created
313    Created,
314    /// A discussion was edited
315    Edited,
316    /// A discussion was deleted
317    Deleted,
318    /// A discussion was transferred between repositories
319    Transferred,
320    /// A discussion was pinned
321    Pinned,
322    /// A discussion was unpinned
323    Unpinned,
324    /// A discussion was labeled
325    Labeled,
326    /// A discussion was unlabeled
327    Unlabeled,
328    /// A discussion was locked
329    Locked,
330    /// A discussion was unlocked
331    Unlocked,
332    /// A discussion's category was changed
333    CategoryChanged,
334    /// A discussion was marked as answered
335    Answered,
336    /// A discussion was unmarked as answered
337    Unanswered,
338}
339
340/// Configuration for discussion events
341
342#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
343pub struct Discussion {
344    /// Filter on specific discussion event types
345    #[serde(default, skip_serializing_if = "Vec::is_empty")]
346    pub types: Vec<DiscussionType>,
347}
348
349impl Discussion {
350    /// Adds a discussion event type to filter on
351    pub fn add_type(mut self, type_: DiscussionType) -> Self {
352        self.types.push(type_);
353        self
354    }
355}
356
357/// Types of discussion comment events
358/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#discussion_comment
359#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
360#[serde(rename_all = "snake_case")]
361pub enum DiscussionCommentType {
362    /// A discussion comment was created
363    Created,
364    /// A discussion comment was edited
365    Edited,
366    /// A discussion comment was deleted
367    Deleted,
368}
369
370/// Configuration for discussion comment events
371
372#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
373pub struct DiscussionComment {
374    /// Filter on specific discussion comment event types
375    #[serde(default, skip_serializing_if = "Vec::is_empty")]
376    pub types: Vec<DiscussionCommentType>,
377}
378
379impl DiscussionComment {
380    /// Adds a discussion comment event type to filter on
381    pub fn add_type(mut self, type_: DiscussionCommentType) -> Self {
382        self.types.push(type_);
383        self
384    }
385}
386
387/// Configuration for issue comment events
388/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment
389#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
390pub struct IssueComment {
391    /// Filter on specific issue comment event types
392    #[serde(default, skip_serializing_if = "Vec::is_empty")]
393    pub types: Vec<IssueCommentType>,
394}
395
396/// Types of issue comment events
397#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
398#[serde(rename_all = "snake_case")]
399pub enum IssueCommentType {
400    /// An issue comment was created
401    Created,
402    /// An issue comment was edited
403    Edited,
404    /// An issue comment was deleted
405    Deleted,
406}
407
408impl IssueComment {
409    /// Adds an issue comment event type to filter on
410    pub fn add_type(mut self, type_: IssueCommentType) -> Self {
411        self.types.push(type_);
412        self
413    }
414}
415
416/// Types of issue events
417/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
418#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
419#[serde(rename_all = "snake_case")]
420pub enum IssuesType {
421    /// An issue was opened
422    Opened,
423    /// An issue was edited
424    Edited,
425    /// An issue was deleted
426    Deleted,
427    /// An issue was transferred between repositories
428    Transferred,
429    /// An issue was pinned
430    Pinned,
431    /// An issue was unpinned
432    Unpinned,
433    /// An issue was closed
434    Closed,
435    /// A closed issue was reopened
436    Reopened,
437    /// An issue was assigned to a user
438    Assigned,
439    /// An issue was unassigned from a user
440    Unassigned,
441    /// A label was added to an issue
442    Labeled,
443    /// A label was removed from an issue
444    Unlabeled,
445    /// An issue was locked
446    Locked,
447    /// An issue was unlocked
448    Unlocked,
449    /// An issue was added to a milestone
450    Milestoned,
451    /// An issue was removed from a milestone
452    Demilestoned,
453}
454
455/// Configuration for issue events
456
457#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
458#[setters(strip_option, into)]
459pub struct Issues {
460    /// Filter on specific issue event types
461    #[serde(default, skip_serializing_if = "Vec::is_empty")]
462    pub types: Vec<IssuesType>,
463}
464
465impl Issues {
466    /// Adds an issue event type to filter on
467    pub fn add_type(mut self, type_: IssuesType) -> Self {
468        self.types.push(type_);
469        self
470    }
471}
472
473/// Types of label events
474/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#label
475#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
476#[serde(rename_all = "snake_case")]
477pub enum LabelType {
478    /// A label was created
479    Created,
480    /// A label was edited
481    Edited,
482    /// A label was deleted
483    Deleted,
484}
485
486/// Configuration for label events
487
488#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
489#[setters(strip_option, into)]
490pub struct Label {
491    /// Filter on specific label event types
492    #[serde(default, skip_serializing_if = "Vec::is_empty")]
493    pub types: Vec<LabelType>,
494}
495
496impl Label {
497    /// Adds a label event type to filter on
498    pub fn add_type(mut self, type_: LabelType) -> Self {
499        self.types.push(type_);
500        self
501    }
502}
503
504#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
505#[serde(rename_all = "snake_case")]
506pub enum MergeGroupType {
507    ChecksRequested,
508}
509
510#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
511#[setters(strip_option, into)]
512pub struct MergeGroup {
513    #[serde(default, skip_serializing_if = "Vec::is_empty")]
514    pub types: Vec<MergeGroupType>,
515}
516
517impl MergeGroup {
518    pub fn add_type(mut self, type_: MergeGroupType) -> Self {
519        self.types.push(type_);
520        self
521    }
522}
523
524#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
525#[serde(rename_all = "snake_case")]
526pub enum MilestoneType {
527    Created,
528    Closed,
529    Opened,
530    Edited,
531    Deleted,
532}
533
534#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
535#[setters(strip_option, into)]
536pub struct Milestone {
537    #[serde(default, skip_serializing_if = "Vec::is_empty")]
538    pub types: Vec<MilestoneType>,
539}
540
541impl Milestone {
542    pub fn add_type(mut self, type_: MilestoneType) -> Self {
543        self.types.push(type_);
544        self
545    }
546}
547
548#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
549#[serde(rename_all = "snake_case")]
550pub enum PullRequestType {
551    Assigned,
552    Unassigned,
553    Labeled,
554    Unlabeled,
555    Opened,
556    Edited,
557    Closed,
558    Reopened,
559    Synchronize,
560    ReadyForReview,
561    Locked,
562    Unlocked,
563    ReviewRequested,
564    ReviewRequestRemoved,
565}
566
567#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
568#[setters(strip_option, into)]
569pub struct PullRequest {
570    #[serde(default, skip_serializing_if = "Vec::is_empty")]
571    pub types: Vec<PullRequestType>,
572    #[serde(default, skip_serializing_if = "Vec::is_empty")]
573    pub branches: Vec<String>,
574    #[serde(default, skip_serializing_if = "Vec::is_empty")]
575    pub paths: Vec<String>,
576}
577
578impl PullRequest {
579    pub fn add_type(mut self, type_: PullRequestType) -> Self {
580        self.types.push(type_);
581        self
582    }
583
584    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
585        self.branches.push(branch.into());
586        self
587    }
588
589    pub fn add_path<S: Into<String>>(mut self, path: S) -> Self {
590        self.paths.push(path.into());
591        self
592    }
593}
594
595/// Types of pull request review events
596/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_review
597#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
598#[serde(rename_all = "snake_case")]
599pub enum PullRequestReviewType {
600    /// A review was submitted for a pull request
601    Submitted,
602    /// A review was edited
603    Edited,
604    /// A review was dismissed
605    Dismissed,
606}
607
608/// Configuration for pull request review events
609
610#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
611#[setters(strip_option, into)]
612pub struct PullRequestReview {
613    /// Filter on specific pull request review event types
614    #[serde(default, skip_serializing_if = "Vec::is_empty")]
615    pub types: Vec<PullRequestReviewType>,
616}
617
618impl PullRequestReview {
619    /// Adds a pull request review event type to filter on
620    pub fn add_type(mut self, type_: PullRequestReviewType) -> Self {
621        self.types.push(type_);
622        self
623    }
624}
625
626/// Types of pull request review comment events
627/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_review_comment
628#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
629#[serde(rename_all = "snake_case")]
630pub enum PullRequestReviewCommentType {
631    /// A review comment was created
632    Created,
633    /// A review comment was edited
634    Edited,
635    /// A review comment was deleted
636    Deleted,
637}
638
639/// Configuration for pull request review comment events
640#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
641#[setters(strip_option, into)]
642pub struct PullRequestReviewComment {
643    /// Filter on specific pull request review comment event types
644    #[serde(default, skip_serializing_if = "Vec::is_empty")]
645    pub types: Vec<PullRequestReviewCommentType>,
646}
647
648impl PullRequestReviewComment {
649    /// Adds a pull request review comment event type to filter on
650    pub fn add_type(mut self, type_: PullRequestReviewCommentType) -> Self {
651        self.types.push(type_);
652        self
653    }
654}
655
656/// Configuration for pull request target events
657/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
658#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
659#[setters(strip_option, into)]
660pub struct PullRequestTarget {
661    /// Filter on specific pull request event types
662    #[serde(default, skip_serializing_if = "Vec::is_empty")]
663    pub types: Vec<PullRequestType>,
664    /// Filter on specific branch names
665    #[serde(default, skip_serializing_if = "Vec::is_empty")]
666    pub branches: Vec<String>,
667}
668
669impl PullRequestTarget {
670    /// Adds a pull request event type to filter on
671    pub fn add_type(mut self, type_: PullRequestType) -> Self {
672        self.types.push(type_);
673        self
674    }
675
676    /// Adds a branch name to filter on
677    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
678        self.branches.push(branch.into());
679        self
680    }
681}
682
683/// Configuration for push events
684/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
685#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
686#[setters(strip_option, into)]
687pub struct Push {
688    /// Filter on specific branch names
689    #[serde(default, skip_serializing_if = "Vec::is_empty")]
690    pub branches: Vec<String>,
691    /// Filter on specific file paths
692    #[serde(default, skip_serializing_if = "Vec::is_empty")]
693    pub paths: Vec<String>,
694    /// Filter on specific tags
695    #[serde(default, skip_serializing_if = "Vec::is_empty")]
696    pub tags: Vec<String>,
697}
698
699impl Push {
700    /// Adds a branch name to filter on
701    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
702        self.branches.push(branch.into());
703        self
704    }
705
706    /// Adds a file path to filter on
707    pub fn add_path<S: Into<String>>(mut self, path: S) -> Self {
708        self.paths.push(path.into());
709        self
710    }
711
712    /// Adds a tag name to filter on
713    pub fn add_tag<S: Into<String>>(mut self, tag: S) -> Self {
714        self.tags.push(tag.into());
715        self
716    }
717}
718
719/// Types of registry package events
720/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#registry_package
721#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
722#[serde(rename_all = "snake_case")]
723pub enum RegistryPackageType {
724    /// A package was published
725    Published,
726    /// A package was updated
727    Updated,
728}
729
730/// Configuration for registry package events
731
732#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
733#[setters(strip_option, into)]
734pub struct RegistryPackage {
735    /// Filter on specific registry package event types
736    #[serde(default, skip_serializing_if = "Vec::is_empty")]
737    pub types: Vec<RegistryPackageType>,
738}
739
740impl RegistryPackage {
741    /// Adds a registry package event type to filter on
742    pub fn add_type(mut self, type_: RegistryPackageType) -> Self {
743        self.types.push(type_);
744        self
745    }
746}
747
748/// Types of release events
749/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release
750#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
751#[serde(rename_all = "snake_case")]
752pub enum ReleaseType {
753    /// A release was published
754    Published,
755    /// A release was unpublished
756    Unpublished,
757    /// A release was created
758    Created,
759    /// A release was edited
760    Edited,
761    /// A release was deleted
762    Deleted,
763    /// A release was marked as a pre-release
764    Prereleased,
765    /// A release was released
766    Released,
767}
768
769/// Configuration for release events
770
771#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
772#[setters(strip_option, into)]
773pub struct Release {
774    /// Filter on specific release event types
775    #[serde(default, skip_serializing_if = "Vec::is_empty")]
776    pub types: Vec<ReleaseType>,
777}
778
779impl Release {
780    /// Adds a release event type to filter on
781    pub fn add_type(mut self, type_: ReleaseType) -> Self {
782        self.types.push(type_);
783        self
784    }
785}
786
787#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
788#[setters(strip_option, into)]
789pub struct RepositoryDispatch {
790    #[serde(default, skip_serializing_if = "Vec::is_empty")]
791    pub types: Vec<String>,
792}
793
794impl RepositoryDispatch {
795    pub fn add_type<S: Into<String>>(mut self, type_: S) -> Self {
796        self.types.push(type_.into());
797        self
798    }
799}
800
801#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
802#[setters(strip_option, into)]
803pub struct Schedule {
804    pub cron: String,
805}
806
807impl Schedule {
808    pub fn new(cron: impl ToString) -> Self {
809        Self { cron: cron.to_string() }
810    }
811}
812
813#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
814#[setters(strip_option, into)]
815pub struct Watch {
816    #[serde(default, skip_serializing_if = "Vec::is_empty")]
817    pub types: Vec<String>,
818}
819
820impl Watch {
821    pub fn add_type<S: Into<String>>(mut self, type_: S) -> Self {
822        self.types.push(type_.into());
823        self
824    }
825}
826
827/// Configuration for workflow call events
828/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_call
829#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
830#[setters(strip_option, into)]
831pub struct WorkflowCall {
832    /// Inputs for the workflow call
833    #[serde(skip_serializing_if = "HashMap::is_empty")]
834    pub inputs: HashMap<String, WorkflowCallInput>,
835    /// Outputs from the workflow call
836    #[serde(skip_serializing_if = "HashMap::is_empty")]
837    pub outputs: HashMap<String, WorkflowCallOutput>,
838    /// Secrets for the workflow call
839    #[serde(skip_serializing_if = "HashMap::is_empty")]
840    pub secrets: HashMap<String, WorkflowCallSecret>,
841}
842
843impl WorkflowCall {
844    pub fn add_input(mut self, name: impl Into<String>, input: WorkflowCallInput) -> Self {
845        self.inputs.insert(name.into(), input);
846        self
847    }
848}
849
850/// Configuration for workflow call input
851#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Setters, Eq)]
852#[setters(strip_option, into)]
853pub struct WorkflowCallInput {
854    /// Description of the input
855    #[serde(skip_serializing_if = "String::is_empty")]
856    pub description: String,
857    /// Indicates if the input is required
858    #[serde(skip_serializing_if = "is_default")]
859    pub required: bool,
860    /// Type of the input
861    #[serde(rename = "type")]
862    pub input_type: String,
863    /// Default value for the input
864    #[serde(skip_serializing_if = "Option::is_none")]
865    pub default: Option<String>,
866}
867
868/// Configuration for workflow call output
869#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Setters, Eq)]
870#[setters(strip_option, into)]
871pub struct WorkflowCallOutput {
872    /// Description of the output
873    #[serde(skip_serializing_if = "String::is_empty")]
874    pub description: String,
875    /// Value of the output
876    #[serde(skip_serializing_if = "String::is_empty")]
877    pub value: String,
878}
879
880/// Configuration for workflow call secret
881#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Setters, Eq)]
882#[setters(strip_option, into)]
883pub struct WorkflowCallSecret {
884    /// Description of the secret
885    #[serde(skip_serializing_if = "String::is_empty")]
886    pub description: String,
887    /// Indicates if the secret is required
888    #[serde(skip_serializing_if = "is_default")]
889    pub required: bool,
890}
891
892/// Configuration for workflow dispatch events
893/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
894
895#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
896#[setters(strip_option, into)]
897pub struct WorkflowDispatch {
898    /// Inputs for the workflow dispatch
899    #[serde(skip_serializing_if = "HashMap::is_empty")]
900    pub inputs: HashMap<String, WorkflowDispatchInput>,
901}
902
903/// Configuration for workflow dispatch input
904#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
905#[setters(strip_option, into)]
906pub struct WorkflowDispatchInput {
907    /// Description of the input
908    #[serde(skip_serializing_if = "String::is_empty")]
909    pub description: String,
910    /// Indicates if the input is required
911    #[serde(skip_serializing_if = "is_default")]
912    pub required: bool,
913    /// Type of the input
914    #[serde(rename = "type")]
915    pub input_type: String,
916    /// Default value for the input
917    #[serde(skip_serializing_if = "Option::is_none")]
918    pub default: Option<String>,
919}
920
921/// Types of workflow run events
922/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
923#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
924#[serde(rename_all = "snake_case")]
925pub enum WorkflowRunType {
926    /// A workflow run was completed
927    Completed,
928    /// A workflow run was requested
929    Requested,
930    /// A workflow run is in progress
931    InProgress,
932}
933
934/// Configuration for workflow run events
935#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
936#[setters(strip_option, into)]
937pub struct WorkflowRun {
938    /// Filter on specific workflow run event types
939    #[serde(default, skip_serializing_if = "Vec::is_empty")]
940    pub types: Vec<WorkflowRunType>,
941    /// Filter on specific workflow names
942    #[serde(default, skip_serializing_if = "Vec::is_empty")]
943    pub workflows: Vec<String>,
944    /// Filter on specific branch names
945    #[serde(default, skip_serializing_if = "Vec::is_empty")]
946    pub branches: Vec<String>,
947}
948
949impl WorkflowRun {
950    /// Adds a workflow run event type to filter on
951    pub fn add_type(mut self, type_: WorkflowRunType) -> Self {
952        self.types.push(type_);
953        self
954    }
955
956    /// Adds a workflow name to filter on
957    pub fn add_workflow<S: Into<String>>(mut self, workflow: S) -> Self {
958        self.workflows.push(workflow.into());
959        self
960    }
961
962    /// Adds a branch name to filter on
963    pub fn add_branch<S: Into<String>>(mut self, branch: S) -> Self {
964        self.branches.push(branch.into());
965        self
966    }
967}