From 6465b918459377f677e9234863d08217275bf3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krisztia=CC=81n=20Go=CC=88drei?= Date: Mon, 30 Sep 2024 09:24:12 +0200 Subject: [PATCH] Add enabled field to the target based triggers model --- models/selective_triggers.go | 11 +++++++++-- models/selective_triggers_test.go | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) 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 {