-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathproject_result.go
87 lines (79 loc) · 2.49 KB
/
project_result.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
package command
import (
"github.com/runatlantis/atlantis/server/events/models"
)
// ProjectResult is the result of executing a plan/policy_check/apply for a specific project.
type ProjectResult struct {
Command Name
SubCommand string
RepoRelDir string
Workspace string
Error error
Failure string
PlanSuccess *models.PlanSuccess
PolicyCheckResults *models.PolicyCheckResults
ApplySuccess string
VersionSuccess string
ImportSuccess *models.ImportSuccess
StateRmSuccess *models.StateRmSuccess
ProjectName string
SilencePRComments []string
}
// CommitStatus returns the vcs commit status of this project result.
func (p ProjectResult) CommitStatus() models.CommitStatus {
if p.Error != nil {
return models.FailedCommitStatus
}
if p.Failure != "" {
return models.FailedCommitStatus
}
return models.SuccessCommitStatus
}
// PolicyStatus returns the approval status of policy sets of this project result.
func (p ProjectResult) PolicyStatus() []models.PolicySetStatus {
var policyStatuses []models.PolicySetStatus
if p.PolicyCheckResults != nil {
for _, policySet := range p.PolicyCheckResults.PolicySetResults {
policyStatus := models.PolicySetStatus{
PolicySetName: policySet.PolicySetName,
Passed: policySet.Passed,
Approvals: policySet.CurApprovals,
}
policyStatuses = append(policyStatuses, policyStatus)
}
}
return policyStatuses
}
// PlanStatus returns the plan status.
func (p ProjectResult) PlanStatus() models.ProjectPlanStatus {
switch p.Command {
case Plan:
if p.Error != nil {
return models.ErroredPlanStatus
} else if p.Failure != "" {
return models.ErroredPlanStatus
} else if p.PlanSuccess.NoChanges() {
return models.PlannedNoChangesPlanStatus
}
return models.PlannedPlanStatus
case PolicyCheck, ApprovePolicies:
if p.Error != nil {
return models.ErroredPolicyCheckStatus
} else if p.Failure != "" {
return models.ErroredPolicyCheckStatus
}
return models.PassedPolicyCheckStatus
case Apply:
if p.Error != nil {
return models.ErroredApplyStatus
} else if p.Failure != "" {
return models.ErroredApplyStatus
}
return models.AppliedPlanStatus
}
panic("PlanStatus() missing a combination")
}
// IsSuccessful returns true if this project result had no errors.
func (p ProjectResult) IsSuccessful() bool {
return p.PlanSuccess != nil || (p.PolicyCheckResults != nil && p.Error == nil && p.Failure == "") || p.ApplySuccess != ""
}