support cron job name in when clause

This commit is contained in:
Brad Rydzewski 2019-04-13 12:46:39 -07:00
parent 68319d032e
commit ff450c8266
3 changed files with 20 additions and 0 deletions

View File

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.0.8] - 2019-04-13
### Added
- Support Cron job name in When clause, by [@bradrydzewski](https://github.com/bradrydzewski).
## [1.0.7] - 2019-04-10
### Added
- Optionally set the Docker container User, by [@bradrydzewski](https://github.com/bradrydzewski).

View File

@ -20,6 +20,7 @@ import "github.com/drone/drone-yaml/yaml"
// pipeline step should be skipped.
type SkipData struct {
Branch string
Cron string
Event string
Instance string
Ref string
@ -34,6 +35,8 @@ func SkipFunc(data SkipData) func(*yaml.Container) bool {
switch {
case !container.When.Branch.Match(data.Branch):
return true
case !container.When.Cron.Match(data.Cron):
return true
case !container.When.Event.Match(data.Event):
return true
case !container.When.Instance.Match(data.Instance):

View File

@ -30,6 +30,19 @@ func TestSkipFunc(t *testing.T) {
want: true,
},
//
// test cron conditions
//
{
data: SkipData{Cron: "nightly"},
when: yaml.Conditions{Cron: yaml.Condition{Include: []string{"nightly"}}},
want: false,
},
{
data: SkipData{Cron: "nightly"},
when: yaml.Conditions{Cron: yaml.Condition{Exclude: []string{"nightly"}}},
want: true,
},
//
// test event conditions
//
{