Skip to content

Commit

Permalink
Add enabled field to the target based triggers model (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
godrei authored Sep 30, 2024
1 parent 6f15bd1 commit 968341c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions models/selective_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions models/selective_triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 968341c

Please sign in to comment.