Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enabled field to the target based triggers model #1003

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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