Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Medeiros committed Oct 13, 2023
1 parent fd88dec commit c729c2f
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 141 deletions.
1 change: 1 addition & 0 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
false,
false,
false,
valid.Autodiscover{Enabled: true},
false,
false,
"",
Expand Down
46 changes: 23 additions & 23 deletions server/core/config/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ workflows:
StateRm: valid.DefaultStateRmStage,
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},

Expand All @@ -194,7 +194,7 @@ projects:`,
Version: 3,
Projects: nil,
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -227,7 +227,7 @@ projects:
},
},
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -250,7 +250,7 @@ projects:
},
},
Workflows: make(map[string]valid.Workflow),
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -275,7 +275,7 @@ projects:
},
},
Workflows: make(map[string]valid.Workflow),
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -285,7 +285,7 @@ version: 3
`,
exp: valid.RepoCfg{
Version: 3,
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
Workflows: make(map[string]valid.Workflow),
},
},
Expand All @@ -298,7 +298,7 @@ autodiscover:
`,
exp: valid.RepoCfg{
Version: 3,
Autodiscover: valid.Autodiscover{Enabled: false},
Autodiscover: &valid.Autodiscover{Enabled: false},
Workflows: make(map[string]valid.Workflow),
},
},
Expand All @@ -322,7 +322,7 @@ projects:
},
},
Workflows: make(map[string]valid.Workflow),
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -346,7 +346,7 @@ workflows: ~
},
},
Workflows: make(map[string]valid.Workflow),
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -377,7 +377,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"default": defaultWorkflow("default"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -410,7 +410,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -445,7 +445,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -480,7 +480,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -515,7 +515,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -550,7 +550,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -585,7 +585,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -620,7 +620,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -655,7 +655,7 @@ workflows:
Workflows: map[string]valid.Workflow{
"myworkflow": defaultWorkflow("myworkflow"),
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -772,7 +772,7 @@ projects:
},
},
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -863,7 +863,7 @@ workflows:
},
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -967,7 +967,7 @@ workflows:
},
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -1051,7 +1051,7 @@ workflows:
},
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -1150,7 +1150,7 @@ workflows:
},
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
}
Expand Down
43 changes: 8 additions & 35 deletions server/core/config/raw/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ import (
"github.com/runatlantis/atlantis/server/core/config/valid"
)

// DefaultAutomerge is the default setting for automerge.
const DefaultAutomerge = false

// DefaultAutodiscover is the default setting for autodiscover.
const DefaultAutodiscover = true

// DefaultParallelApply is the default setting for parallel apply
const DefaultParallelApply = false

// DefaultParallelPlan is the default setting for parallel plan
const DefaultParallelPlan = false

// DefaultParallelPolicyCheck is the default setting for parallel plan
const DefaultParallelPolicyCheck = false

// DefaultDeleteSourceBranchOnMerge being false is the default setting whether or not to remove a source branch on merge
const DefaultDeleteSourceBranchOnMerge = false

// DefaultEmojiReaction is the default emoji reaction for repos
const DefaultEmojiReaction = ""

Expand Down Expand Up @@ -76,27 +58,18 @@ func (r RepoCfg) ToValid() valid.RepoCfg {
validProjects = append(validProjects, p.ToValid())
}

automerge := DefaultAutomerge
if r.Automerge != nil {
automerge = *r.Automerge
}

var autodiscover valid.Autodiscover
var autodiscover *valid.Autodiscover
if r.Autodiscover == nil {
autodiscover = DefaultAutoDiscover()
defaultAutoDiscover := DefaultAutoDiscover()
autodiscover = &defaultAutoDiscover
} else {
autodiscover = r.Autodiscover.ToValid()
validAutoDiscover := r.Autodiscover.ToValid()
autodiscover = &validAutoDiscover
}

parallelApply := DefaultParallelApply
if r.ParallelApply != nil {
parallelApply = *r.ParallelApply
}

parallelPlan := DefaultParallelPlan
if r.ParallelPlan != nil {
parallelPlan = *r.ParallelPlan
}
automerge := r.Automerge
parallelApply := r.ParallelApply
parallelPlan := r.ParallelPlan

emojiReaction := DefaultEmojiReaction
if r.EmojiReaction != nil {
Expand Down
20 changes: 10 additions & 10 deletions server/core/config/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestConfig_ToValid(t *testing.T) {
exp: valid.RepoCfg{
Version: 2,
Workflows: make(map[string]valid.Workflow),
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -263,7 +263,7 @@ func TestConfig_ToValid(t *testing.T) {
Version: 2,
Workflows: map[string]valid.Workflow{},
Projects: nil,
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -277,7 +277,7 @@ func TestConfig_ToValid(t *testing.T) {
ParallelApply: nil,
AbortOnExcecutionOrderFail: false,
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -294,7 +294,7 @@ func TestConfig_ToValid(t *testing.T) {
ParallelApply: Bool(true),
AbortOnExcecutionOrderFail: true,
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -311,7 +311,7 @@ func TestConfig_ToValid(t *testing.T) {
ParallelApply: Bool(false),
AbortOnExcecutionOrderFail: false,
Workflows: map[string]valid.Workflow{},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand All @@ -322,7 +322,7 @@ func TestConfig_ToValid(t *testing.T) {
},
exp: valid.RepoCfg{
Version: 2,
Autodiscover: valid.Autodiscover{Enabled: false},
Autodiscover: &valid.Autodiscover{Enabled: false},
Workflows: map[string]valid.Workflow{},
},
},
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestConfig_ToValid(t *testing.T) {
StateRm: valid.DefaultStateRmStage,
},
},
Autodiscover: valid.Autodiscover{Enabled: true},
Autodiscover: &valid.Autodiscover{Enabled: true},
},
},
{
Expand Down Expand Up @@ -411,9 +411,9 @@ func TestConfig_ToValid(t *testing.T) {
},
exp: valid.RepoCfg{
Version: 2,
Automerge: true,
Autodiscover: valid.Autodiscover{Enabled: true},
ParallelApply: true,
Automerge: Bool(true),
Autodiscover: &valid.Autodiscover{Enabled: true},
ParallelApply: Bool(true),
Workflows: map[string]valid.Workflow{
"myworkflow": {
Name: "myworkflow",
Expand Down
11 changes: 6 additions & 5 deletions server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type RepoCfg struct {
Projects []Project
Workflows map[string]Workflow
PolicySets PolicySets
Automerge bool
Autodiscover Autodiscover
ParallelApply bool
ParallelPlan bool
ParallelPolicyCheck bool
Automerge *bool
Autodiscover *Autodiscover
ParallelApply *bool
ParallelPlan *bool
ParallelPolicyCheck *bool
DeleteSourceBranchOnMerge *bool
RepoLocking *bool
CustomPolicyCheck *bool
Expand Down Expand Up @@ -130,6 +130,7 @@ type Project struct {
WorkflowName *string
TerraformVersion *version.Version
Autoplan Autoplan
Autodiscover Autodiscover
PlanRequirements []string
ApplyRequirements []string
ImportRequirements []string
Expand Down
Loading

0 comments on commit c729c2f

Please sign in to comment.