Skip to content

Commit

Permalink
[CI-3776] Reenable run_if (#1017)
Browse files Browse the repository at this point in the history
* Reenable pipeline run_if

* Add custom json unmarshal
  • Loading branch information
tothszabi authored Nov 11, 2024
1 parent dc69014 commit 5be4943
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions models/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"encoding/json"
"fmt"
"slices"
"strings"
Expand Down Expand Up @@ -77,9 +78,9 @@ type StageWorkflowModel struct {
type GraphPipelineWorkflowListItemModel map[string]GraphPipelineWorkflowModel

type GraphPipelineWorkflowModel struct {
DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
AbortOnFail bool `json:"abort_on_fail,omitempty" yaml:"abort_on_fail,omitempty"`
//RunIf GraphPipelineRunIfModel `json:"run_if,omitempty" yaml:"run_if,omitempty"`
DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
AbortOnFail bool `json:"abort_on_fail,omitempty" yaml:"abort_on_fail,omitempty"`
RunIf GraphPipelineRunIfModel `json:"run_if,omitempty" yaml:"run_if,omitempty"`
ShouldAlwaysRun GraphPipelineAlwaysRunMode `json:"should_always_run,omitempty" yaml:"should_always_run,omitempty"`
}

Expand All @@ -93,13 +94,36 @@ func (d *GraphPipelineAlwaysRunMode) UnmarshalYAML(unmarshal func(interface{}) e
return err
}

if err := validateGraphPipelineAlwaysRunMode(value); err != nil {
return err
}

*d = GraphPipelineAlwaysRunMode(value)

return nil
}

func (d *GraphPipelineAlwaysRunMode) UnmarshalJSON(data []byte) error {
var value string
if err := json.Unmarshal(data, &value); err != nil {
return err
}

if err := validateGraphPipelineAlwaysRunMode(value); err != nil {
return err
}

*d = GraphPipelineAlwaysRunMode(value)

return nil
}

func validateGraphPipelineAlwaysRunMode(value string) error {
allowedValues := []string{string(GraphPipelineAlwaysRunModeOff), string(GraphPipelineAlwaysRunModeWorkflow)}
if !slices.Contains(allowedValues, value) {
return fmt.Errorf("%s is not a valid should_always_run value (%s)", value, allowedValues)
}

*d = GraphPipelineAlwaysRunMode(value)

return nil
}

Expand Down

0 comments on commit 5be4943

Please sign in to comment.