diff --git a/models/selective_triggers.go b/models/selective_triggers.go index 3334fe29..366d00d6 100644 --- a/models/selective_triggers.go +++ b/models/selective_triggers.go @@ -10,6 +10,7 @@ import ( ) type Triggers struct { + Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"` PushTriggers []PushGitEventTriggerItem `json:"push,omitempty" yaml:"push,omitempty"` PullRequestTriggers []PullRequestGitEventTriggerItem `json:"pull_request,omitempty" yaml:"pull_request,omitempty"` TagTriggers []TagGitEventTriggerItem `json:"tag,omitempty" yaml:"tag,omitempty"` @@ -59,13 +60,19 @@ func (tagItem TagGitEventTriggerItem) toString() string { func (triggers *Triggers) UnmarshalYAML(unmarshal func(interface{}) error) error { var triggersConfig map[string]any if err := unmarshal(&triggersConfig); err != nil { - return fmt.Errorf("'triggers': should be a map with 'push', 'pull_request' and 'tag' keys") + return fmt.Errorf("'triggers': should be a map with 'enabled', 'push', 'pull_request' and 'tag' keys") } - if err := ensureKeys(triggersConfig, "push", "pull_request", "tag"); err != nil { + if err := ensureKeys(triggersConfig, "enabled", "push", "pull_request", "tag"); err != nil { return fmt.Errorf("'triggers': %w", err) } + enabled, err := boolPtrValue(triggersConfig, "enabled") + if err != nil { + return fmt.Errorf("'triggers': %w", err) + } + triggers.Enabled = enabled + if pushTriggersRaw, ok := triggersConfig["push"]; ok { pushTriggers, err := parsePushTriggers(pushTriggersRaw) if err != nil { diff --git a/models/selective_triggers_test.go b/models/selective_triggers_test.go index 3ef1ed9a..7f6742f8 100644 --- a/models/selective_triggers_test.go +++ b/models/selective_triggers_test.go @@ -162,7 +162,7 @@ func TestYAMLUnmarshalTriggers_Validation_Push(t *testing.T) { - pull_request_source_branch: "*" workflow: primary - tag: "*.*.*"`, - wantErr: "'triggers': should be a map with 'push', 'pull_request' and 'tag' keys", + wantErr: "'triggers': should be a map with 'enabled', 'push', 'pull_request' and 'tag' keys", }, { name: "Throws error when 'triggers' has unknown keys", @@ -404,11 +404,13 @@ default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git" workflows: test: triggers: + enabled: false push: - branch: regex: branch pull_request: - - source_branch: source_branch`, + - source_branch: source_branch + enabled: false`, }, } for _, tt := range tests {