Merge pull request #862 from runatlantis/fix-default

Fix bug when redefining default workflow
This commit is contained in:
Luke Kysow
2019-11-26 16:45:32 -08:00
committed by GitHub
2 changed files with 60 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ import (
"strings"
"testing"
version "github.com/hashicorp/go-version"
"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/yaml"
"github.com/runatlantis/atlantis/server/events/yaml/valid"
. "github.com/runatlantis/atlantis/testing"
@@ -1076,6 +1076,57 @@ repos:
},
},
},
"redefine default workflow": {
input: `
workflows:
default:
plan:
steps:
- run: custom
apply:
steps: []
`,
exp: valid.GlobalCfg{
Repos: []valid.Repo{
{
IDRegex: regexp.MustCompile(".*"),
ApplyRequirements: []string{},
Workflow: &valid.Workflow{
Name: "default",
Apply: valid.Stage{
Steps: nil,
},
Plan: valid.Stage{
Steps: []valid.Step{
{
StepName: "run",
RunCommand: "custom",
},
},
},
},
AllowedOverrides: []string{},
AllowCustomWorkflows: Bool(false),
},
},
Workflows: map[string]valid.Workflow{
"default": {
Name: "default",
Apply: valid.Stage{
Steps: nil,
},
Plan: valid.Stage{
Steps: []valid.Step{
{
StepName: "run",
RunCommand: "custom",
},
},
},
},
},
},
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {

View File

@@ -60,7 +60,14 @@ func (g GlobalCfg) Validate() error {
func (g GlobalCfg) ToValid(defaultCfg valid.GlobalCfg) valid.GlobalCfg {
workflows := make(map[string]valid.Workflow)
for k, v := range g.Workflows {
workflows[k] = v.ToValid(k)
validatedWorkflow := v.ToValid(k)
workflows[k] = validatedWorkflow
if k == valid.DefaultWorkflowName {
// Handle the special case where they're redefining the default
// workflow. In this case, our default repo config references
// the "old" default workflow and so needs to be redefined.
defaultCfg.Repos[0].Workflow = &validatedWorkflow
}
}
// Merge in defaults without overriding.
for k, v := range defaultCfg.Workflows {