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