diff --git a/models/models.go b/models/models.go index d8c5ce90b..be37a437e 100644 --- a/models/models.go +++ b/models/models.go @@ -30,13 +30,21 @@ type StageListItemModel map[string]StageModel // StageModel ... type StageModel struct { - Title string `json:"title,omitempty" yaml:"title,omitempty"` - Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` - Description string `json:"description,omitempty" yaml:"description,omitempty"` - ShouldAlwaysRun bool `json:"should_always_run,omitempty" yaml:"should_always_run,omitempty"` - AbortOnFail bool `json:"abort_on_fail,omitempty" yaml:"abort_on_fail,omitempty"` - RunIf string `json:"run_if,omitempty" yaml:"run_if,omitempty"` - Workflows []WorkflowListItemModel `json:"workflows,omitempty" yaml:"workflows,omitempty"` + Title string `json:"title,omitempty" yaml:"title,omitempty"` + Summary string `json:"summary,omitempty" yaml:"summary,omitempty"` + Description string `json:"description,omitempty" yaml:"description,omitempty"` + ShouldAlwaysRun bool `json:"should_always_run,omitempty" yaml:"should_always_run,omitempty"` + AbortOnFail bool `json:"abort_on_fail,omitempty" yaml:"abort_on_fail,omitempty"` + RunIf string `json:"run_if,omitempty" yaml:"run_if,omitempty"` + Workflows []StageWorkflowListItemModel `json:"workflows,omitempty" yaml:"workflows,omitempty"` +} + +// StageWorkflowListItemModel ... +type StageWorkflowListItemModel map[string]StageWorkflowModel + +// StageWorkflowModel ... +type StageWorkflowModel struct { + RunIf string `json:"run_if,omitempty" yaml:"run_if,omitempty"` } // WorkflowListItemModel ... diff --git a/models/models_methods.go b/models/models_methods.go index bb7eabd9f..ca3c13f7a 100644 --- a/models/models_methods.go +++ b/models/models_methods.go @@ -281,7 +281,7 @@ func validatePipelines(config *BitriseDataModel) ([]string, error) { } for _, pipelineStage := range pipeline.Stages { - pipelineStageID, err := GetStageIDFromListItemModel(pipelineStage) + pipelineStageID, err := getStageID(pipelineStage) if err != nil { return pipelineWarnings, err } @@ -318,7 +318,7 @@ func validateStages(config *BitriseDataModel) ([]string, error) { for _, stageWorkflow := range stage.Workflows { found := false - stageWorkflowID, err := GetWorkflowIDFromListItemModel(stageWorkflow) + stageWorkflowID, err := getWorkflowID(stageWorkflow) if isUtilityWorkflow(stageWorkflowID) { return stageWarnings, fmt.Errorf("workflow (%s) defined in stage (%s), is a utility workflow", stageWorkflowID, ID) @@ -778,29 +778,27 @@ func MergeStepWith(step, otherStep stepmanModels.StepModel) (stepmanModels.StepM // ---------------------------- // --- WorkflowIDData -// GetWorkflowIDFromListItemModel ... -func GetWorkflowIDFromListItemModel(workflowListItem WorkflowListItemModel) (string, error) { +func getWorkflowID(workflowListItem StageWorkflowListItemModel) (string, error) { if len(workflowListItem) > 1 { - return "", errors.New("WorkflowListItem contains more than 1 key-value pair") + return "", errors.New("StageWorkflowListItemModel contains more than 1 key-value pair") } for key := range workflowListItem { return key, nil } - return "", errors.New("WorkflowListItem does not contain a key-value pair") + return "", errors.New("StageWorkflowListItemModel does not contain a key-value pair") } // ---------------------------- // --- StageIDData -// GetStageIDFromListItemModel ... -func GetStageIDFromListItemModel(stageListItem StageListItemModel) (string, error) { +func getStageID(stageListItem StageListItemModel) (string, error) { if len(stageListItem) > 1 { - return "", errors.New("StageListItem contains more than 1 key-value pair") + return "", errors.New("StageListItemModel contains more than 1 key-value pair") } for key := range stageListItem { return key, nil } - return "", errors.New("StageListItem does not contain a key-value pair") + return "", errors.New("StageListItemModel does not contain a key-value pair") } // ---------------------------- diff --git a/models/models_methods_test.go b/models/models_methods_test.go index d124af2e2..4b7401b6d 100644 --- a/models/models_methods_test.go +++ b/models/models_methods_test.go @@ -38,27 +38,27 @@ func TestValidateConfig(t *testing.T) { }, Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow1": WorkflowModel{}}, - WorkflowListItemModel{"workflow2": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow1": StageWorkflowModel{}}, + StageWorkflowListItemModel{"workflow2": StageWorkflowModel{}}, }, }, "stage2": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow3": WorkflowModel{}}, - WorkflowListItemModel{"workflow4": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow3": StageWorkflowModel{}}, + StageWorkflowListItemModel{"workflow4": StageWorkflowModel{}}, }, }, "stage3": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow5": WorkflowModel{}}, - WorkflowListItemModel{"workflow6": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow5": StageWorkflowModel{}}, + StageWorkflowListItemModel{"workflow6": StageWorkflowModel{}}, }, }, "stage4": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow7": WorkflowModel{}}, - WorkflowListItemModel{"workflow8": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow7": StageWorkflowModel{}}, + StageWorkflowListItemModel{"workflow8": StageWorkflowModel{}}, }, }, }, @@ -105,8 +105,8 @@ func TestValidateConfig(t *testing.T) { }, Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow1": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow1": StageWorkflowModel{}}, }, }, }, @@ -163,8 +163,8 @@ func TestValidateConfig(t *testing.T) { }, Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow1": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow1": StageWorkflowModel{}}, }, }, }, @@ -197,8 +197,8 @@ func TestValidateConfig(t *testing.T) { FormatVersion: "1.4.0", Stages: map[string]StageModel{ "st/id": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow1": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow1": StageWorkflowModel{}}, }, }, }, @@ -218,7 +218,7 @@ func TestValidateConfig(t *testing.T) { FormatVersion: "1.4.0", Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{}, + Workflows: []StageWorkflowListItemModel{}, }, }, } @@ -248,8 +248,8 @@ func TestValidateConfig(t *testing.T) { FormatVersion: "1.4.0", Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"workflow2": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"workflow2": StageWorkflowModel{}}, }, }, }, @@ -269,8 +269,8 @@ func TestValidateConfig(t *testing.T) { FormatVersion: "12", Stages: map[string]StageModel{ "stage1": StageModel{ - Workflows: []WorkflowListItemModel{ - WorkflowListItemModel{"_utility_workflow": WorkflowModel{}}, + Workflows: []StageWorkflowListItemModel{ + StageWorkflowListItemModel{"_utility_workflow": StageWorkflowModel{}}, }, }, }, @@ -634,36 +634,36 @@ func TestGetInputByKey(t *testing.T) { // --- WorkflowIDData func TestGetWorkflowIDFromListItemModel(t *testing.T) { - workflowData := WorkflowModel{} + workflowData := StageWorkflowModel{} t.Log("valid workflowlist item") { - workflowListItem := WorkflowListItemModel{ + workflowListItem := StageWorkflowListItemModel{ "workflow1": workflowData, } - id, err := GetWorkflowIDFromListItemModel(workflowListItem) + id, err := getWorkflowID(workflowListItem) require.NoError(t, err) require.Equal(t, "workflow1", id) } t.Log("invalid workflowlist item - more than 1 workflow") { - workflowListItem := WorkflowListItemModel{ + workflowListItem := StageWorkflowListItemModel{ "workflow1": workflowData, "workflow2": workflowData, } - id, err := GetWorkflowIDFromListItemModel(workflowListItem) + id, err := getWorkflowID(workflowListItem) require.Error(t, err) require.Equal(t, "", id) } t.Log("invalid workflowlist item - no workflow") { - workflowListItem := WorkflowListItemModel{} + workflowListItem := StageWorkflowListItemModel{} - id, err := GetWorkflowIDFromListItemModel(workflowListItem) + id, err := getWorkflowID(workflowListItem) require.Error(t, err) require.Equal(t, "", id) } @@ -681,7 +681,7 @@ func TestGetStageIDFromListItemModel(t *testing.T) { "stage1": stageData, } - id, err := GetStageIDFromListItemModel(stageListItem) + id, err := getStageID(stageListItem) require.NoError(t, err) require.Equal(t, "stage1", id) } @@ -693,7 +693,7 @@ func TestGetStageIDFromListItemModel(t *testing.T) { "stage2": stageData, } - id, err := GetStageIDFromListItemModel(stageListItem) + id, err := getStageID(stageListItem) require.Error(t, err) require.Equal(t, "", id) } @@ -702,7 +702,7 @@ func TestGetStageIDFromListItemModel(t *testing.T) { { stageListItem := StageListItemModel{} - id, err := GetStageIDFromListItemModel(stageListItem) + id, err := getStageID(stageListItem) require.Error(t, err) require.Equal(t, "", id) }