forked from runatlantis/atlantis
/
repo_cfg.go
91 lines (80 loc) · 1.99 KB
/
repo_cfg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Package valid contains the structs representing the atlantis.yaml config
// after it's been parsed and validated.
package valid
import version "github.com/hashicorp/go-version"
// RepoCfg is the atlantis.yaml config after it's been parsed and validated.
type RepoCfg struct {
// Version is the version of the atlantis YAML file.
Version int
Projects []Project
Workflows map[string]Workflow
Automerge bool
}
func (r RepoCfg) FindProjectsByDirWorkspace(repoRelDir string, workspace string) []Project {
var ps []Project
for _, p := range r.Projects {
if p.Dir == repoRelDir && p.Workspace == workspace {
ps = append(ps, p)
}
}
return ps
}
// FindProjectsByDir returns all projects that are in dir.
func (r RepoCfg) FindProjectsByDir(dir string) []Project {
var ps []Project
for _, p := range r.Projects {
if p.Dir == dir {
ps = append(ps, p)
}
}
return ps
}
func (r RepoCfg) FindProjectByName(name string) *Project {
for _, p := range r.Projects {
if p.Name != nil && *p.Name == name {
return &p
}
}
return nil
}
type Project struct {
Dir string
Workspace string
Name *string
WorkflowName *string
TerraformVersion *version.Version
Autoplan Autoplan
ApplyRequirements []string
}
// GetName returns the name of the project or an empty string if there is no
// project name.
func (p Project) GetName() string {
if p.Name != nil {
return *p.Name
}
return ""
}
type Autoplan struct {
WhenModified []string
Enabled bool
}
type Stage struct {
Steps []Step
}
type Step struct {
StepName string
ExtraArgs []string
// RunCommand is either a custom run step or the command to run
// during an env step to populate the environment variable dynamically.
RunCommand string
// EnvVarName is the name of the
// environment variable that should be set by this step.
EnvVarName string
// EnvVarValue is the value to set EnvVarName to.
EnvVarValue string
}
type Workflow struct {
Name string
Apply Stage
Plan Stage
}