-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry picked refactor apply requirements from upstream (#93)
- Loading branch information
Showing
6 changed files
with
248 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
"github.com/runatlantis/atlantis/server/events/runtime" | ||
"github.com/runatlantis/atlantis/server/events/yaml/raw" | ||
"github.com/runatlantis/atlantis/server/events/yaml/valid" | ||
) | ||
|
||
//go:generate pegomock generate -m --package mocks -o mocks/mock_apply_handler.go ApplyRequirement | ||
type ApplyRequirement interface { | ||
ValidateProject(repoDir string, ctx models.ProjectCommandContext) (string, error) | ||
} | ||
|
||
type AggregateApplyRequirements struct { | ||
PullApprovedChecker runtime.PullApprovedChecker | ||
WorkingDir WorkingDir | ||
} | ||
|
||
func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx models.ProjectCommandContext) (failure string, err error) { | ||
|
||
for _, req := range ctx.ApplyRequirements { | ||
switch req { | ||
case raw.ApprovedApplyRequirement: | ||
approved, err := a.PullApprovedChecker.PullIsApproved(ctx.Pull.BaseRepo, ctx.Pull) // nolint: vetshadow | ||
if err != nil { | ||
return "", errors.Wrap(err, "checking if pull request was approved") | ||
} | ||
if !approved { | ||
return "Pull request must be approved by at least one person other than the author before running apply.", nil | ||
} | ||
// this should come before mergeability check since mergeability is a superset of this check. | ||
case valid.PoliciesPassedApplyReq: | ||
if ctx.ProjectPlanStatus == models.ErroredPolicyCheckStatus { | ||
return "All policies must pass for project before running apply", nil | ||
} | ||
case raw.MergeableApplyRequirement: | ||
if !ctx.PullMergeable { | ||
return "Pull request must be mergeable before running apply.", nil | ||
} | ||
case raw.UnDivergedApplyRequirement: | ||
if a.WorkingDir.HasDiverged(ctx.Log, repoDir) { | ||
return "Default branch must be rebased onto pull request before running apply.", nil | ||
} | ||
} | ||
} | ||
// Passed all apply requirements configured. | ||
return "", nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.