mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 21:48:25 +00:00
Add godocs. Refactor ProjectResult. Golint errors.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
// Package cmd provides all CLI commands.
|
||||
// NOTE: These are different from the commands that get run via pull request
|
||||
// comments.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@@ -67,8 +67,8 @@ const (
|
||||
DefaultPort = 4141
|
||||
)
|
||||
|
||||
const RedTermStart = "\033[31m"
|
||||
const RedTermEnd = "\033[39m"
|
||||
const redTermStart = "\033[31m"
|
||||
const redTermEnd = "\033[39m"
|
||||
|
||||
var stringFlags = []stringFlag{
|
||||
{
|
||||
@@ -458,16 +458,16 @@ func (s *ServerCmd) trimAtSymbolFromUsers(userConfig *server.UserConfig) {
|
||||
|
||||
func (s *ServerCmd) securityWarnings(userConfig *server.UserConfig) {
|
||||
if userConfig.GithubUser != "" && userConfig.GithubWebhookSecret == "" && !s.SilenceOutput {
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No GitHub webhook secret set. This could allow attackers to spoof requests from GitHub.%s\n", RedTermStart, RedTermEnd)
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No GitHub webhook secret set. This could allow attackers to spoof requests from GitHub.%s\n", redTermStart, redTermEnd)
|
||||
}
|
||||
if userConfig.GitlabUser != "" && userConfig.GitlabWebhookSecret == "" && !s.SilenceOutput {
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No GitLab webhook secret set. This could allow attackers to spoof requests from GitLab.%s\n", RedTermStart, RedTermEnd)
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No GitLab webhook secret set. This could allow attackers to spoof requests from GitLab.%s\n", redTermStart, redTermEnd)
|
||||
}
|
||||
if userConfig.BitbucketUser != "" && userConfig.BitbucketBaseURL != DefaultBitbucketBaseURL && userConfig.BitbucketWebhookSecret == "" && !s.SilenceOutput {
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No Bitbucket webhook secret set. This could allow attackers to spoof requests from Bitbucket.%s\n", RedTermStart, RedTermEnd)
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] No Bitbucket webhook secret set. This could allow attackers to spoof requests from Bitbucket.%s\n", redTermStart, redTermEnd)
|
||||
}
|
||||
if userConfig.BitbucketUser != "" && userConfig.BitbucketBaseURL == DefaultBitbucketBaseURL && !s.SilenceOutput {
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] Bitbucket Cloud does not support webhook secrets. This could allow attackers to spoof requests from Bitbucket. Ensure you are whitelisting Bitbucket IPs.%s\n", RedTermStart, RedTermEnd)
|
||||
fmt.Fprintf(os.Stderr, "%s[WARN] Bitbucket Cloud does not support webhook secrets. This could allow attackers to spoof requests from Bitbucket. Ensure you are whitelisting Bitbucket IPs.%s\n", redTermStart, redTermEnd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ func (s *ServerCmd) withErrPrint(f func(*cobra.Command, []string) error) func(*c
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
err := f(cmd, args)
|
||||
if err != nil && !s.SilenceOutput {
|
||||
fmt.Fprintf(os.Stderr, "%s[ERROR] %s%s\n\n", RedTermStart, err.Error(), RedTermEnd)
|
||||
fmt.Fprintf(os.Stderr, "%s[ERROR] %s%s\n\n", redTermStart, err.Error(), redTermEnd)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package cmd_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
// CommandResult is the result of running a Command.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -71,6 +71,7 @@ type DefaultCommandRunner struct {
|
||||
ProjectCommandRunner ProjectCommandRunner
|
||||
}
|
||||
|
||||
// RunAutoplanCommand runs plan when a pull request is opened or updated.
|
||||
func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo models.Repo, pull models.PullRequest, user models.User) {
|
||||
log := c.buildLogger(baseRepo.FullName, pull.Num)
|
||||
ctx := &CommandContext{
|
||||
@@ -126,11 +127,11 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead
|
||||
pull, err = c.getGitlabData(baseRepo, pullNum)
|
||||
case models.BitbucketCloud, models.BitbucketServer:
|
||||
if maybePull == nil {
|
||||
err = errors.New("pull request should not be nil, this is a bug!")
|
||||
err = errors.New("pull request should not be nil–this is a bug")
|
||||
}
|
||||
pull = *maybePull
|
||||
default:
|
||||
err = errors.New("Unknown VCS type, this is a bug!")
|
||||
err = errors.New("Unknown VCS type–this is a bug")
|
||||
}
|
||||
if err != nil {
|
||||
log.Err(err.Error())
|
||||
@@ -239,7 +240,7 @@ func (c *DefaultCommandRunner) validateCtxAndComment(ctx *CommandContext) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *DefaultCommandRunner) updatePull(ctx *CommandContext, command CommandInterface, res CommandResult) {
|
||||
func (c *DefaultCommandRunner) updatePull(ctx *CommandContext, command PullCommand, res CommandResult) {
|
||||
// Log if we got any errors or failures.
|
||||
if res.Error != nil {
|
||||
ctx.Log.Err(res.Error.Error())
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,14 +10,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
// CommandName is the type of command.
|
||||
// CommandName is which command to run.
|
||||
type CommandName int
|
||||
|
||||
const (
|
||||
// ApplyCommand is a command to run terraform apply.
|
||||
ApplyCommand CommandName = iota
|
||||
// PlanCommand is a command to run terraform plan.
|
||||
PlanCommand
|
||||
// Adding more? Don't forget to update String() below
|
||||
)
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -27,15 +27,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
WorkspaceFlagLong = "workspace"
|
||||
WorkspaceFlagShort = "w"
|
||||
DirFlagLong = "dir"
|
||||
DirFlagShort = "d"
|
||||
ProjectFlagLong = "project"
|
||||
ProjectFlagShort = "p"
|
||||
VerboseFlagLong = "verbose"
|
||||
VerboseFlagShort = ""
|
||||
AtlantisExecutable = "atlantis"
|
||||
workspaceFlagLong = "workspace"
|
||||
workspaceFlagShort = "w"
|
||||
dirFlagLong = "dir"
|
||||
dirFlagShort = "d"
|
||||
projectFlagLong = "project"
|
||||
projectFlagShort = "p"
|
||||
verboseFlagLong = "verbose"
|
||||
verboseFlagShort = ""
|
||||
atlantisExecutable = "atlantis"
|
||||
)
|
||||
|
||||
// multiLineRegex is used to ignore multi-line comments since those aren't valid
|
||||
@@ -121,7 +121,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen
|
||||
if vcsHost == models.Gitlab {
|
||||
vcsUser = e.GitlabUser
|
||||
}
|
||||
executableNames := []string{"run", AtlantisExecutable, "@" + vcsUser}
|
||||
executableNames := []string{"run", atlantisExecutable, "@" + vcsUser}
|
||||
|
||||
// If the comment doesn't start with the name of our 'executable' then
|
||||
// ignore it.
|
||||
@@ -160,18 +160,18 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen
|
||||
name = PlanCommand
|
||||
flagSet = pflag.NewFlagSet(PlanCommand.String(), pflag.ContinueOnError)
|
||||
flagSet.SetOutput(ioutil.Discard)
|
||||
flagSet.StringVarP(&workspace, WorkspaceFlagLong, WorkspaceFlagShort, "", "Switch to this Terraform workspace before planning.")
|
||||
flagSet.StringVarP(&dir, DirFlagLong, DirFlagShort, "", "Which directory to run plan in relative to root of repo, ex. 'child/dir'.")
|
||||
flagSet.StringVarP(&project, ProjectFlagLong, ProjectFlagShort, "", fmt.Sprintf("Which project to run plan for. Refers to the name of the project configured in %s. Cannot be used at same time as workspace or dir flags.", yaml.AtlantisYAMLFilename))
|
||||
flagSet.BoolVarP(&verbose, VerboseFlagLong, VerboseFlagShort, false, "Append Atlantis log to comment.")
|
||||
flagSet.StringVarP(&workspace, workspaceFlagLong, workspaceFlagShort, "", "Switch to this Terraform workspace before planning.")
|
||||
flagSet.StringVarP(&dir, dirFlagLong, dirFlagShort, "", "Which directory to run plan in relative to root of repo, ex. 'child/dir'.")
|
||||
flagSet.StringVarP(&project, projectFlagLong, projectFlagShort, "", fmt.Sprintf("Which project to run plan for. Refers to the name of the project configured in %s. Cannot be used at same time as workspace or dir flags.", yaml.AtlantisYAMLFilename))
|
||||
flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.")
|
||||
case ApplyCommand.String():
|
||||
name = ApplyCommand
|
||||
flagSet = pflag.NewFlagSet(ApplyCommand.String(), pflag.ContinueOnError)
|
||||
flagSet.SetOutput(ioutil.Discard)
|
||||
flagSet.StringVarP(&workspace, WorkspaceFlagLong, WorkspaceFlagShort, "", "Apply the plan for this Terraform workspace.")
|
||||
flagSet.StringVarP(&dir, DirFlagLong, DirFlagShort, "", "Apply the plan for this directory, relative to root of repo, ex. 'child/dir'.")
|
||||
flagSet.StringVarP(&project, ProjectFlagLong, ProjectFlagShort, "", fmt.Sprintf("Apply the plan for this project. Refers to the name of the project configured in %s. Cannot be used at same time as workspace or dir flags.", yaml.AtlantisYAMLFilename))
|
||||
flagSet.BoolVarP(&verbose, VerboseFlagLong, VerboseFlagShort, false, "Append Atlantis log to comment.")
|
||||
flagSet.StringVarP(&workspace, workspaceFlagLong, workspaceFlagShort, "", "Apply the plan for this Terraform workspace.")
|
||||
flagSet.StringVarP(&dir, dirFlagLong, dirFlagShort, "", "Apply the plan for this directory, relative to root of repo, ex. 'child/dir'.")
|
||||
flagSet.StringVarP(&project, projectFlagLong, projectFlagShort, "", fmt.Sprintf("Apply the plan for this project. Refers to the name of the project configured in %s. Cannot be used at same time as workspace or dir flags.", yaml.AtlantisYAMLFilename))
|
||||
flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.")
|
||||
default:
|
||||
return CommentParseResult{CommentResponse: fmt.Sprintf("Error: unknown command %q – this is a bug", command)}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen
|
||||
// don't detect, ex. atlantis plan -p project -d . -w default won't cause
|
||||
// an error.
|
||||
if project != "" && (workspace != "" || dir != "") {
|
||||
err := fmt.Sprintf("cannot use -%s/--%s at same time as -%s/--%s or -%s/--%s", ProjectFlagShort, ProjectFlagLong, DirFlagShort, DirFlagLong, WorkspaceFlagShort, WorkspaceFlagLong)
|
||||
err := fmt.Sprintf("cannot use -%s/--%s at same time as -%s/--%s or -%s/--%s", projectFlagShort, projectFlagLong, dirFlagShort, dirFlagLong, workspaceFlagShort, workspaceFlagLong)
|
||||
return CommentParseResult{CommentResponse: e.errMarkdown(err, command, flagSet)}
|
||||
}
|
||||
|
||||
@@ -246,33 +246,33 @@ func (e *CommentParser) BuildPlanComment(repoRelDir string, workspace string, pr
|
||||
}
|
||||
commentFlags = fmt.Sprintf(" -- %s", strings.Join(flagsWithoutQuotes, " "))
|
||||
}
|
||||
return fmt.Sprintf("%s %s%s%s", AtlantisExecutable, PlanCommand.String(), flags, commentFlags)
|
||||
return fmt.Sprintf("%s %s%s%s", atlantisExecutable, PlanCommand.String(), flags, commentFlags)
|
||||
}
|
||||
|
||||
// BuildApplyComment builds an apply comment for the specified args.
|
||||
func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, project string) string {
|
||||
flags := e.buildFlags(repoRelDir, workspace, project)
|
||||
return fmt.Sprintf("%s %s%s", AtlantisExecutable, ApplyCommand.String(), flags)
|
||||
return fmt.Sprintf("%s %s%s", atlantisExecutable, ApplyCommand.String(), flags)
|
||||
}
|
||||
|
||||
func (e *CommentParser) buildFlags(repoRelDir string, workspace string, project string) string {
|
||||
switch {
|
||||
// If project is specified we can just use its name.
|
||||
case project != "":
|
||||
return fmt.Sprintf(" -%s %s", ProjectFlagShort, project)
|
||||
return fmt.Sprintf(" -%s %s", projectFlagShort, project)
|
||||
// If it's the root and default workspace then we just need to specify one
|
||||
// of the flags and the other will get defaulted.
|
||||
case repoRelDir == DefaultRepoRelDir && workspace == DefaultWorkspace:
|
||||
return fmt.Sprintf(" -%s %s", DirFlagShort, DefaultRepoRelDir)
|
||||
return fmt.Sprintf(" -%s %s", dirFlagShort, DefaultRepoRelDir)
|
||||
// If dir is the default then we just need to specify workspace.
|
||||
case repoRelDir == DefaultRepoRelDir:
|
||||
return fmt.Sprintf(" -%s %s", WorkspaceFlagShort, workspace)
|
||||
return fmt.Sprintf(" -%s %s", workspaceFlagShort, workspace)
|
||||
// If workspace is the default then we just need to specify the dir.
|
||||
case workspace == DefaultWorkspace:
|
||||
return fmt.Sprintf(" -%s %s", DirFlagShort, repoRelDir)
|
||||
return fmt.Sprintf(" -%s %s", dirFlagShort, repoRelDir)
|
||||
// Otherwise we have to specify both flags.
|
||||
default:
|
||||
return fmt.Sprintf(" -%s %s -%s %s", DirFlagShort, repoRelDir, WorkspaceFlagShort, workspace)
|
||||
return fmt.Sprintf(" -%s %s -%s %s", dirFlagShort, repoRelDir, workspaceFlagShort, workspace)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ func (e *CommentParser) validateDir(dir string) (string, error) {
|
||||
validatedDir = filepath.Clean(validatedDir)
|
||||
// Detect relative dirs since they're not allowed.
|
||||
if strings.HasPrefix(validatedDir, "..") {
|
||||
return "", fmt.Errorf("using a relative path %q with -%s/--%s is not allowed", dir, DirFlagShort, DirFlagLong)
|
||||
return "", fmt.Errorf("using a relative path %q with -%s/--%s is not allowed", dir, dirFlagShort, dirFlagLong)
|
||||
}
|
||||
|
||||
return validatedDir, nil
|
||||
@@ -307,6 +307,8 @@ func (e *CommentParser) errMarkdown(errMsg string, command string, flagSet *pfla
|
||||
return fmt.Sprintf("```\nError: %s.\nUsage of %s:\n%s```", errMsg, command, flagSet.FlagUsagesWrapped(usagesCols))
|
||||
}
|
||||
|
||||
// HelpComment is the comment we add to the pull request when someone runs
|
||||
// `atlantis help`.
|
||||
var HelpComment = "```cmake\n" +
|
||||
`atlantis
|
||||
Terraform For Teams
|
||||
@@ -337,4 +339,6 @@ Flags:
|
||||
Use "atlantis [command] --help" for more information about a command.
|
||||
`
|
||||
|
||||
// DidYouMeanAtlantisComment is the comment we add to the pull request when
|
||||
// someone runs a command with terraform instead of atlantis.
|
||||
var DidYouMeanAtlantisComment = "Did you mean to use `atlantis` instead of `terraform`?"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
@@ -114,11 +114,11 @@ func TestUpdateProjectResult(t *testing.T) {
|
||||
switch statusStr {
|
||||
case "failure":
|
||||
result = events.ProjectResult{
|
||||
ProjectCommandResult: events.ProjectCommandResult{Failure: "failure"},
|
||||
Failure: "failure",
|
||||
}
|
||||
case "error":
|
||||
result = events.ProjectResult{
|
||||
ProjectCommandResult: events.ProjectCommandResult{Error: errors.New("err")},
|
||||
Error: errors.New("err"),
|
||||
}
|
||||
default:
|
||||
result = events.ProjectResult{}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -31,34 +31,46 @@ import (
|
||||
const gitlabPullOpened = "opened"
|
||||
const usagesCols = 90
|
||||
|
||||
type CommandInterface interface {
|
||||
// PullCommand is a command to run on a pull request.
|
||||
type PullCommand interface {
|
||||
// CommandName is the name of the command we're running.
|
||||
CommandName() CommandName
|
||||
// IsVerbose is true if the output of this command should be verbose.
|
||||
IsVerbose() bool
|
||||
// IsAutoplan is true if this is an autoplan command vs. a comment command.
|
||||
IsAutoplan() bool
|
||||
}
|
||||
|
||||
// AutoplanCommand is a plan command that is automatically triggered when a
|
||||
// pull request is opened or updated.
|
||||
type AutoplanCommand struct{}
|
||||
|
||||
// CommandName is Plan.
|
||||
func (c AutoplanCommand) CommandName() CommandName {
|
||||
return PlanCommand
|
||||
}
|
||||
|
||||
// IsVerbose is false for autoplan commands.
|
||||
func (c AutoplanCommand) IsVerbose() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsAutoplan is true for autoplan commands (obviously).
|
||||
func (c AutoplanCommand) IsAutoplan() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// CommentCommand is a command that was triggered by a pull request comment.
|
||||
type CommentCommand struct {
|
||||
// RepoRelDir is the path relative to the repo root to run the command in.
|
||||
// Will never end in "/". If empty then the comment specified no directory.
|
||||
RepoRelDir string
|
||||
// CommentArgs are the extra arguments appended to comment,
|
||||
// Flags are the extra arguments appended to the comment,
|
||||
// ex. atlantis plan -- -target=resource
|
||||
Flags []string
|
||||
Name CommandName
|
||||
Flags []string
|
||||
// Name is the name of the command the comment specified.
|
||||
Name CommandName
|
||||
// Verbose is true if the command should output verbosely.
|
||||
Verbose bool
|
||||
// Workspace is the name of the Terraform workspace to run the command in.
|
||||
// If empty then the comment specified no workspace.
|
||||
@@ -76,18 +88,22 @@ func (c CommentCommand) IsForSpecificProject() bool {
|
||||
return c.RepoRelDir != "" || c.Workspace != "" || c.ProjectName != ""
|
||||
}
|
||||
|
||||
// CommandName returns the name of this command.
|
||||
func (c CommentCommand) CommandName() CommandName {
|
||||
return c.Name
|
||||
}
|
||||
|
||||
// IsVerbose is true if the command should give verbose output.
|
||||
func (c CommentCommand) IsVerbose() bool {
|
||||
return c.Verbose
|
||||
}
|
||||
|
||||
// IsAutoplan will be false for comment commands.
|
||||
func (c CommentCommand) IsAutoplan() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// String returns a string representation of the command.
|
||||
func (c CommentCommand) String() string {
|
||||
return fmt.Sprintf("command=%q verbose=%t dir=%q workspace=%q project=%q flags=%q", c.Name.String(), c.Verbose, c.RepoRelDir, c.Workspace, c.ProjectName, strings.Join(c.Flags, ","))
|
||||
}
|
||||
@@ -114,27 +130,113 @@ func NewCommentCommand(repoRelDir string, flags []string, name CommandName, verb
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_event_parsing.go EventParsing
|
||||
|
||||
// EventParsing parses webhook events from different VCS hosts into their
|
||||
// respective Atlantis models.
|
||||
// todo: rename to VCSParsing or the like because this also parses API responses #refactor
|
||||
type EventParsing interface {
|
||||
ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (baseRepo models.Repo, user models.User, pullNum int, err error)
|
||||
// ParseGithubPull returns the pull request, base repo and head repo.
|
||||
ParseGithubPull(pull *github.PullRequest) (models.PullRequest, models.Repo, models.Repo, error)
|
||||
// ParseGithubPullEvent returns the pull request, head repo and user that
|
||||
// caused the event. Base repo is available as a field on PullRequest.
|
||||
ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (pull models.PullRequest, pullEventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
// ParseGithubIssueCommentEvent parses GitHub pull request comment events.
|
||||
// baseRepo is the repo that the pull request will be merged into.
|
||||
// user is the pull request author.
|
||||
// pullNum is the number of the pull request that triggered the webhook.
|
||||
ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (
|
||||
baseRepo models.Repo, user models.User, pullNum int, err error)
|
||||
|
||||
// ParseGithubPull parses the response from the GitHub API endpoint (not
|
||||
// from a webhook) that returns a pull request.
|
||||
// pull is the parsed pull request.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
ParseGithubPull(ghPull *github.PullRequest) (
|
||||
pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, err error)
|
||||
|
||||
// ParseGithubPullEvent parses GitHub pull request events.
|
||||
// pull is the parsed pull request.
|
||||
// pullEventType is the type of event, for example opened/closed.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
// user is the pull request author.
|
||||
ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
|
||||
pull models.PullRequest, pullEventType models.PullRequestEventType,
|
||||
baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
|
||||
// ParseGithubRepo parses the response from the GitHub API endpoint that
|
||||
// returns a repo into the Atlantis model.
|
||||
ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error)
|
||||
// ParseGitlabMergeEvent returns the pull request, base repo, head repo and
|
||||
// user that caused the event.
|
||||
ParseGitlabMergeEvent(event gitlab.MergeEvent) (pull models.PullRequest, pullEventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
ParseGitlabMergeCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
|
||||
// ParseGitlabMergeRequestEvent parses GitLab merge request events.
|
||||
// pull is the parsed merge request.
|
||||
// pullEventType is the type of event, for example opened/closed.
|
||||
// baseRepo is the repo the merge request will be merged into.
|
||||
// headRepo is the repo the merge request branch is from.
|
||||
// user is the pull request author.
|
||||
ParseGitlabMergeRequestEvent(event gitlab.MergeEvent) (
|
||||
pull models.PullRequest, pullEventType models.PullRequestEventType,
|
||||
baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
|
||||
// ParseGitlabMergeRequestCommentEvent parses GitLab merge request comment
|
||||
// events.
|
||||
// baseRepo is the repo the merge request will be merged into.
|
||||
// headRepo is the repo the merge request branch is from.
|
||||
// user is the pull request author.
|
||||
ParseGitlabMergeRequestCommentEvent(event gitlab.MergeCommentEvent) (
|
||||
baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
|
||||
// ParseGitlabMergeRequest parses the response from the GitLab API endpoint
|
||||
// that returns a merge request.
|
||||
ParseGitlabMergeRequest(mr *gitlab.MergeRequest, baseRepo models.Repo) models.PullRequest
|
||||
ParseBitbucketCloudPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
ParseBitbucketCloudCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error)
|
||||
GetBitbucketCloudEventType(eventTypeHeader string) models.PullRequestEventType
|
||||
ParseBitbucketServerPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error)
|
||||
ParseBitbucketServerCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error)
|
||||
GetBitbucketServerEventType(eventTypeHeader string) models.PullRequestEventType
|
||||
|
||||
// ParseBitbucketCloudPullEvent parses a pull request event from Bitbucket
|
||||
// Cloud (bitbucket.org).
|
||||
// pull is the parsed pull request.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
// user is the pull request author.
|
||||
ParseBitbucketCloudPullEvent(body []byte) (
|
||||
pull models.PullRequest, baseRepo models.Repo,
|
||||
headRepo models.Repo, user models.User, err error)
|
||||
|
||||
// ParseBitbucketCloudPullCommentEvent parses a pull request comment event
|
||||
// from Bitbucket Cloud (bitbucket.org).
|
||||
// pull is the parsed pull request.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
// user is the pull request author.
|
||||
// comment is the comment that triggered the event.
|
||||
ParseBitbucketCloudPullCommentEvent(body []byte) (
|
||||
pull models.PullRequest, baseRepo models.Repo,
|
||||
headRepo models.Repo, user models.User, comment string, err error)
|
||||
|
||||
// GetBitbucketCloudPullEventType returns the type of the pull request
|
||||
// event given the Bitbucket Cloud header.
|
||||
GetBitbucketCloudPullEventType(eventTypeHeader string) models.PullRequestEventType
|
||||
|
||||
// ParseBitbucketServerPullEvent parses a pull request event from Bitbucket
|
||||
// Server.
|
||||
// pull is the parsed pull request.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
// user is the pull request author.
|
||||
ParseBitbucketServerPullEvent(body []byte) (
|
||||
pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo,
|
||||
user models.User, err error)
|
||||
|
||||
// ParseBitbucketServerPullCommentEvent parses a pull request comment event
|
||||
// from Bitbucket Server.
|
||||
// pull is the parsed pull request.
|
||||
// baseRepo is the repo the pull request will be merged into.
|
||||
// headRepo is the repo the pull request branch is from.
|
||||
// user is the pull request author.
|
||||
// comment is the comment that triggered the event.
|
||||
ParseBitbucketServerPullCommentEvent(body []byte) (
|
||||
pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo,
|
||||
user models.User, comment string, err error)
|
||||
|
||||
// GetBitbucketServerPullEventType returns the type of the pull request
|
||||
// event given the Bitbucket Server header.
|
||||
GetBitbucketServerPullEventType(eventTypeHeader string) models.PullRequestEventType
|
||||
}
|
||||
|
||||
// EventParser parses VCS events.
|
||||
type EventParser struct {
|
||||
GithubUser string
|
||||
GithubToken string
|
||||
@@ -145,9 +247,9 @@ type EventParser struct {
|
||||
BitbucketServerURL string
|
||||
}
|
||||
|
||||
// GetBitbucketCloudEventType translates the bitbucket header name into a pull
|
||||
// request event type.
|
||||
func (e *EventParser) GetBitbucketCloudEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
// GetBitbucketCloudPullEventType returns the type of the pull request
|
||||
// event given the Bitbucket Cloud header.
|
||||
func (e *EventParser) GetBitbucketCloudPullEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
switch eventTypeHeader {
|
||||
case bitbucketcloud.PullCreatedHeader:
|
||||
return models.OpenedPullEvent
|
||||
@@ -159,7 +261,10 @@ func (e *EventParser) GetBitbucketCloudEventType(eventTypeHeader string) models.
|
||||
return models.OtherPullEvent
|
||||
}
|
||||
|
||||
func (e *EventParser) ParseBitbucketCloudCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error) {
|
||||
// ParseBitbucketCloudPullCommentEvent parses a pull request comment event
|
||||
// from Bitbucket Cloud (bitbucket.org).
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseBitbucketCloudPullCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error) {
|
||||
var event bitbucketcloud.CommentEvent
|
||||
if err = json.Unmarshal(body, &event); err != nil {
|
||||
err = errors.Wrap(err, "parsing json")
|
||||
@@ -186,7 +291,7 @@ func (e *EventParser) parseCommonBitbucketCloudEventData(event bitbucketcloud.Co
|
||||
case "DECLINE":
|
||||
prState = models.ClosedPullState
|
||||
default:
|
||||
err = fmt.Errorf("unable to determine pull request state from %q, this is a bug!", *event.PullRequest.State)
|
||||
err = fmt.Errorf("unable to determine pull request state from %q–this is a bug", *event.PullRequest.State)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -224,6 +329,9 @@ func (e *EventParser) parseCommonBitbucketCloudEventData(event bitbucketcloud.Co
|
||||
return
|
||||
}
|
||||
|
||||
// ParseBitbucketCloudPullEvent parses a pull request event from Bitbucket
|
||||
// Cloud (bitbucket.org).
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseBitbucketCloudPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
var event bitbucketcloud.PullRequestEvent
|
||||
if err = json.Unmarshal(body, &event); err != nil {
|
||||
@@ -238,6 +346,8 @@ func (e *EventParser) ParseBitbucketCloudPullEvent(body []byte) (pull models.Pul
|
||||
return
|
||||
}
|
||||
|
||||
// ParseGithubIssueCommentEvent parses GitHub pull request comment events.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGithubIssueCommentEvent(comment *github.IssueCommentEvent) (baseRepo models.Repo, user models.User, pullNum int, err error) {
|
||||
baseRepo, err = e.ParseGithubRepo(comment.Repo)
|
||||
if err != nil {
|
||||
@@ -259,6 +369,8 @@ func (e *EventParser) ParseGithubIssueCommentEvent(comment *github.IssueCommentE
|
||||
return
|
||||
}
|
||||
|
||||
// ParseGithubPullEvent parses GitHub pull request events.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (pull models.PullRequest, pullEventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
if pullEvent.PullRequest == nil {
|
||||
err = errors.New("pull_request is null")
|
||||
@@ -291,6 +403,9 @@ func (e *EventParser) ParseGithubPullEvent(pullEvent *github.PullRequestEvent) (
|
||||
return
|
||||
}
|
||||
|
||||
// ParseGithubPull parses the response from the GitHub API endpoint (not
|
||||
// from a webhook) that returns a pull request.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGithubPull(pull *github.PullRequest) (pullModel models.PullRequest, baseRepo models.Repo, headRepo models.Repo, err error) {
|
||||
commit := pull.Head.GetSHA()
|
||||
if commit == "" {
|
||||
@@ -344,11 +459,17 @@ func (e *EventParser) ParseGithubPull(pull *github.PullRequest) (pullModel model
|
||||
return
|
||||
}
|
||||
|
||||
// ParseGithubRepo parses the response from the GitHub API endpoint that
|
||||
// returns a repo into the Atlantis model.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGithubRepo(ghRepo *github.Repository) (models.Repo, error) {
|
||||
return models.NewRepo(models.Github, ghRepo.GetFullName(), ghRepo.GetCloneURL(), e.GithubUser, e.GithubToken)
|
||||
}
|
||||
|
||||
func (e *EventParser) ParseGitlabMergeEvent(event gitlab.MergeEvent) (pull models.PullRequest, eventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
// ParseGitlabMergeRequestEvent parses GitLab merge request events.
|
||||
// pull is the parsed merge request.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGitlabMergeRequestEvent(event gitlab.MergeEvent) (pull models.PullRequest, eventType models.PullRequestEventType, baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
modelState := models.ClosedPullState
|
||||
if event.ObjectAttributes.State == gitlabPullOpened {
|
||||
modelState = models.OpenPullState
|
||||
@@ -393,8 +514,10 @@ func (e *EventParser) ParseGitlabMergeEvent(event gitlab.MergeEvent) (pull model
|
||||
return
|
||||
}
|
||||
|
||||
// ParseGitlabMergeCommentEvent creates Atlantis models out of a GitLab event.
|
||||
func (e *EventParser) ParseGitlabMergeCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
// ParseGitlabMergeRequestCommentEvent parses GitLab merge request comment
|
||||
// events.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseGitlabMergeRequestCommentEvent(event gitlab.MergeCommentEvent) (baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
// Parse the base repo first.
|
||||
repoFullName := event.Project.PathWithNamespace
|
||||
cloneURL := event.Project.GitHTTPURL
|
||||
@@ -436,7 +559,9 @@ func (e *EventParser) ParseGitlabMergeRequest(mr *gitlab.MergeRequest, baseRepo
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EventParser) GetBitbucketServerEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
// GetBitbucketServerPullEventType returns the type of the pull request
|
||||
// event given the Bitbucket Server header.
|
||||
func (e *EventParser) GetBitbucketServerPullEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
switch eventTypeHeader {
|
||||
case bitbucketserver.PullCreatedHeader:
|
||||
return models.OpenedPullEvent
|
||||
@@ -446,7 +571,10 @@ func (e *EventParser) GetBitbucketServerEventType(eventTypeHeader string) models
|
||||
return models.OtherPullEvent
|
||||
}
|
||||
|
||||
func (e *EventParser) ParseBitbucketServerCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error) {
|
||||
// ParseBitbucketServerPullCommentEvent parses a pull request comment event
|
||||
// from Bitbucket Server.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseBitbucketServerPullCommentEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, comment string, err error) {
|
||||
var event bitbucketserver.CommentEvent
|
||||
if err = json.Unmarshal(body, &event); err != nil {
|
||||
err = errors.Wrap(err, "parsing json")
|
||||
@@ -471,7 +599,7 @@ func (e *EventParser) parseCommonBitbucketServerEventData(event bitbucketserver.
|
||||
case "DECLINED":
|
||||
prState = models.ClosedPullState
|
||||
default:
|
||||
err = fmt.Errorf("unable to determine pull request state from %q, this is a bug!", *event.PullRequest.State)
|
||||
err = fmt.Errorf("unable to determine pull request state from %q–this is a bug", *event.PullRequest.State)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -516,6 +644,9 @@ func (e *EventParser) parseCommonBitbucketServerEventData(event bitbucketserver.
|
||||
return
|
||||
}
|
||||
|
||||
// ParseBitbucketServerPullEvent parses a pull request event from Bitbucket
|
||||
// Server.
|
||||
// See EventParsing for return value docs.
|
||||
func (e *EventParser) ParseBitbucketServerPullEvent(body []byte) (pull models.PullRequest, baseRepo models.Repo, headRepo models.Repo, user models.User, err error) {
|
||||
var event bitbucketserver.PullRequestEvent
|
||||
if err = json.Unmarshal(body, &event); err != nil {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
@@ -274,7 +274,7 @@ func TestParseGitlabMergeEvent(t *testing.T) {
|
||||
var event *gitlab.MergeEvent
|
||||
err = json.Unmarshal(bytes, &event)
|
||||
Ok(t, err)
|
||||
pull, evType, actBaseRepo, actHeadRepo, actUser, err := parser.ParseGitlabMergeEvent(*event)
|
||||
pull, evType, actBaseRepo, actHeadRepo, actUser, err := parser.ParseGitlabMergeRequestEvent(*event)
|
||||
Ok(t, err)
|
||||
|
||||
expBaseRepo := models.Repo{
|
||||
@@ -316,7 +316,7 @@ func TestParseGitlabMergeEvent(t *testing.T) {
|
||||
|
||||
t.Log("If the state is closed, should set field correctly.")
|
||||
event.ObjectAttributes.State = "closed"
|
||||
pull, _, _, _, _, err = parser.ParseGitlabMergeEvent(*event)
|
||||
pull, _, _, _, _, err = parser.ParseGitlabMergeRequestEvent(*event)
|
||||
Ok(t, err)
|
||||
Equals(t, models.ClosedPullState, pull.State)
|
||||
}
|
||||
@@ -330,7 +330,7 @@ func TestParseGitlabMergeEvent_Subgroup(t *testing.T) {
|
||||
var event *gitlab.MergeEvent
|
||||
err = json.Unmarshal(bytes, &event)
|
||||
Ok(t, err)
|
||||
pull, evType, actBaseRepo, actHeadRepo, actUser, err := parser.ParseGitlabMergeEvent(*event)
|
||||
pull, evType, actBaseRepo, actHeadRepo, actUser, err := parser.ParseGitlabMergeRequestEvent(*event)
|
||||
Ok(t, err)
|
||||
|
||||
expBaseRepo := models.Repo{
|
||||
@@ -411,7 +411,7 @@ func TestParseGitlabMergeEvent_ActionType(t *testing.T) {
|
||||
eventJSON := strings.Replace(mergeEventJSON, `"action": "open"`, fmt.Sprintf(`"action": %q`, c.action), 1)
|
||||
err := json.Unmarshal([]byte(eventJSON), &event)
|
||||
Ok(t, err)
|
||||
_, evType, _, _, _, err := parser.ParseGitlabMergeEvent(*event)
|
||||
_, evType, _, _, _, err := parser.ParseGitlabMergeRequestEvent(*event)
|
||||
Ok(t, err)
|
||||
Equals(t, c.exp, evType)
|
||||
})
|
||||
@@ -497,7 +497,7 @@ func TestParseGitlabMergeCommentEvent(t *testing.T) {
|
||||
var event *gitlab.MergeCommentEvent
|
||||
err = json.Unmarshal(bytes, &event)
|
||||
Ok(t, err)
|
||||
baseRepo, headRepo, user, err := parser.ParseGitlabMergeCommentEvent(*event)
|
||||
baseRepo, headRepo, user, err := parser.ParseGitlabMergeRequestCommentEvent(*event)
|
||||
Ok(t, err)
|
||||
Equals(t, models.Repo{
|
||||
FullName: "gitlabhq/gitlab-test",
|
||||
@@ -534,7 +534,7 @@ func TestParseGitlabMergeCommentEvent_Subgroup(t *testing.T) {
|
||||
var event *gitlab.MergeCommentEvent
|
||||
err = json.Unmarshal(bytes, &event)
|
||||
Ok(t, err)
|
||||
baseRepo, headRepo, user, err := parser.ParseGitlabMergeCommentEvent(*event)
|
||||
baseRepo, headRepo, user, err := parser.ParseGitlabMergeRequestCommentEvent(*event)
|
||||
Ok(t, err)
|
||||
|
||||
Equals(t, models.Repo{
|
||||
@@ -667,12 +667,12 @@ func TestCommentCommand_String(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseBitbucketCloudCommentEvent_EmptyString(t *testing.T) {
|
||||
_, _, _, _, _, err := parser.ParseBitbucketCloudCommentEvent([]byte(""))
|
||||
_, _, _, _, _, err := parser.ParseBitbucketCloudPullCommentEvent([]byte(""))
|
||||
ErrEquals(t, "parsing json: unexpected end of JSON input", err)
|
||||
}
|
||||
|
||||
func TestParseBitbucketCloudCommentEvent_EmptyObject(t *testing.T) {
|
||||
_, _, _, _, _, err := parser.ParseBitbucketCloudCommentEvent([]byte("{}"))
|
||||
_, _, _, _, _, err := parser.ParseBitbucketCloudPullCommentEvent([]byte("{}"))
|
||||
ErrContains(t, "Key: 'CommentEvent.CommonEventData.Actor' Error:Field validation for 'Actor' failed on the 'required' tag\nKey: 'CommentEvent.CommonEventData.Repository' Error:Field validation for 'Repository' failed on the 'required' tag\nKey: 'CommentEvent.CommonEventData.PullRequest' Error:Field validation for 'PullRequest' failed on the 'required' tag\nKey: 'CommentEvent.Comment' Error:Field validation for 'Comment' failed on the 'required' tag", err)
|
||||
}
|
||||
|
||||
@@ -681,7 +681,7 @@ func TestParseBitbucketCloudCommentEvent_CommitHashMissing(t *testing.T) {
|
||||
bytes, err := ioutil.ReadFile(path)
|
||||
Ok(t, err)
|
||||
emptyCommitHash := strings.Replace(string(bytes), ` "hash": "e0624da46d3a",`, "", -1)
|
||||
_, _, _, _, _, err = parser.ParseBitbucketCloudCommentEvent([]byte(emptyCommitHash))
|
||||
_, _, _, _, _, err = parser.ParseBitbucketCloudPullCommentEvent([]byte(emptyCommitHash))
|
||||
ErrContains(t, "Key: 'CommentEvent.CommonEventData.PullRequest.Source.Commit.Hash' Error:Field validation for 'Hash' failed on the 'required' tag", err)
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ func TestParseBitbucketCloudCommentEvent_ValidEvent(t *testing.T) {
|
||||
path := filepath.Join("testdata", "bitbucket-cloud-comment-event.json")
|
||||
bytes, err := ioutil.ReadFile(path)
|
||||
Ok(t, err)
|
||||
pull, baseRepo, headRepo, user, comment, err := parser.ParseBitbucketCloudCommentEvent(bytes)
|
||||
pull, baseRepo, headRepo, user, comment, err := parser.ParseBitbucketCloudPullCommentEvent(bytes)
|
||||
Ok(t, err)
|
||||
expBaseRepo := models.Repo{
|
||||
FullName: "lkysow/atlantis-example",
|
||||
@@ -761,7 +761,7 @@ func TestParseBitbucketCloudCommentEvent_MultipleStates(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
t.Run(c.pullState, func(t *testing.T) {
|
||||
withState := strings.Replace(string(bytes), `"state": "MERGED"`, fmt.Sprintf(`"state": "%s"`, c.pullState), -1)
|
||||
pull, _, _, _, _, err := parser.ParseBitbucketCloudCommentEvent([]byte(withState))
|
||||
pull, _, _, _, _, err := parser.ParseBitbucketCloudPullCommentEvent([]byte(withState))
|
||||
Ok(t, err)
|
||||
Equals(t, c.exp, pull.State)
|
||||
})
|
||||
@@ -841,19 +841,19 @@ func TestGetBitbucketCloudEventType(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.header, func(t *testing.T) {
|
||||
act := parser.GetBitbucketCloudEventType(c.header)
|
||||
act := parser.GetBitbucketCloudPullEventType(c.header)
|
||||
Equals(t, c.exp, act)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBitbucketServerCommentEvent_EmptyString(t *testing.T) {
|
||||
_, _, _, _, _, err := parser.ParseBitbucketServerCommentEvent([]byte(""))
|
||||
_, _, _, _, _, err := parser.ParseBitbucketServerPullCommentEvent([]byte(""))
|
||||
ErrEquals(t, "parsing json: unexpected end of JSON input", err)
|
||||
}
|
||||
|
||||
func TestParseBitbucketServerCommentEvent_EmptyObject(t *testing.T) {
|
||||
_, _, _, _, _, err := parser.ParseBitbucketServerCommentEvent([]byte("{}"))
|
||||
_, _, _, _, _, err := parser.ParseBitbucketServerPullCommentEvent([]byte("{}"))
|
||||
ErrContains(t, `API response "{}" was missing fields: Key: 'CommentEvent.CommonEventData.Actor' Error:Field validation for 'Actor' failed on the 'required' tag`, err)
|
||||
}
|
||||
|
||||
@@ -864,7 +864,7 @@ func TestParseBitbucketServerCommentEvent_CommitHashMissing(t *testing.T) {
|
||||
Ok(t, err)
|
||||
}
|
||||
emptyCommitHash := strings.Replace(string(bytes), `"latestCommit": "bfb1af1ba9c2a2fa84cd61af67e6e1b60a22e060",`, "", -1)
|
||||
_, _, _, _, _, err = parser.ParseBitbucketServerCommentEvent([]byte(emptyCommitHash))
|
||||
_, _, _, _, _, err = parser.ParseBitbucketServerPullCommentEvent([]byte(emptyCommitHash))
|
||||
ErrContains(t, "Key: 'CommentEvent.CommonEventData.PullRequest.FromRef.LatestCommit' Error:Field validation for 'LatestCommit' failed on the 'required' tag", err)
|
||||
}
|
||||
|
||||
@@ -874,7 +874,7 @@ func TestParseBitbucketServerCommentEvent_ValidEvent(t *testing.T) {
|
||||
if err != nil {
|
||||
Ok(t, err)
|
||||
}
|
||||
pull, baseRepo, headRepo, user, comment, err := parser.ParseBitbucketServerCommentEvent(bytes)
|
||||
pull, baseRepo, headRepo, user, comment, err := parser.ParseBitbucketServerPullCommentEvent(bytes)
|
||||
Ok(t, err)
|
||||
expBaseRepo := models.Repo{
|
||||
FullName: "atlantis/atlantis-example",
|
||||
@@ -942,7 +942,7 @@ func TestParseBitbucketServerCommentEvent_MultipleStates(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
t.Run(c.pullState, func(t *testing.T) {
|
||||
withState := strings.Replace(string(bytes), `"state": "OPEN"`, fmt.Sprintf(`"state": "%s"`, c.pullState), -1)
|
||||
pull, _, _, _, _, err := parser.ParseBitbucketServerCommentEvent([]byte(withState))
|
||||
pull, _, _, _, _, err := parser.ParseBitbucketServerPullCommentEvent([]byte(withState))
|
||||
Ok(t, err)
|
||||
Equals(t, c.exp, pull.State)
|
||||
})
|
||||
@@ -1018,7 +1018,7 @@ func TestGetBitbucketServerEventType(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.header, func(t *testing.T) {
|
||||
act := parser.GetBitbucketServerEventType(c.header)
|
||||
act := parser.GetBitbucketServerPullEventType(c.header)
|
||||
Equals(t, c.exp, act)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package boltdb_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package locking_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -23,8 +23,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
PlanCommandTitle = "Plan"
|
||||
ApplyCommandTitle = "Apply"
|
||||
planCommandTitle = "Plan"
|
||||
applyCommandTitle = "Apply"
|
||||
)
|
||||
|
||||
// MarkdownRenderer renders responses as markdown.
|
||||
@@ -51,11 +51,11 @@ type FailureData struct {
|
||||
|
||||
// ResultData is data about a successful response.
|
||||
type ResultData struct {
|
||||
Results []ProjectResultTmplData
|
||||
Results []projectResultTmplData
|
||||
CommonData
|
||||
}
|
||||
|
||||
type ProjectResultTmplData struct {
|
||||
type projectResultTmplData struct {
|
||||
Workspace string
|
||||
RepoRelDir string
|
||||
Rendered string
|
||||
@@ -76,11 +76,11 @@ func (m *MarkdownRenderer) Render(res CommandResult, cmdName CommandName, log st
|
||||
}
|
||||
|
||||
func (m *MarkdownRenderer) renderProjectResults(results []ProjectResult, common CommonData) string {
|
||||
var resultsTmplData []ProjectResultTmplData
|
||||
var resultsTmplData []projectResultTmplData
|
||||
numPlanSuccesses := 0
|
||||
|
||||
for _, result := range results {
|
||||
resultData := ProjectResultTmplData{
|
||||
resultData := projectResultTmplData{
|
||||
Workspace: result.Workspace,
|
||||
RepoRelDir: result.RepoRelDir,
|
||||
}
|
||||
@@ -113,15 +113,15 @@ func (m *MarkdownRenderer) renderProjectResults(results []ProjectResult, common
|
||||
|
||||
var tmpl *template.Template
|
||||
switch {
|
||||
case len(resultsTmplData) == 1 && common.Command == PlanCommandTitle && numPlanSuccesses > 0:
|
||||
case len(resultsTmplData) == 1 && common.Command == planCommandTitle && numPlanSuccesses > 0:
|
||||
tmpl = singleProjectPlanSuccessTmpl
|
||||
case len(resultsTmplData) == 1 && common.Command == PlanCommandTitle && numPlanSuccesses == 0:
|
||||
case len(resultsTmplData) == 1 && common.Command == planCommandTitle && numPlanSuccesses == 0:
|
||||
tmpl = singleProjectPlanUnsuccessfulTmpl
|
||||
case len(resultsTmplData) == 1 && common.Command == ApplyCommandTitle:
|
||||
case len(resultsTmplData) == 1 && common.Command == applyCommandTitle:
|
||||
tmpl = singleProjectApplyTmpl
|
||||
case common.Command == PlanCommandTitle:
|
||||
case common.Command == planCommandTitle:
|
||||
tmpl = multiProjectPlanTmpl
|
||||
case common.Command == ApplyCommandTitle:
|
||||
case common.Command == applyCommandTitle:
|
||||
tmpl = multiProjectApplyTmpl
|
||||
default:
|
||||
return "no template matched–this is a bug"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
@@ -132,13 +132,11 @@ func TestRenderProjectResults(t *testing.T) {
|
||||
events.PlanCommand,
|
||||
[]events.ProjectResult{
|
||||
{
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
},
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
},
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
@@ -166,11 +164,9 @@ $$$
|
||||
events.ApplyCommand,
|
||||
[]events.ProjectResult{
|
||||
{
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
ApplySuccess: "success",
|
||||
},
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
ApplySuccess: "success",
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
},
|
||||
},
|
||||
`Ran Apply in dir: $path$ workspace: $workspace$
|
||||
@@ -188,25 +184,21 @@ $$$
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
},
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
},
|
||||
},
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path2",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output2",
|
||||
LockURL: "lock-url2",
|
||||
ApplyCmd: "atlantis apply -d path2 -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path2 -w workspace",
|
||||
},
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output2",
|
||||
LockURL: "lock-url2",
|
||||
ApplyCmd: "atlantis apply -d path2 -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path2 -w workspace",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -245,18 +237,14 @@ $$$
|
||||
events.ApplyCommand,
|
||||
[]events.ProjectResult{
|
||||
{
|
||||
RepoRelDir: "path",
|
||||
Workspace: "workspace",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
ApplySuccess: "success",
|
||||
},
|
||||
RepoRelDir: "path",
|
||||
Workspace: "workspace",
|
||||
ApplySuccess: "success",
|
||||
},
|
||||
{
|
||||
RepoRelDir: "path2",
|
||||
Workspace: "workspace",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
ApplySuccess: "success2",
|
||||
},
|
||||
RepoRelDir: "path2",
|
||||
Workspace: "workspace",
|
||||
ApplySuccess: "success2",
|
||||
},
|
||||
},
|
||||
`Ran Apply for 2 projects:
|
||||
@@ -281,9 +269,7 @@ $$$
|
||||
events.PlanCommand,
|
||||
[]events.ProjectResult{
|
||||
{
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Error: errors.New("error"),
|
||||
},
|
||||
Error: errors.New("error"),
|
||||
RepoRelDir: "path",
|
||||
Workspace: "workspace",
|
||||
},
|
||||
@@ -305,9 +291,7 @@ $$$
|
||||
{
|
||||
RepoRelDir: "path",
|
||||
Workspace: "workspace",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Failure: "failure",
|
||||
},
|
||||
Failure: "failure",
|
||||
},
|
||||
},
|
||||
`Ran Plan in dir: $path$ workspace: $workspace$
|
||||
@@ -324,28 +308,22 @@ $$$
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
},
|
||||
PlanSuccess: &events.PlanSuccess{
|
||||
TerraformOutput: "terraform-output",
|
||||
LockURL: "lock-url",
|
||||
ApplyCmd: "atlantis apply -d path -w workspace",
|
||||
RePlanCmd: "atlantis plan -d path -w workspace",
|
||||
},
|
||||
},
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path2",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Failure: "failure",
|
||||
},
|
||||
Failure: "failure",
|
||||
},
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path3",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Error: errors.New("error"),
|
||||
},
|
||||
Error: errors.New("error"),
|
||||
},
|
||||
},
|
||||
`Ran Plan for 3 projects:
|
||||
@@ -384,25 +362,19 @@ $$$
|
||||
events.ApplyCommand,
|
||||
[]events.ProjectResult{
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
ApplySuccess: "success",
|
||||
},
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path",
|
||||
ApplySuccess: "success",
|
||||
},
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path2",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Failure: "failure",
|
||||
},
|
||||
Failure: "failure",
|
||||
},
|
||||
{
|
||||
Workspace: "workspace",
|
||||
RepoRelDir: "path3",
|
||||
ProjectCommandResult: events.ProjectCommandResult{
|
||||
Error: errors.New("error"),
|
||||
},
|
||||
Error: errors.New("error"),
|
||||
},
|
||||
},
|
||||
`Ran Apply for 3 projects:
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package matchers
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/petergtz/pegomock"
|
||||
events "github.com/runatlantis/atlantis/server/events"
|
||||
)
|
||||
|
||||
func AnyEventsProjectCommandResult() events.ProjectCommandResult {
|
||||
pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(events.ProjectCommandResult))(nil)).Elem()))
|
||||
var nullValue events.ProjectCommandResult
|
||||
return nullValue
|
||||
}
|
||||
|
||||
func EqEventsProjectCommandResult(value events.ProjectCommandResult) events.ProjectCommandResult {
|
||||
pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value})
|
||||
var nullValue events.ProjectCommandResult
|
||||
return nullValue
|
||||
}
|
||||
@@ -116,9 +116,9 @@ func (mock *MockEventParsing) ParseGithubRepo(ghRepo *github.Repository) (models
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) ParseGitlabMergeEvent(event go_gitlab.MergeEvent) (models.PullRequest, models.PullRequestEventType, models.Repo, models.Repo, models.User, error) {
|
||||
func (mock *MockEventParsing) ParseGitlabMergeRequestEvent(event go_gitlab.MergeEvent) (models.PullRequest, models.PullRequestEventType, models.Repo, models.Repo, models.User, error) {
|
||||
params := []pegomock.Param{event}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseGitlabMergeEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseGitlabMergeRequestEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 models.PullRequest
|
||||
var ret1 models.PullRequestEventType
|
||||
var ret2 models.Repo
|
||||
@@ -148,9 +148,9 @@ func (mock *MockEventParsing) ParseGitlabMergeEvent(event go_gitlab.MergeEvent)
|
||||
return ret0, ret1, ret2, ret3, ret4, ret5
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) ParseGitlabMergeCommentEvent(event go_gitlab.MergeCommentEvent) (models.Repo, models.Repo, models.User, error) {
|
||||
func (mock *MockEventParsing) ParseGitlabMergeRequestCommentEvent(event go_gitlab.MergeCommentEvent) (models.Repo, models.Repo, models.User, error) {
|
||||
params := []pegomock.Param{event}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseGitlabMergeCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseGitlabMergeRequestCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 models.Repo
|
||||
var ret1 models.Repo
|
||||
var ret2 models.User
|
||||
@@ -212,9 +212,9 @@ func (mock *MockEventParsing) ParseBitbucketCloudPullEvent(body []byte) (models.
|
||||
return ret0, ret1, ret2, ret3, ret4
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) ParseBitbucketCloudCommentEvent(body []byte) (models.PullRequest, models.Repo, models.Repo, models.User, string, error) {
|
||||
func (mock *MockEventParsing) ParseBitbucketCloudPullCommentEvent(body []byte) (models.PullRequest, models.Repo, models.Repo, models.User, string, error) {
|
||||
params := []pegomock.Param{body}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseBitbucketCloudCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseBitbucketCloudPullCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 models.PullRequest
|
||||
var ret1 models.Repo
|
||||
var ret2 models.Repo
|
||||
@@ -244,9 +244,9 @@ func (mock *MockEventParsing) ParseBitbucketCloudCommentEvent(body []byte) (mode
|
||||
return ret0, ret1, ret2, ret3, ret4, ret5
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) GetBitbucketCloudEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
func (mock *MockEventParsing) GetBitbucketCloudPullEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
params := []pegomock.Param{eventTypeHeader}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("GetBitbucketCloudEventType", params, []reflect.Type{reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("GetBitbucketCloudPullEventType", params, []reflect.Type{reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem()})
|
||||
var ret0 models.PullRequestEventType
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
@@ -284,9 +284,9 @@ func (mock *MockEventParsing) ParseBitbucketServerPullEvent(body []byte) (models
|
||||
return ret0, ret1, ret2, ret3, ret4
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) ParseBitbucketServerCommentEvent(body []byte) (models.PullRequest, models.Repo, models.Repo, models.User, string, error) {
|
||||
func (mock *MockEventParsing) ParseBitbucketServerPullCommentEvent(body []byte) (models.PullRequest, models.Repo, models.Repo, models.User, string, error) {
|
||||
params := []pegomock.Param{body}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseBitbucketServerCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("ParseBitbucketServerPullCommentEvent", params, []reflect.Type{reflect.TypeOf((*models.PullRequest)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.Repo)(nil)).Elem(), reflect.TypeOf((*models.User)(nil)).Elem(), reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
|
||||
var ret0 models.PullRequest
|
||||
var ret1 models.Repo
|
||||
var ret2 models.Repo
|
||||
@@ -316,9 +316,9 @@ func (mock *MockEventParsing) ParseBitbucketServerCommentEvent(body []byte) (mod
|
||||
return ret0, ret1, ret2, ret3, ret4, ret5
|
||||
}
|
||||
|
||||
func (mock *MockEventParsing) GetBitbucketServerEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
func (mock *MockEventParsing) GetBitbucketServerPullEventType(eventTypeHeader string) models.PullRequestEventType {
|
||||
params := []pegomock.Param{eventTypeHeader}
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("GetBitbucketServerEventType", params, []reflect.Type{reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem()})
|
||||
result := pegomock.GetGenericMockFrom(mock).Invoke("GetBitbucketServerPullEventType", params, []reflect.Type{reflect.TypeOf((*models.PullRequestEventType)(nil)).Elem()})
|
||||
var ret0 models.PullRequestEventType
|
||||
if len(result) != 0 {
|
||||
if result[0] != nil {
|
||||
@@ -456,7 +456,7 @@ func (c *EventParsing_ParseGithubRepo_OngoingVerification) GetAllCapturedArgumen
|
||||
|
||||
func (verifier *VerifierEventParsing) ParseGitlabMergeEvent(event go_gitlab.MergeEvent) *EventParsing_ParseGitlabMergeEvent_OngoingVerification {
|
||||
params := []pegomock.Param{event}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseGitlabMergeEvent", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseGitlabMergeRequestEvent", params)
|
||||
return &EventParsing_ParseGitlabMergeEvent_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ func (c *EventParsing_ParseGitlabMergeEvent_OngoingVerification) GetAllCapturedA
|
||||
|
||||
func (verifier *VerifierEventParsing) ParseGitlabMergeCommentEvent(event go_gitlab.MergeCommentEvent) *EventParsing_ParseGitlabMergeCommentEvent_OngoingVerification {
|
||||
params := []pegomock.Param{event}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseGitlabMergeCommentEvent", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseGitlabMergeRequestCommentEvent", params)
|
||||
return &EventParsing_ParseGitlabMergeCommentEvent_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
@@ -566,9 +566,9 @@ func (c *EventParsing_ParseBitbucketCloudPullEvent_OngoingVerification) GetAllCa
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierEventParsing) ParseBitbucketCloudCommentEvent(body []byte) *EventParsing_ParseBitbucketCloudCommentEvent_OngoingVerification {
|
||||
func (verifier *VerifierEventParsing) ParseBitbucketCloudPullCommentEvent(body []byte) *EventParsing_ParseBitbucketCloudCommentEvent_OngoingVerification {
|
||||
params := []pegomock.Param{body}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseBitbucketCloudCommentEvent", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseBitbucketCloudPullCommentEvent", params)
|
||||
return &EventParsing_ParseBitbucketCloudCommentEvent_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ func (c *EventParsing_ParseBitbucketCloudCommentEvent_OngoingVerification) GetAl
|
||||
|
||||
func (verifier *VerifierEventParsing) GetBitbucketCloudEventType(eventTypeHeader string) *EventParsing_GetBitbucketCloudEventType_OngoingVerification {
|
||||
params := []pegomock.Param{eventTypeHeader}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetBitbucketCloudEventType", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetBitbucketCloudPullEventType", params)
|
||||
return &EventParsing_GetBitbucketCloudEventType_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
@@ -647,9 +647,9 @@ func (c *EventParsing_ParseBitbucketServerPullEvent_OngoingVerification) GetAllC
|
||||
return
|
||||
}
|
||||
|
||||
func (verifier *VerifierEventParsing) ParseBitbucketServerCommentEvent(body []byte) *EventParsing_ParseBitbucketServerCommentEvent_OngoingVerification {
|
||||
func (verifier *VerifierEventParsing) ParseBitbucketServerPullCommentEvent(body []byte) *EventParsing_ParseBitbucketServerCommentEvent_OngoingVerification {
|
||||
params := []pegomock.Param{body}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseBitbucketServerCommentEvent", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ParseBitbucketServerPullCommentEvent", params)
|
||||
return &EventParsing_ParseBitbucketServerCommentEvent_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ func (c *EventParsing_ParseBitbucketServerCommentEvent_OngoingVerification) GetA
|
||||
|
||||
func (verifier *VerifierEventParsing) GetBitbucketServerEventType(eventTypeHeader string) *EventParsing_GetBitbucketServerEventType_OngoingVerification {
|
||||
params := []pegomock.Param{eventTypeHeader}
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetBitbucketServerEventType", params)
|
||||
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetBitbucketServerPullEventType", params)
|
||||
return &EventParsing_GetBitbucketServerEventType_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package models
|
||||
|
||||
// CommitStatus is the result of executing an Atlantis command for the commit.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package fixtures
|
||||
|
||||
import "github.com/runatlantis/atlantis/server/events/models"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package models_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,18 +13,34 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultRepoRelDir is the default directory we run commands in, relative
|
||||
// to the root of the repo.
|
||||
DefaultRepoRelDir = "."
|
||||
DefaultWorkspace = "default"
|
||||
// DefaultWorkspace is the default Terraform workspace we run commands in.
|
||||
// This is also Terraform's default workspace.
|
||||
DefaultWorkspace = "default"
|
||||
)
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder
|
||||
|
||||
// ProjectCommandBuilder builds commands that run on individual projects.
|
||||
type ProjectCommandBuilder interface {
|
||||
// BuildAutoplanCommands builds project commands that will run plan on
|
||||
// the projects determined to be modified.
|
||||
BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error)
|
||||
// BuildPlanCommands builds project plan commands for this comment. If the
|
||||
// comment doesn't specify one project then there may be multiple commands
|
||||
// to be run.
|
||||
BuildPlanCommands(ctx *CommandContext, commentCommand *CommentCommand) ([]models.ProjectCommandContext, error)
|
||||
// BuildApplyCommands builds project apply commands for this comment. If the
|
||||
// comment doesn't specify one project then there may be multiple commands
|
||||
// to be run.
|
||||
BuildApplyCommands(ctx *CommandContext, commentCommand *CommentCommand) ([]models.ProjectCommandContext, error)
|
||||
}
|
||||
|
||||
// DefaultProjectCommandBuilder implements ProjectCommandBuilder.
|
||||
// This class combines the data from the comment and any repo config file or
|
||||
// Atlantis server config and then generates a set of contexts.
|
||||
type DefaultProjectCommandBuilder struct {
|
||||
ParserValidator *yaml.ParserValidator
|
||||
ProjectFinder ProjectFinder
|
||||
@@ -37,10 +53,14 @@ type DefaultProjectCommandBuilder struct {
|
||||
CommentBuilder CommentBuilder
|
||||
}
|
||||
|
||||
type TerraformExec interface {
|
||||
// TFCommandRunner runs Terraform commands.
|
||||
type TFCommandRunner interface {
|
||||
// RunCommandWithVersion runs a Terraform command using the version v.
|
||||
RunCommandWithVersion(log *logging.SimpleLogger, path string, args []string, v *version.Version, workspace string) (string, error)
|
||||
}
|
||||
|
||||
// BuildAutoplanCommands builds project commands that will run plan on
|
||||
// the projects determined to be modified.
|
||||
func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) {
|
||||
cmds, err := p.buildPlanAllCommands(ctx, nil, false)
|
||||
if err != nil {
|
||||
@@ -186,6 +206,9 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *CommandConte
|
||||
return p.buildProjectCommandCtx(ctx, cmd.ProjectName, cmd.Flags, repoDir, repoRelDir, workspace)
|
||||
}
|
||||
|
||||
// BuildPlanCommands builds project plan commands for this comment. If the
|
||||
// comment doesn't specify one project then there may be multiple commands
|
||||
// to be run.
|
||||
func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) {
|
||||
if !cmd.IsForSpecificProject() {
|
||||
return p.buildPlanAllCommands(ctx, cmd.Flags, cmd.Verbose)
|
||||
@@ -226,6 +249,9 @@ func (p *DefaultProjectCommandBuilder) buildApplyAllCommands(ctx *CommandContext
|
||||
return cmds, nil
|
||||
}
|
||||
|
||||
// BuildApplyCommands builds project apply commands for this comment. If the
|
||||
// comment doesn't specify one project then there may be multiple commands
|
||||
// to be run.
|
||||
func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) {
|
||||
if !cmd.IsForSpecificProject() {
|
||||
return p.buildApplyAllCommands(ctx, cmd)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -30,26 +30,35 @@ import (
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_lock_url_generator.go LockURLGenerator
|
||||
|
||||
// LockURLGenerator generates urls to locks.
|
||||
type LockURLGenerator interface {
|
||||
// GenerateLockURL returns the full URL to the lock at lockID.
|
||||
GenerateLockURL(lockID string) string
|
||||
}
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_step_runner.go StepRunner
|
||||
|
||||
// StepRunner runs steps. Steps are individual pieces of execution like
|
||||
// `terraform plan`.
|
||||
type StepRunner interface {
|
||||
// Run runs the step.
|
||||
Run(ctx models.ProjectCommandContext, extraArgs []string, path string) (string, error)
|
||||
}
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_webhooks_sender.go WebhooksSender
|
||||
|
||||
// WebhooksSender sends webhook.
|
||||
type WebhooksSender interface {
|
||||
// Send sends the webhook.
|
||||
Send(log *logging.SimpleLogger, res webhooks.ApplyResult) error
|
||||
}
|
||||
|
||||
// PlanSuccess is the result of a successful plan.
|
||||
type PlanSuccess struct {
|
||||
// TerraformOutput is the output from Terraform of running plan.
|
||||
TerraformOutput string
|
||||
LockURL string
|
||||
// LockURL is the full URL to the lock held by this plan.
|
||||
LockURL string
|
||||
// RePlanCmd is the command that users should run to re-plan this project.
|
||||
RePlanCmd string
|
||||
// ApplyCmd is the command that users should run to apply this plan.
|
||||
@@ -58,11 +67,16 @@ type PlanSuccess struct {
|
||||
|
||||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_runner.go ProjectCommandRunner
|
||||
|
||||
// ProjectCommandRunner runs project commands. A project command is a command
|
||||
// for a specific TF project.
|
||||
type ProjectCommandRunner interface {
|
||||
// Plan runs terraform plan for the project described by ctx.
|
||||
Plan(ctx models.ProjectCommandContext) ProjectResult
|
||||
// Apply runs terraform apply for the project described by ctx.
|
||||
Apply(ctx models.ProjectCommandContext) ProjectResult
|
||||
}
|
||||
|
||||
// DefaultProjectCommandRunner implements ProjectCommandRunner.
|
||||
type DefaultProjectCommandRunner struct {
|
||||
Locker ProjectLocker
|
||||
LockURLGenerator LockURLGenerator
|
||||
@@ -77,41 +91,45 @@ type DefaultProjectCommandRunner struct {
|
||||
RequireApprovalOverride bool
|
||||
}
|
||||
|
||||
// Plan runs terraform plan for the project described by ctx.
|
||||
func (p *DefaultProjectCommandRunner) Plan(ctx models.ProjectCommandContext) ProjectResult {
|
||||
result := p.doPlan(ctx)
|
||||
planSuccess, failure, err := p.doPlan(ctx)
|
||||
return ProjectResult{
|
||||
ProjectCommandResult: result,
|
||||
RepoRelDir: ctx.RepoRelDir,
|
||||
Workspace: ctx.Workspace,
|
||||
PlanSuccess: planSuccess,
|
||||
Error: err,
|
||||
Failure: failure,
|
||||
RepoRelDir: ctx.RepoRelDir,
|
||||
Workspace: ctx.Workspace,
|
||||
}
|
||||
}
|
||||
|
||||
// Apply runs terraform apply for the project described by ctx.
|
||||
func (p *DefaultProjectCommandRunner) Apply(ctx models.ProjectCommandContext) ProjectResult {
|
||||
result := p.doApply(ctx)
|
||||
applyOut, failure, err := p.doApply(ctx)
|
||||
return ProjectResult{
|
||||
ProjectCommandResult: result,
|
||||
RepoRelDir: ctx.RepoRelDir,
|
||||
Workspace: ctx.Workspace,
|
||||
Failure: failure,
|
||||
Error: err,
|
||||
ApplySuccess: applyOut,
|
||||
RepoRelDir: ctx.RepoRelDir,
|
||||
Workspace: ctx.Workspace,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) ProjectCommandResult {
|
||||
func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) (*PlanSuccess, string, error) {
|
||||
// Acquire Atlantis lock for this repo/dir/workspace.
|
||||
lockAttempt, err := p.Locker.TryLock(ctx.Log, ctx.Pull, ctx.User, ctx.Workspace, models.NewProject(ctx.BaseRepo.FullName, ctx.RepoRelDir))
|
||||
if err != nil {
|
||||
return ProjectCommandResult{
|
||||
Error: errors.Wrap(err, "acquiring lock"),
|
||||
}
|
||||
return nil, "", errors.Wrap(err, "acquiring lock")
|
||||
}
|
||||
if !lockAttempt.LockAcquired {
|
||||
return ProjectCommandResult{Failure: lockAttempt.LockFailureReason}
|
||||
return nil, lockAttempt.LockFailureReason, nil
|
||||
}
|
||||
ctx.Log.Debug("acquired lock for project")
|
||||
|
||||
// Acquire internal lock for the directory we're going to operate in.
|
||||
unlockFn, err := p.WorkingDirLocker.TryLock(ctx.BaseRepo.FullName, ctx.Pull.Num, ctx.Workspace)
|
||||
if err != nil {
|
||||
return ProjectCommandResult{Error: err}
|
||||
return nil, "", err
|
||||
}
|
||||
defer unlockFn()
|
||||
|
||||
@@ -121,7 +139,7 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) P
|
||||
if unlockErr := lockAttempt.UnlockFn(); unlockErr != nil {
|
||||
ctx.Log.Err("error unlocking state after plan error: %v", unlockErr)
|
||||
}
|
||||
return ProjectCommandResult{Error: cloneErr}
|
||||
return nil, "", cloneErr
|
||||
}
|
||||
projAbsPath := filepath.Join(repoDir, ctx.RepoRelDir)
|
||||
|
||||
@@ -140,17 +158,15 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) P
|
||||
if unlockErr := lockAttempt.UnlockFn(); unlockErr != nil {
|
||||
ctx.Log.Err("error unlocking state after plan error: %v", unlockErr)
|
||||
}
|
||||
return ProjectCommandResult{Error: fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))}
|
||||
return nil, "", fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))
|
||||
}
|
||||
|
||||
return ProjectCommandResult{
|
||||
PlanSuccess: &PlanSuccess{
|
||||
LockURL: p.LockURLGenerator.GenerateLockURL(lockAttempt.LockKey),
|
||||
TerraformOutput: strings.Join(outputs, "\n"),
|
||||
RePlanCmd: ctx.RePlanCmd,
|
||||
ApplyCmd: ctx.ApplyCmd,
|
||||
},
|
||||
}
|
||||
return &PlanSuccess{
|
||||
LockURL: p.LockURLGenerator.GenerateLockURL(lockAttempt.LockKey),
|
||||
TerraformOutput: strings.Join(outputs, "\n"),
|
||||
RePlanCmd: ctx.RePlanCmd,
|
||||
ApplyCmd: ctx.ApplyCmd,
|
||||
}, "", nil
|
||||
}
|
||||
|
||||
func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx models.ProjectCommandContext, absPath string) ([]string, error) {
|
||||
@@ -179,13 +195,13 @@ func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx models.Pr
|
||||
return outputs, nil
|
||||
}
|
||||
|
||||
func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext) ProjectCommandResult {
|
||||
func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext) (applyOut string, failure string, err error) {
|
||||
repoDir, err := p.WorkingDir.GetWorkingDir(ctx.BaseRepo, ctx.Pull, ctx.Workspace)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return ProjectCommandResult{Error: errors.New("project has not been cloned–did you run plan?")}
|
||||
return "", "", errors.New("project has not been cloned–did you run plan?")
|
||||
}
|
||||
return ProjectCommandResult{Error: err}
|
||||
return "", "", err
|
||||
}
|
||||
absPath := filepath.Join(repoDir, ctx.RepoRelDir)
|
||||
|
||||
@@ -193,6 +209,8 @@ func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext)
|
||||
if ctx.ProjectConfig != nil {
|
||||
applyRequirements = ctx.ProjectConfig.ApplyRequirements
|
||||
}
|
||||
// todo: this class shouldn't know about the server-side approval requirement.
|
||||
// Instead the project_command_builder should figure this out and store this information in the ctx. # refactor
|
||||
if p.RequireApprovalOverride {
|
||||
applyRequirements = []string{raw.ApprovedApplyRequirement}
|
||||
}
|
||||
@@ -201,17 +219,17 @@ func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext)
|
||||
case raw.ApprovedApplyRequirement:
|
||||
approved, err := p.PullApprovedChecker.PullIsApproved(ctx.BaseRepo, ctx.Pull) // nolint: vetshadow
|
||||
if err != nil {
|
||||
return ProjectCommandResult{Error: errors.Wrap(err, "checking if pull request was approved")}
|
||||
return "", "", errors.Wrap(err, "checking if pull request was approved")
|
||||
}
|
||||
if !approved {
|
||||
return ProjectCommandResult{Failure: "Pull request must be approved before running apply."}
|
||||
return "", "Pull request must be approved before running apply.", nil
|
||||
}
|
||||
}
|
||||
}
|
||||
// Acquire internal lock for the directory we're going to operate in.
|
||||
unlockFn, err := p.WorkingDirLocker.TryLock(ctx.BaseRepo.FullName, ctx.Pull.Num, ctx.Workspace)
|
||||
if err != nil {
|
||||
return ProjectCommandResult{Error: err}
|
||||
return "", "", err
|
||||
}
|
||||
defer unlockFn()
|
||||
|
||||
@@ -232,11 +250,9 @@ func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext)
|
||||
Success: err == nil,
|
||||
})
|
||||
if err != nil {
|
||||
return ProjectCommandResult{Error: fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))}
|
||||
}
|
||||
return ProjectCommandResult{
|
||||
ApplySuccess: strings.Join(outputs, "\n"),
|
||||
return "", "", fmt.Errorf("%s\n%s", err, strings.Join(outputs, "\n"))
|
||||
}
|
||||
return strings.Join(outputs, "\n"), "", nil
|
||||
}
|
||||
|
||||
func (p DefaultProjectCommandRunner) defaultPlanStage() valid.Stage {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,21 +10,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"github.com/runatlantis/atlantis/server/events/models"
|
||||
)
|
||||
|
||||
// ProjectResult is the result of executing a plan/apply for a project.
|
||||
// ProjectResult is the result of executing a plan/apply for a specific project.
|
||||
type ProjectResult struct {
|
||||
ProjectCommandResult
|
||||
RepoRelDir string
|
||||
Workspace string
|
||||
}
|
||||
|
||||
type ProjectCommandResult struct {
|
||||
RepoRelDir string
|
||||
Workspace string
|
||||
Error error
|
||||
Failure string
|
||||
PlanSuccess *PlanSuccess
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package terraform_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
// purposefully empty to trigger coverage report
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package fixtures
|
||||
|
||||
import "github.com/google/go-github/github"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package webhooks_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -149,7 +149,7 @@ func (w *FileWorkspace) Delete(r models.Repo, p models.PullRequest) error {
|
||||
return os.RemoveAll(w.repoPullDir(r, p))
|
||||
}
|
||||
|
||||
// Delete deletes the working dir for this workspace.
|
||||
// DeleteForWorkspace deletes the working dir for this workspace.
|
||||
func (w *FileWorkspace) DeleteForWorkspace(r models.Repo, p models.PullRequest, workspace string) error {
|
||||
return os.RemoveAll(w.cloneDir(r, p, workspace))
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
@@ -145,7 +145,7 @@ func (e *EventsController) handleBitbucketCloudPost(w http.ResponseWriter, r *ht
|
||||
switch eventType {
|
||||
case bitbucketcloud.PullCreatedHeader, bitbucketcloud.PullUpdatedHeader, bitbucketcloud.PullFulfilledHeader, bitbucketcloud.PullRejectedHeader:
|
||||
e.Logger.Debug("handling as pull request state changed event")
|
||||
e.HandleBitbucketCloudPullRequestEvent(w, eventType, body, reqID)
|
||||
e.handleBitbucketCloudPullRequestEvent(w, eventType, body, reqID)
|
||||
return
|
||||
case bitbucketcloud.PullCommentCreatedHeader:
|
||||
e.Logger.Debug("handling as comment created event")
|
||||
@@ -175,7 +175,7 @@ func (e *EventsController) handleBitbucketServerPost(w http.ResponseWriter, r *h
|
||||
switch eventType {
|
||||
case bitbucketserver.PullCreatedHeader, bitbucketserver.PullMergedHeader, bitbucketserver.PullDeclinedHeader:
|
||||
e.Logger.Debug("handling as pull request state changed event")
|
||||
e.HandleBitbucketServerPullRequestEvent(w, eventType, body, reqID)
|
||||
e.handleBitbucketServerPullRequestEvent(w, eventType, body, reqID)
|
||||
return
|
||||
case bitbucketserver.PullCommentCreatedHeader:
|
||||
e.Logger.Debug("handling as comment created event")
|
||||
@@ -207,7 +207,7 @@ func (e *EventsController) HandleGithubCommentEvent(w http.ResponseWriter, event
|
||||
|
||||
// HandleBitbucketCloudCommentEvent handles comment events from Bitbucket.
|
||||
func (e *EventsController) HandleBitbucketCloudCommentEvent(w http.ResponseWriter, body []byte, reqID string) {
|
||||
pull, baseRepo, headRepo, user, comment, err := e.Parser.ParseBitbucketCloudCommentEvent(body)
|
||||
pull, baseRepo, headRepo, user, comment, err := e.Parser.ParseBitbucketCloudPullCommentEvent(body)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketCloudRequestIDHeader, reqID)
|
||||
return
|
||||
@@ -217,7 +217,7 @@ func (e *EventsController) HandleBitbucketCloudCommentEvent(w http.ResponseWrite
|
||||
|
||||
// HandleBitbucketServerCommentEvent handles comment events from Bitbucket.
|
||||
func (e *EventsController) HandleBitbucketServerCommentEvent(w http.ResponseWriter, body []byte, reqID string) {
|
||||
pull, baseRepo, headRepo, user, comment, err := e.Parser.ParseBitbucketServerCommentEvent(body)
|
||||
pull, baseRepo, headRepo, user, comment, err := e.Parser.ParseBitbucketServerPullCommentEvent(body)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketCloudRequestIDHeader, reqID)
|
||||
return
|
||||
@@ -225,24 +225,24 @@ func (e *EventsController) HandleBitbucketServerCommentEvent(w http.ResponseWrit
|
||||
e.handleCommentEvent(w, baseRepo, &headRepo, &pull, user, pull.Num, comment, models.BitbucketCloud)
|
||||
}
|
||||
|
||||
func (e *EventsController) HandleBitbucketCloudPullRequestEvent(w http.ResponseWriter, eventType string, body []byte, reqID string) {
|
||||
func (e *EventsController) handleBitbucketCloudPullRequestEvent(w http.ResponseWriter, eventType string, body []byte, reqID string) {
|
||||
pull, baseRepo, headRepo, user, err := e.Parser.ParseBitbucketCloudPullEvent(body)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketCloudRequestIDHeader, reqID)
|
||||
return
|
||||
}
|
||||
pullEventType := e.Parser.GetBitbucketCloudEventType(eventType)
|
||||
pullEventType := e.Parser.GetBitbucketCloudPullEventType(eventType)
|
||||
e.Logger.Info("identified event as type %q", pullEventType.String())
|
||||
e.handlePullRequestEvent(w, baseRepo, headRepo, pull, user, pullEventType)
|
||||
}
|
||||
|
||||
func (e *EventsController) HandleBitbucketServerPullRequestEvent(w http.ResponseWriter, eventType string, body []byte, reqID string) {
|
||||
func (e *EventsController) handleBitbucketServerPullRequestEvent(w http.ResponseWriter, eventType string, body []byte, reqID string) {
|
||||
pull, baseRepo, headRepo, user, err := e.Parser.ParseBitbucketServerPullEvent(body)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing pull data: %s %s=%s", err, bitbucketServerRequestIDHeader, reqID)
|
||||
return
|
||||
}
|
||||
pullEventType := e.Parser.GetBitbucketServerEventType(eventType)
|
||||
pullEventType := e.Parser.GetBitbucketServerPullEventType(eventType)
|
||||
e.Logger.Info("identified event as type %q", pullEventType.String())
|
||||
e.handlePullRequestEvent(w, baseRepo, headRepo, pull, user, pullEventType)
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func (e *EventsController) handleGitlabPost(w http.ResponseWriter, r *http.Reque
|
||||
// commands can come from. It's exported to make testing easier.
|
||||
func (e *EventsController) HandleGitlabCommentEvent(w http.ResponseWriter, event gitlab.MergeCommentEvent) {
|
||||
// todo: can gitlab return the pull request here too?
|
||||
baseRepo, headRepo, user, err := e.Parser.ParseGitlabMergeCommentEvent(event)
|
||||
baseRepo, headRepo, user, err := e.Parser.ParseGitlabMergeRequestCommentEvent(event)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing webhook: %s", err)
|
||||
return
|
||||
@@ -389,7 +389,7 @@ func (e *EventsController) handleCommentEvent(w http.ResponseWriter, baseRepo mo
|
||||
// request if the event is a merge request closed event. It's exported to make
|
||||
// testing easier.
|
||||
func (e *EventsController) HandleGitlabMergeRequestEvent(w http.ResponseWriter, event gitlab.MergeEvent) {
|
||||
pull, pullEventType, baseRepo, headRepo, user, err := e.Parser.ParseGitlabMergeEvent(event)
|
||||
pull, pullEventType, baseRepo, headRepo, user, err := e.Parser.ParseGitlabMergeRequestEvent(event)
|
||||
if err != nil {
|
||||
e.respond(w, logging.Error, http.StatusBadRequest, "Error parsing webhook: %s", err)
|
||||
return
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server_test
|
||||
|
||||
import (
|
||||
@@ -312,7 +312,7 @@ func TestPost_GitlabMergeRequestInvalid(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, errors.New("err"))
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, errors.New("err"))
|
||||
w := httptest.NewRecorder()
|
||||
e.Post(w, req)
|
||||
responseContains(t, w, http.StatusBadRequest, "Error parsing webhook: err")
|
||||
@@ -346,7 +346,7 @@ func TestPost_GitlabMergeRequestNotWhitelisted(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
e.Post(w, req)
|
||||
@@ -377,7 +377,7 @@ func TestPost_GitlabMergeRequestUnsupportedAction(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, repo, repo, models.User{}, nil)
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, repo, repo, models.User{}, nil)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
e.Post(w, req)
|
||||
@@ -413,7 +413,7 @@ func TestPost_GitlabMergeRequestClosedErrCleaningPull(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
When(c.CleanUpPull(repo, pullRequest)).ThenReturn(errors.New("err"))
|
||||
w := httptest.NewRecorder()
|
||||
e.Post(w, req)
|
||||
@@ -447,7 +447,7 @@ func TestPost_GitlabMergeRequestSuccess(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
w := httptest.NewRecorder()
|
||||
e.Post(w, req)
|
||||
responseContains(t, w, http.StatusOK, "Pull request cleaned successfully")
|
||||
@@ -492,7 +492,7 @@ func TestPost_PullOpenedOrUpdated(t *testing.T) {
|
||||
When(gl.ParseAndValidate(req, secret)).ThenReturn(gitlabMergeEvent, nil)
|
||||
repo := models.Repo{}
|
||||
pullRequest := models.PullRequest{State: models.ClosedPullState}
|
||||
When(p.ParseGitlabMergeEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
When(p.ParseGitlabMergeRequestEvent(gitlabMergeEvent)).ThenReturn(pullRequest, models.OpenedPullEvent, repo, repo, models.User{}, nil)
|
||||
case models.Github:
|
||||
req.Header.Set(githubHeader, "pull_request")
|
||||
event := fmt.Sprintf(`{"action": "%s"}`, c.Action)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package logging_test
|
||||
|
||||
// purposefully empty to trigger coverage report
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package recovery_test
|
||||
|
||||
// purposefully empty to trigger coverage report
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
// Package server handles the web server and executing commands that come in
|
||||
// via webhooks.
|
||||
package server
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package testdrive
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package testdrive
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// Modified hereafter by contributors to runatlantis/atlantis.
|
||||
//
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user