Skip to content

Commit 4952275

Browse files
authored
fix: make event.schedule as vector (#170)
* fix: support vec for schedule type * feat: add method to append schedules to Event struct * feat: add cron schedule
1 parent 3810f4b commit 4952275

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/gh-workflow/src/event.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct Event {
6666
#[serde(skip_serializing_if = "Option::is_none")]
6767
pub repository_dispatch: Option<RepositoryDispatch>,
6868
#[serde(skip_serializing_if = "Option::is_none")]
69-
pub schedule: Option<Schedule>,
69+
pub schedule: Option<Vec<Schedule>>,
7070
#[serde(skip_serializing_if = "Option::is_none")]
7171
pub status: Option<bool>,
7272
#[serde(skip_serializing_if = "Option::is_none")]
@@ -79,6 +79,22 @@ pub struct Event {
7979
pub workflow_run: Option<WorkflowRun>,
8080
}
8181

82+
impl 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+
8298
/// Types of branch protection rule events
8399
/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#branch_protection_rule
84100
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -753,14 +769,12 @@ impl RepositoryDispatch {
753769
#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
754770
#[setters(strip_option, into)]
755771
pub struct Schedule {
756-
#[serde(default, skip_serializing_if = "Vec::is_empty")]
757-
pub cron: Vec<String>,
772+
pub cron: String,
758773
}
759774

760775
impl Schedule {
761-
pub fn add_cron<S: Into<String>>(mut self, cron: S) -> Self {
762-
self.cron.push(cron.into());
763-
self
776+
pub fn new(cron: impl ToString) -> Self {
777+
Self { cron: cron.to_string() }
764778
}
765779
}
766780

0 commit comments

Comments
 (0)