1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-07-12 22:21:40 +02:00

Add default event filter (#1140)

breakout from #934

when new events are added you don't have to worry that pipeline will behave different as it does now with this

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
6543
2022-08-30 00:36:37 +02:00
committed by GitHub
parent 7e18e69563
commit ca84f703e3
6 changed files with 101 additions and 65 deletions

View File

@ -63,7 +63,13 @@ func (when *When) Match(metadata frontend.Metadata) bool {
return true
}
}
return when.IsEmpty()
if when.IsEmpty() {
// test against default Constraints
empty := &Constraint{}
return empty.Match(metadata)
}
return false
}
func (when *When) IncludesStatus(status string) bool {
@ -120,6 +126,16 @@ func (when *When) UnmarshalYAML(value *yaml.Node) error {
// Match returns true if all constraints match the given input. If a single
// constraint fails a false value is returned.
func (c *Constraint) Match(metadata frontend.Metadata) bool {
// if event filter is not set, set default
if c.Event.IsEmpty() {
c.Event.Include = []string{
frontend.EventPush,
frontend.EventPull,
frontend.EventTag,
frontend.EventDeploy,
}
}
match := c.Platform.Match(metadata.Sys.Platform) &&
c.Environment.Match(metadata.Curr.Target) &&
c.Event.Match(metadata.Curr.Event) &&
@ -140,6 +156,11 @@ func (c *Constraint) Match(metadata frontend.Metadata) bool {
return match
}
// IsEmpty return true if a constraint has no conditions
func (c List) IsEmpty() bool {
return len(c.Include) == 0 && len(c.Exclude) == 0
}
// Match returns true if the string matches the include patterns and does not
// match any of the exclude patterns.
func (c *List) Match(v string) bool {