Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions crates/gh-workflow/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ pub enum PullRequestType {
}

#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[setters(strip_option, into)]
pub struct PullRequest {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand All @@ -541,6 +542,9 @@ pub struct PullRequest {
pub branches: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths: Vec<String>,
/// Ignore specific file paths
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths_ignore: Vec<String>,
}

impl PullRequest {
Expand All @@ -554,10 +558,17 @@ impl PullRequest {
self
}

/// Adds a file path to filter on
pub fn add_path<S: Into<String>>(mut self, path: S) -> Self {
self.paths.push(path.into());
self
}

/// Adds a file path to not trigger on
pub fn add_ignored_path<S: Into<String>>(mut self, path: S) -> Self {
self.paths_ignore.push(path.into());
self
}
}

/// Types of pull request review events
Expand Down Expand Up @@ -624,6 +635,7 @@ impl PullRequestReviewComment {
/// Configuration for pull request target events
/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[setters(strip_option, into)]
pub struct PullRequestTarget {
/// Filter on specific pull request event types
Expand All @@ -632,6 +644,11 @@ pub struct PullRequestTarget {
/// Filter on specific branch names
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub branches: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths: Vec<String>,
/// Ignore specific file paths
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths_ignore: Vec<String>,
}

impl PullRequestTarget {
Expand All @@ -646,11 +663,24 @@ impl PullRequestTarget {
self.branches.push(branch.into());
self
}

/// Adds a file path to filter on
pub fn add_path<S: Into<String>>(mut self, path: S) -> Self {
self.paths.push(path.into());
self
}

/// Adds a file path to not trigger on
pub fn add_ignored_path<S: Into<String>>(mut self, path: S) -> Self {
self.paths_ignore.push(path.into());
self
}
}

/// Configuration for push events
/// See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
#[derive(Debug, Clone, Default, Deserialize, Serialize, Setters, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[setters(strip_option, into)]
pub struct Push {
/// Filter on specific branch names
Expand All @@ -659,6 +689,9 @@ pub struct Push {
/// Filter on specific file paths
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths: Vec<String>,
/// Ignore specific file paths
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub paths_ignore: Vec<String>,
/// Filter on specific tags
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<String>,
Expand All @@ -677,6 +710,12 @@ impl Push {
self
}

/// Adds a file path to not trigger on
pub fn add_ignored_path<S: Into<String>>(mut self, path: S) -> Self {
self.paths_ignore.push(path.into());
self
}

/// Adds a tag name to filter on
pub fn add_tag<S: Into<String>>(mut self, tag: S) -> Self {
self.tags.push(tag.into());
Expand Down