From b34423a453e3fe513e1179170ca212bd3d8eae9f Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Thu, 24 Feb 2022 14:32:38 -0800 Subject: [PATCH 1/7] Moved CommandContext and CommandResult to models --- CONTRIBUTING.md | 2 +- server/events/apply_command_runner.go | 8 +-- server/events/apply_command_runner_test.go | 4 +- .../events/approve_policies_command_runner.go | 8 +-- server/events/automerger.go | 2 +- server/events/command_result.go | 41 ------------- server/events/command_runner.go | 14 ++--- server/events/command_runner_internal_test.go | 4 +- server/events/db_updater.go | 2 +- .../instrumented_project_command_builder.go | 6 +- server/events/markdown_renderer.go | 2 +- server/events/markdown_renderer_test.go | 36 +++++------ .../matchers/ptr_to_events_commandcontext.go | 20 +++---- .../matchers/ptr_to_models_commandcontext.go | 12 ++-- .../events/mocks/mock_apply_command_locker.go | 14 ++--- ...mock_pre_workflows_hooks_command_runner.go | 14 ++--- .../mocks/mock_project_command_builder.go | 60 +++++++++---------- .../mocks/mock_stale_command_checker.go | 14 ++--- server/events/{ => models}/command_context.go | 28 +++------ server/events/models/command_result.go | 26 ++++++++ .../{ => models}/command_result_test.go | 23 ++++--- server/events/plan_command_runner.go | 22 +++---- server/events/policy_check_command_runner.go | 6 +- .../pre_workflow_hooks_command_runner.go | 4 +- .../pre_workflow_hooks_command_runner_test.go | 2 +- server/events/project_command_builder.go | 34 +++++------ .../project_command_builder_internal_test.go | 6 +- server/events/project_command_builder_test.go | 22 +++---- .../events/project_command_context_builder.go | 12 ++-- .../project_command_context_builder_test.go | 2 +- .../events/project_command_pool_executor.go | 8 +-- server/events/pull_updater.go | 5 +- .../size_limited_project_command_builder.go | 4 +- ...ze_limited_project_command_builder_test.go | 4 +- server/events/stale_command_handler.go | 3 +- server/events/stale_command_handler_test.go | 4 +- server/events/unlock_command_runner.go | 2 +- server/events/version_command_runner.go | 4 +- 38 files changed, 229 insertions(+), 255 deletions(-) delete mode 100644 server/events/command_result.go rename server/events/{ => models}/command_context.go (53%) create mode 100644 server/events/models/command_result.go rename server/events/{ => models}/command_result_test.go (81%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62f16298c..01e7a3ab7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,7 +160,7 @@ Each interface that is mocked has a `go:generate` command above it, e.g. //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder type ProjectCommandBuilder interface { - BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) } ``` diff --git a/server/events/apply_command_runner.go b/server/events/apply_command_runner.go index e0c1ac2f8..dfa5459ad 100644 --- a/server/events/apply_command_runner.go +++ b/server/events/apply_command_runner.go @@ -62,7 +62,7 @@ type ApplyCommandRunner struct { silenceVCSStatusNoProjects bool } -func (a *ApplyCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { +func (a *ApplyCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { var err error baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -118,7 +118,7 @@ func (a *ApplyCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, cmd.CommandName()); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - a.pullUpdater.updatePull(ctx, cmd, CommandResult{Error: err}) + a.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) return } @@ -138,7 +138,7 @@ func (a *ApplyCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { } // Only run commands in parallel if enabled - var result CommandResult + var result models.CommandResult if a.isParallelEnabled(projectCmds) { ctx.Log.Info("Running applies in parallel") result = runProjectCmdsParallel(projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize) @@ -174,7 +174,7 @@ func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []models.ProjectComma return len(projectCmds) > 0 && projectCmds[0].ParallelApplyEnabled } -func (a *ApplyCommandRunner) updateCommitStatus(ctx *CommandContext, pullStatus models.PullStatus) { +func (a *ApplyCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/apply_command_runner_test.go b/server/events/apply_command_runner_test.go index 465176d45..ee5957449 100644 --- a/server/events/apply_command_runner_test.go +++ b/server/events/apply_command_runner_test.go @@ -57,12 +57,12 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil) When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - ctx := &events.CommandContext{ + ctx := &models.CommandContext{ User: fixtures.User, Log: logger, Pull: modelPull, HeadRepo: fixtures.GithubRepo, - Trigger: events.Comment, + Trigger: models.Comment, Scope: scopeNull, } diff --git a/server/events/approve_policies_command_runner.go b/server/events/approve_policies_command_runner.go index ea57e4520..a03172439 100644 --- a/server/events/approve_policies_command_runner.go +++ b/server/events/approve_policies_command_runner.go @@ -38,7 +38,7 @@ type ApprovePoliciesCommandRunner struct { silenceVCSStatusNoProjects bool } -func (a *ApprovePoliciesCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { +func (a *ApprovePoliciesCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -51,7 +51,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *CommandContext, cmd *CommentComm if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PolicyCheckCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - a.pullUpdater.updatePull(ctx, cmd, CommandResult{Error: err}) + a.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) return } @@ -86,7 +86,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *CommandContext, cmd *CommentComm a.updateCommitStatus(ctx, pullStatus) } -func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *CommandContext, prjCmds []models.ProjectCommandContext) (result CommandResult) { +func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *models.CommandContext, prjCmds []models.ProjectCommandContext) (result models.CommandResult) { // Check if vcs user is in the owner list of the PolicySets. All projects // share the same Owners list at this time so no reason to iterate over each // project. @@ -105,7 +105,7 @@ func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *Com return } -func (a *ApprovePoliciesCommandRunner) updateCommitStatus(ctx *CommandContext, pullStatus models.PullStatus) { +func (a *ApprovePoliciesCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/automerger.go b/server/events/automerger.go index 4ce7e3d2d..f5e39989a 100644 --- a/server/events/automerger.go +++ b/server/events/automerger.go @@ -12,7 +12,7 @@ type AutoMerger struct { GlobalAutomerge bool } -func (c *AutoMerger) automerge(ctx *CommandContext, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool) { +func (c *AutoMerger) automerge(ctx *models.CommandContext, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool) { // We only automerge if all projects have been successfully applied. for _, p := range pullStatus.Projects { if p.Status != models.AppliedPlanStatus { diff --git a/server/events/command_result.go b/server/events/command_result.go deleted file mode 100644 index 655bf8a08..000000000 --- a/server/events/command_result.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 HootSuite Media Inc. -// -// Licensed under the Apache License, Version 2.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// 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" - -// CommandResult is the result of running a Command. -type CommandResult struct { - Error error - Failure string - ProjectResults []models.ProjectResult - // PlansDeleted is true if all plans created during this command were - // deleted. This happens if automerging is enabled and one project has an - // error since automerging requires all plans to succeed. - PlansDeleted bool -} - -// HasErrors returns true if there were any errors during the execution, -// even if it was only in one project. -func (c CommandResult) HasErrors() bool { - if c.Error != nil || c.Failure != "" { - return true - } - for _, r := range c.ProjectResults { - if !r.IsSuccessful() { - return true - } - } - return false -} diff --git a/server/events/command_runner.go b/server/events/command_runner.go index e50468b35..408d5ac6e 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -52,7 +52,7 @@ type CommandRunner interface { // StaleCommandChecker handles checks to validate if current command is stale and can be dropped. type StaleCommandChecker interface { // CommandIsStale returns true if currentEventTimestamp is earlier than timestamp set in DB's latest pull model. - CommandIsStale(ctx *CommandContext) bool + CommandIsStale(ctx *models.CommandContext) bool } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_github_pull_getter.go GithubPullGetter @@ -81,7 +81,7 @@ type GitlabMergeRequestGetter interface { // CommentCommandRunner runs individual command workflows. type CommentCommandRunner interface { - Run(*CommandContext, *CommentCommand) + Run(*models.CommandContext, *CommentCommand) } func buildCommentCommandRunner( @@ -154,14 +154,14 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo timer := scope.Timer(metrics.ExecutionTimeMetric).Start() defer timer.Stop() - ctx := &CommandContext{ + ctx := &models.CommandContext{ User: user, Log: log, Scope: scope, Pull: pull, HeadRepo: headRepo, PullStatus: status, - Trigger: Auto, + Trigger: models.Auto, TriggerTimestamp: timestamp, } if !c.validateCtxAndComment(ctx) { @@ -222,13 +222,13 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead log.Err("Unable to fetch pull status, this is likely a bug.", err) } - ctx := &CommandContext{ + ctx := &models.CommandContext{ User: user, Log: log, Pull: pull, PullStatus: status, HeadRepo: headRepo, - Trigger: Comment, + Trigger: models.Comment, Scope: scope, TriggerTimestamp: timestamp, } @@ -343,7 +343,7 @@ func (c *DefaultCommandRunner) ensureValidRepoMetadata( return } -func (c *DefaultCommandRunner) validateCtxAndComment(ctx *CommandContext) bool { +func (c *DefaultCommandRunner) validateCtxAndComment(ctx *models.CommandContext) bool { if !c.AllowForkPRs && ctx.HeadRepo.Owner != ctx.Pull.BaseRepo.Owner { if c.SilenceForkPRErrors { return false diff --git a/server/events/command_runner_internal_test.go b/server/events/command_runner_internal_test.go index 440002645..a8d0ddf53 100644 --- a/server/events/command_runner_internal_test.go +++ b/server/events/command_runner_internal_test.go @@ -74,7 +74,7 @@ func TestApplyUpdateCommitStatus(t *testing.T) { cr := &ApplyCommandRunner{ commitStatusUpdater: csu, } - cr.updateCommitStatus(&CommandContext{}, c.pullStatus) + cr.updateCommitStatus(&models.CommandContext{}, c.pullStatus) Equals(t, models.Repo{}, csu.CalledRepo) Equals(t, models.PullRequest{}, csu.CalledPull) Equals(t, c.expStatus, csu.CalledStatus) @@ -136,7 +136,7 @@ func TestPlanUpdateCommitStatus(t *testing.T) { cr := &PlanCommandRunner{ commitStatusUpdater: csu, } - cr.updateCommitStatus(&CommandContext{}, c.pullStatus) + cr.updateCommitStatus(&models.CommandContext{}, c.pullStatus) Equals(t, models.Repo{}, csu.CalledRepo) Equals(t, models.PullRequest{}, csu.CalledPull) Equals(t, c.expStatus, csu.CalledStatus) diff --git a/server/events/db_updater.go b/server/events/db_updater.go index 230b646b3..abf01df65 100644 --- a/server/events/db_updater.go +++ b/server/events/db_updater.go @@ -9,7 +9,7 @@ type DBUpdater struct { DB *db.BoltDB } -func (c *DBUpdater) updateDB(ctx *CommandContext, pull models.PullRequest, results []models.ProjectResult) (models.PullStatus, error) { +func (c *DBUpdater) updateDB(ctx *models.CommandContext, pull models.PullRequest, results []models.ProjectResult) (models.PullStatus, error) { // Filter out results that errored due to the directory not existing. We // don't store these in the database because they would never be "apply-able" // and so the pull request would always have errors. diff --git a/server/events/instrumented_project_command_builder.go b/server/events/instrumented_project_command_builder.go index c6eea0390..7fcdc6a2c 100644 --- a/server/events/instrumented_project_command_builder.go +++ b/server/events/instrumented_project_command_builder.go @@ -11,7 +11,7 @@ type InstrumentedProjectCommandBuilder struct { Logger logging.SimpleLogging } -func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -32,7 +32,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *CommandConte return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -53,7 +53,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandCo return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index 13f8abf83..b06a54774 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -102,7 +102,7 @@ type projectResultTmplData struct { // Render formats the data into a markdown string. // nolint: interfacer -func (m *MarkdownRenderer) Render(res CommandResult, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { +func (m *MarkdownRenderer) Render(res models.CommandResult, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { commandStr := strings.Title(strings.Replace(cmdName.String(), "_", " ", -1)) common := commonData{ Command: commandStr, diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 4bcb3119c..422256538 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -163,7 +163,7 @@ $$$ } r := events.MarkdownRenderer{} for _, c := range cases { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) @@ -206,7 +206,7 @@ func TestRenderErr(t *testing.T) { r := events.MarkdownRenderer{} for _, c := range cases { - res := events.CommandResult{ + res := models.CommandResult{ Error: c.Error, } for _, verbose := range []bool{true, false} { @@ -251,7 +251,7 @@ func TestRenderFailure(t *testing.T) { r := events.MarkdownRenderer{} for _, c := range cases { - res := events.CommandResult{ + res := models.CommandResult{ Failure: c.Failure, } for _, verbose := range []bool{true, false} { @@ -269,7 +269,7 @@ func TestRenderFailure(t *testing.T) { func TestRenderErrAndFailure(t *testing.T) { r := events.MarkdownRenderer{} - res := events.CommandResult{ + res := models.CommandResult{ Error: errors.New("error"), Failure: "failure", } @@ -906,7 +906,7 @@ $$$ r := events.MarkdownRenderer{} for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1059,7 +1059,7 @@ $$$ } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1205,7 +1205,7 @@ $$$ } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1229,7 +1229,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { DisableMarkdownFolding: true, } - rendered := mr.Render(events.CommandResult{ + rendered := mr.Render(models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1313,7 +1313,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { GitlabSupportsCommonMark: c.GitlabCommonMarkSupport, } - rendered := mr.Render(events.CommandResult{ + rendered := mr.Render(models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1444,7 +1444,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { ApplySuccess: c.Output, } } - rendered := mr.Render(events.CommandResult{ + rendered := mr.Render(models.CommandResult{ ProjectResults: []models.ProjectResult{pr}, }, cmd, "log", false, c.VCSHost, make(map[string]string)) @@ -1528,7 +1528,7 @@ $$$ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) - rendered := mr.Render(events.CommandResult{ + rendered := mr.Render(models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1574,7 +1574,7 @@ $$$ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) + "Plan: 1 to add, 0 to change, 0 to destroy." - rendered := mr.Render(events.CommandResult{ + rendered := mr.Render(models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1648,11 +1648,11 @@ Plan: 1 to add, 0 to change, 0 to destroy. // all the plans as a result. func TestRenderProjectResults_PlansDeleted(t *testing.T) { cases := map[string]struct { - cr events.CommandResult + cr models.CommandResult exp string }{ "one failure": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1669,7 +1669,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { `, }, "two failures": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1701,7 +1701,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { `, }, "one failure, one success": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -2209,7 +2209,7 @@ $$$ r.DisableRepoLocking = true for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -2489,7 +2489,7 @@ Plan: 1 to add, 1 to change, 1 to destroy. } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := events.CommandResult{ + res := models.CommandResult{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { diff --git a/server/events/mocks/matchers/ptr_to_events_commandcontext.go b/server/events/mocks/matchers/ptr_to_events_commandcontext.go index 60fe56924..84b5b2533 100644 --- a/server/events/mocks/matchers/ptr_to_events_commandcontext.go +++ b/server/events/mocks/matchers/ptr_to_events_commandcontext.go @@ -5,29 +5,29 @@ import ( "github.com/petergtz/pegomock" "reflect" - events "github.com/runatlantis/atlantis/server/events" + models "github.com/runatlantis/atlantis/server/events/models" ) -func AnyPtrToEventsCommandContext() *events.CommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*events.CommandContext))(nil)).Elem())) - var nullValue *events.CommandContext +func AnyPtrToEventsCommandContext() *models.CommandContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*models.CommandContext))(nil)).Elem())) + var nullValue *models.CommandContext return nullValue } -func EqPtrToEventsCommandContext(value *events.CommandContext) *events.CommandContext { +func EqPtrToEventsCommandContext(value *models.CommandContext) *models.CommandContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue *events.CommandContext + var nullValue *models.CommandContext return nullValue } -func NotEqPtrToEventsCommandContext(value *events.CommandContext) *events.CommandContext { +func NotEqPtrToEventsCommandContext(value *models.CommandContext) *models.CommandContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue *events.CommandContext + var nullValue *models.CommandContext return nullValue } -func PtrToEventsCommandContextThat(matcher pegomock.ArgumentMatcher) *events.CommandContext { +func PtrToEventsCommandContextThat(matcher pegomock.ArgumentMatcher) *models.CommandContext { pegomock.RegisterMatcher(matcher) - var nullValue *events.CommandContext + var nullValue *models.CommandContext return nullValue } diff --git a/server/events/mocks/matchers/ptr_to_models_commandcontext.go b/server/events/mocks/matchers/ptr_to_models_commandcontext.go index ca6abf31d..877258086 100644 --- a/server/events/mocks/matchers/ptr_to_models_commandcontext.go +++ b/server/events/mocks/matchers/ptr_to_models_commandcontext.go @@ -3,18 +3,18 @@ package matchers import ( "github.com/petergtz/pegomock" - events "github.com/runatlantis/atlantis/server/events" + models "github.com/runatlantis/atlantis/server/events/models" "reflect" ) -func AnyPtrToModelsCommandContext() *events.CommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*events.CommandContext))(nil)).Elem())) - var nullValue *events.CommandContext +func AnyPtrToModelsCommandContext() *models.CommandContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*models.CommandContext))(nil)).Elem())) + var nullValue *models.CommandContext return nullValue } -func EqPtrToModelsCommandContext(value *events.CommandContext) *events.CommandContext { +func EqPtrToModelsCommandContext(value *models.CommandContext) *models.CommandContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue *events.CommandContext + var nullValue *models.CommandContext return nullValue } diff --git a/server/events/mocks/mock_apply_command_locker.go b/server/events/mocks/mock_apply_command_locker.go index 37fc004d7..1e932abde 100644 --- a/server/events/mocks/mock_apply_command_locker.go +++ b/server/events/mocks/mock_apply_command_locker.go @@ -5,7 +5,7 @@ package mocks import ( pegomock "github.com/petergtz/pegomock" - events "github.com/runatlantis/atlantis/server/events" + models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" ) @@ -25,7 +25,7 @@ func NewMockApplyCommandLocker(options ...pegomock.Option) *MockApplyCommandLock func (mock *MockApplyCommandLocker) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockApplyCommandLocker) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockApplyCommandLocker) IsDisabled(ctx *events.CommandContext) bool { +func (mock *MockApplyCommandLocker) IsDisabled(ctx *models.CommandContext) bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockApplyCommandLocker().") } @@ -77,7 +77,7 @@ type VerifierMockApplyCommandLocker struct { timeout time.Duration } -func (verifier *VerifierMockApplyCommandLocker) IsDisabled(ctx *events.CommandContext) *MockApplyCommandLocker_IsDisabled_OngoingVerification { +func (verifier *VerifierMockApplyCommandLocker) IsDisabled(ctx *models.CommandContext) *MockApplyCommandLocker_IsDisabled_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsDisabled", params, verifier.timeout) return &MockApplyCommandLocker_IsDisabled_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -88,17 +88,17 @@ type MockApplyCommandLocker_IsDisabled_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetCapturedArguments() *events.CommandContext { +func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetCapturedArguments() *models.CommandContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext) { +func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } } return diff --git a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go index ebbb9f876..a7197944b 100644 --- a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go +++ b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go @@ -5,7 +5,7 @@ package mocks import ( pegomock "github.com/petergtz/pegomock" - events "github.com/runatlantis/atlantis/server/events" + models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" ) @@ -27,7 +27,7 @@ func (mock *MockPreWorkflowHooksCommandRunner) SetFailHandler(fh pegomock.FailHa } func (mock *MockPreWorkflowHooksCommandRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *events.CommandContext) error { +func (mock *MockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *models.CommandContext) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockPreWorkflowHooksCommandRunner().") } @@ -79,7 +79,7 @@ type VerifierMockPreWorkflowHooksCommandRunner struct { timeout time.Duration } -func (verifier *VerifierMockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *events.CommandContext) *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification { +func (verifier *VerifierMockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *models.CommandContext) *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RunPreHooks", params, verifier.timeout) return &MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -90,17 +90,17 @@ type MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetCapturedArguments() *events.CommandContext { +func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetCapturedArguments() *models.CommandContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext) { +func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } } return diff --git a/server/events/mocks/mock_project_command_builder.go b/server/events/mocks/mock_project_command_builder.go index 60b3bec18..78522cba0 100644 --- a/server/events/mocks/mock_project_command_builder.go +++ b/server/events/mocks/mock_project_command_builder.go @@ -26,7 +26,7 @@ func NewMockProjectCommandBuilder(options ...pegomock.Option) *MockProjectComman func (mock *MockProjectCommandBuilder) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandBuilder) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *events.CommandContext) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -45,7 +45,7 @@ func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *events.Command return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *events.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -64,7 +64,7 @@ func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *events.CommandCont return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *events.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -83,7 +83,7 @@ func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *events.CommandCon return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *events.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -102,7 +102,7 @@ func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *events. return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *events.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -158,7 +158,7 @@ type VerifierMockProjectCommandBuilder struct { timeout time.Duration } -func (verifier *VerifierMockProjectCommandBuilder) BuildAutoplanCommands(ctx *events.CommandContext) *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildAutoplanCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -169,23 +169,23 @@ type MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification struct methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetCapturedArguments() *events.CommandContext { +func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetCapturedArguments() *models.CommandContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext) { +func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } } return } -func (verifier *VerifierMockProjectCommandBuilder) BuildPlanCommands(ctx *events.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildPlanCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -196,17 +196,17 @@ type MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetCapturedArguments() (*events.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -216,7 +216,7 @@ func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAll return } -func (verifier *VerifierMockProjectCommandBuilder) BuildApplyCommands(ctx *events.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApplyCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -227,17 +227,17 @@ type MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetCapturedArguments() (*events.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -247,7 +247,7 @@ func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAl return } -func (verifier *VerifierMockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *events.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApprovePoliciesCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -258,17 +258,17 @@ type MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetCapturedArguments() (*events.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -278,7 +278,7 @@ func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerificat return } -func (verifier *VerifierMockProjectCommandBuilder) BuildVersionCommands(ctx *events.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildVersionCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -289,17 +289,17 @@ type MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetCapturedArguments() (*events.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_stale_command_checker.go b/server/events/mocks/mock_stale_command_checker.go index 6e81405d4..c716bb1c0 100644 --- a/server/events/mocks/mock_stale_command_checker.go +++ b/server/events/mocks/mock_stale_command_checker.go @@ -5,7 +5,7 @@ package mocks import ( pegomock "github.com/petergtz/pegomock" - events "github.com/runatlantis/atlantis/server/events" + models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" ) @@ -25,7 +25,7 @@ func NewMockStaleCommandChecker(options ...pegomock.Option) *MockStaleCommandChe func (mock *MockStaleCommandChecker) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockStaleCommandChecker) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockStaleCommandChecker) CommandIsStale(ctx *events.CommandContext) bool { +func (mock *MockStaleCommandChecker) CommandIsStale(ctx *models.CommandContext) bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockStaleCommandChecker().") } @@ -77,7 +77,7 @@ type VerifierMockStaleCommandChecker struct { timeout time.Duration } -func (verifier *VerifierMockStaleCommandChecker) CommandIsStale(ctx *events.CommandContext) *MockStaleCommandChecker_CommandIsStale_OngoingVerification { +func (verifier *VerifierMockStaleCommandChecker) CommandIsStale(ctx *models.CommandContext) *MockStaleCommandChecker_CommandIsStale_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CommandIsStale", params, verifier.timeout) return &MockStaleCommandChecker_CommandIsStale_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -88,17 +88,17 @@ type MockStaleCommandChecker_CommandIsStale_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetCapturedArguments() *events.CommandContext { +func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetCapturedArguments() *models.CommandContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetAllCapturedArguments() (_param0 []*events.CommandContext) { +func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*events.CommandContext, len(c.methodInvocations)) + _param0 = make([]*models.CommandContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*events.CommandContext) + _param0[u] = param.(*models.CommandContext) } } return diff --git a/server/events/command_context.go b/server/events/models/command_context.go similarity index 53% rename from server/events/command_context.go rename to server/events/models/command_context.go index f99f31526..7d51d3b8f 100644 --- a/server/events/command_context.go +++ b/server/events/models/command_context.go @@ -1,22 +1,10 @@ -// Copyright 2017 HootSuite Media Inc. -// -// Licensed under the Apache License, Version 2.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// Modified hereafter by contributors to runatlantis/atlantis. -package events +package models import ( - "github.com/runatlantis/atlantis/server/events/models" + "time" + "github.com/runatlantis/atlantis/server/logging" "github.com/uber-go/tally" - "time" ) // CommandTrigger represents the how the command was triggered @@ -37,17 +25,17 @@ type CommandContext struct { // If the pull request branch is from the same repository then HeadRepo will // be the same as BaseRepo. // See https://help.github.com/articles/about-pull-request-merges/. - HeadRepo models.Repo - Pull models.PullRequest + HeadRepo Repo + Pull PullRequest Scope tally.Scope // User is the user that triggered this command. - User models.User + User User Log logging.SimpleLogging // Current PR state - PullRequestStatus models.PullReqStatus + PullRequestStatus PullReqStatus - PullStatus *models.PullStatus + PullStatus *PullStatus Trigger CommandTrigger diff --git a/server/events/models/command_result.go b/server/events/models/command_result.go new file mode 100644 index 000000000..97fa0c216 --- /dev/null +++ b/server/events/models/command_result.go @@ -0,0 +1,26 @@ +package models + +// CommandResult is the result of running a Command. +type CommandResult struct { + Error error + Failure string + ProjectResults []ProjectResult + // PlansDeleted is true if all plans created during this command were + // deleted. This happens if automerging is enabled and one project has an + // error since automerging requires all plans to succeed. + PlansDeleted bool +} + +// HasErrors returns true if there were any errors during the execution, +// even if it was only in one project. +func (c CommandResult) HasErrors() bool { + if c.Error != nil || c.Failure != "" { + return true + } + for _, r := range c.ProjectResults { + if !r.IsSuccessful() { + return true + } + } + return false +} diff --git a/server/events/command_result_test.go b/server/events/models/command_result_test.go similarity index 81% rename from server/events/command_result_test.go rename to server/events/models/command_result_test.go index bcdeae365..5985efe32 100644 --- a/server/events/command_result_test.go +++ b/server/events/models/command_result_test.go @@ -1,39 +1,38 @@ -package events_test +package models_test import ( "errors" "testing" - "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) func TestCommandResult_HasErrors(t *testing.T) { cases := map[string]struct { - cr events.CommandResult + cr models.CommandResult exp bool }{ "error": { - cr: events.CommandResult{ + cr: models.CommandResult{ Error: errors.New("err"), }, exp: true, }, "failure": { - cr: events.CommandResult{ + cr: models.CommandResult{ Failure: "failure", }, exp: true, }, "empty results list": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{}, }, exp: false, }, "successful plan": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, @@ -43,7 +42,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "successful apply": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { ApplySuccess: "success", @@ -53,7 +52,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "single errored project": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { Error: errors.New("err"), @@ -63,7 +62,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: true, }, "single failed project": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { Failure: "failure", @@ -73,7 +72,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: true, }, "two successful projects": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, @@ -86,7 +85,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "one successful, one failed project": { - cr: events.CommandResult{ + cr: models.CommandResult{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 36fcb2253..7fe5ca78f 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -65,7 +65,7 @@ type PlanCommandRunner struct { pullStatusFetcher PullStatusFetcher } -func (p *PlanCommandRunner) runAutoplan(ctx *CommandContext) { +func (p *PlanCommandRunner) runAutoplan(ctx *models.CommandContext) { baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -74,7 +74,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *CommandContext) { if statusErr := p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - p.pullUpdater.updatePull(ctx, AutoplanCommand{}, CommandResult{Error: err}) + p.pullUpdater.updatePull(ctx, AutoplanCommand{}, models.CommandResult{Error: err}) return } @@ -106,7 +106,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *CommandContext) { } // Only run commands in parallel if enabled - var result CommandResult + var result models.CommandResult if p.isParallelEnabled(projectCmds) { ctx.Log.Info("Running plans in parallel") result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize) @@ -145,7 +145,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *CommandContext) { } } -func (p *PlanCommandRunner) run(ctx *CommandContext, cmd *CommentCommand) { +func (p *PlanCommandRunner) run(ctx *models.CommandContext, cmd *CommentCommand) { var err error baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -159,7 +159,7 @@ func (p *PlanCommandRunner) run(ctx *CommandContext, cmd *CommentCommand) { if statusErr := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - p.pullUpdater.updatePull(ctx, cmd, CommandResult{Error: err}) + p.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) return } @@ -180,7 +180,7 @@ func (p *PlanCommandRunner) run(ctx *CommandContext, cmd *CommentCommand) { projectCmds, policyCheckCmds := p.partitionProjectCmds(ctx, projectCmds) // Only run commands in parallel if enabled - var result CommandResult + var result models.CommandResult if p.isParallelEnabled(projectCmds) { ctx.Log.Info("Running applies in parallel") result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize) @@ -216,15 +216,15 @@ func (p *PlanCommandRunner) run(ctx *CommandContext, cmd *CommentCommand) { } } -func (p *PlanCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { - if ctx.Trigger == Auto { +func (p *PlanCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { + if ctx.Trigger == models.Auto { p.runAutoplan(ctx) } else { p.run(ctx, cmd) } } -func (p *PlanCommandRunner) updateCommitStatus(ctx *CommandContext, pullStatus models.PullStatus) { +func (p *PlanCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus @@ -252,7 +252,7 @@ func (p *PlanCommandRunner) updateCommitStatus(ctx *CommandContext, pullStatus m } // deletePlans deletes all plans generated in this ctx. -func (p *PlanCommandRunner) deletePlans(ctx *CommandContext) { +func (p *PlanCommandRunner) deletePlans(ctx *models.CommandContext) { pullDir, err := p.workingDir.GetPullDir(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { ctx.Log.Err("getting pull dir: %s", err) @@ -263,7 +263,7 @@ func (p *PlanCommandRunner) deletePlans(ctx *CommandContext) { } func (p *PlanCommandRunner) partitionProjectCmds( - ctx *CommandContext, + ctx *models.CommandContext, cmds []models.ProjectCommandContext, ) ( projectCmds []models.ProjectCommandContext, diff --git a/server/events/policy_check_command_runner.go b/server/events/policy_check_command_runner.go index 246830fa9..82f4e2f73 100644 --- a/server/events/policy_check_command_runner.go +++ b/server/events/policy_check_command_runner.go @@ -31,7 +31,7 @@ type PolicyCheckCommandRunner struct { silenceVCSStatusNoProjects bool } -func (p *PolicyCheckCommandRunner) Run(ctx *CommandContext, cmds []models.ProjectCommandContext) { +func (p *PolicyCheckCommandRunner) Run(ctx *models.CommandContext, cmds []models.ProjectCommandContext) { if len(cmds) == 0 { ctx.Log.Info("no projects to run policy_check in") if !p.silenceVCSStatusNoProjects { @@ -51,7 +51,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *CommandContext, cmds []models.Projec ctx.Log.Warn("unable to update commit status: %s", err) } - var result CommandResult + var result models.CommandResult if p.isParallelEnabled(cmds) { ctx.Log.Info("Running policy_checks in parallel") result = runProjectCmdsParallel(cmds, p.prjCmdRunner.PolicyCheck, p.parallelPoolSize) @@ -69,7 +69,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *CommandContext, cmds []models.Projec p.updateCommitStatus(ctx, pullStatus) } -func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *CommandContext, pullStatus models.PullStatus) { +func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/pre_workflow_hooks_command_runner.go b/server/events/pre_workflow_hooks_command_runner.go index e0451362f..cd4b6cb99 100644 --- a/server/events/pre_workflow_hooks_command_runner.go +++ b/server/events/pre_workflow_hooks_command_runner.go @@ -10,7 +10,7 @@ import ( //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_pre_workflows_hooks_command_runner.go PreWorkflowHooksCommandRunner type PreWorkflowHooksCommandRunner interface { - RunPreHooks(ctx *CommandContext) error + RunPreHooks(ctx *models.CommandContext) error } // DefaultPreWorkflowHooksCommandRunner is the first step when processing a workflow hook commands. @@ -24,7 +24,7 @@ type DefaultPreWorkflowHooksCommandRunner struct { // RunPreHooks runs pre_workflow_hooks when PR is opened or updated. func (w *DefaultPreWorkflowHooksCommandRunner) RunPreHooks( - ctx *CommandContext, + ctx *models.CommandContext, ) error { pull := ctx.Pull baseRepo := pull.BaseRepo diff --git a/server/events/pre_workflow_hooks_command_runner_test.go b/server/events/pre_workflow_hooks_command_runner_test.go index 75702a8d8..49fe52949 100644 --- a/server/events/pre_workflow_hooks_command_runner_test.go +++ b/server/events/pre_workflow_hooks_command_runner_test.go @@ -47,7 +47,7 @@ func TestRunPreHooks_Clone(t *testing.T) { var newPull = fixtures.Pull newPull.BaseRepo = fixtures.GithubRepo - ctx := &events.CommandContext{ + ctx := &models.CommandContext{ Pull: newPull, HeadRepo: fixtures.GithubRepo, User: fixtures.User, diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 2bd87d7b5..a73a6e897 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -118,30 +118,30 @@ func NewProjectCommandBuilderWithLimit( type ProjectPlanCommandBuilder interface { // BuildAutoplanCommands builds project commands that will run plan on // the projects determined to be modified. - BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) // BuildPlanCommands builds project plan commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildPlanCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectApplyCommandBuilder interface { // BuildApplyCommands builds project Apply commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildApplyCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApplyCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectApprovePoliciesCommandBuilder interface { // BuildApprovePoliciesCommands builds project PolicyCheck commands for this ctx and comment. - BuildApprovePoliciesCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectVersionCommandBuilder interface { // BuildVersionCommands builds project Version commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildVersionCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildVersionCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder @@ -173,7 +173,7 @@ type DefaultProjectCommandBuilder struct { } // See ProjectCommandBuilder.BuildAutoplanCommands. -func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { projCtxs, err := p.buildPlanAllCommands(ctx, nil, false, false) if err != nil { return nil, err @@ -190,7 +190,7 @@ func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext } // See ProjectCommandBuilder.BuildPlanCommands. -func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildPlanAllCommands(ctx, cmd.Flags, cmd.Verbose, cmd.ForceApply) } @@ -199,7 +199,7 @@ func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, cm } // See ProjectCommandBuilder.BuildApplyCommands. -func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -207,11 +207,11 @@ func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *CommandContext, c return pac, err } -func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { return p.buildAllProjectCommands(ctx, cmd) } -func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -221,7 +221,7 @@ func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *CommandContext, // buildPlanAllCommands builds plan contexts for all projects we determine were // modified in this ctx. -func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *CommandContext, commentFlags []string, verbose bool, forceApply bool) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *models.CommandContext, commentFlags []string, verbose bool, forceApply bool) ([]models.ProjectCommandContext, error) { // We'll need the list of modified files. modifiedFiles, err := p.VCSClient.GetModifiedFiles(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { @@ -353,7 +353,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *CommandContext, // buildProjectPlanCommand builds a plan context for a single project. // cmd must be for only one project. -func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -400,7 +400,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *CommandConte // getCfg returns the atlantis.yaml config (if it exists) for this project. If // there is no config, then projectCfg and repoCfg will be nil. -func (p *DefaultProjectCommandBuilder) getCfg(ctx *CommandContext, projectName string, dir string, workspace string, repoDir string) (projectsCfg []valid.Project, repoCfg *valid.RepoCfg, err error) { +func (p *DefaultProjectCommandBuilder) getCfg(ctx *models.CommandContext, projectName string, dir string, workspace string, repoDir string) (projectsCfg []valid.Project, repoCfg *valid.RepoCfg, err error) { hasConfigFile, err := p.ParserValidator.HasRepoCfg(repoDir) if err != nil { err = errors.Wrapf(err, "looking for %s file in %q", config.AtlantisYAMLFilename, repoDir) @@ -452,7 +452,7 @@ func (p *DefaultProjectCommandBuilder) getCfg(ctx *CommandContext, projectName s // buildAllProjectCommands builds contexts for a command for every project that has // pending plans in this ctx. -func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *CommandContext, commentCmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *models.CommandContext, commentCmd *CommentCommand) ([]models.ProjectCommandContext, error) { // Lock all dirs in this pull request (instead of a single dir) because we // don't know how many dirs we'll need to run the command in. unlockFn, err := p.WorkingDirLocker.TryLockPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num) @@ -491,7 +491,7 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *CommandConte // buildProjectApplyCommand builds an apply command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -533,7 +533,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *CommandCont // buildProjectVersionCommand builds a version command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -575,7 +575,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *CommandCo // buildProjectCommandCtx builds a context for a single or several projects identified // by the parameters. -func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *CommandContext, +func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *models.CommandContext, cmd models.CommandName, projectName string, commentFlags []string, diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index 0ebc2dd8c..4e2250661 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -622,7 +622,7 @@ projects: // We run a test for each type of command. for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ Log: logger, Pull: models.PullRequest{ BaseRepo: baseRepo, @@ -817,7 +817,7 @@ projects: // We run a test for each type of command, again specific projects for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ Pull: models.PullRequest{ BaseRepo: baseRepo, }, @@ -1042,7 +1042,7 @@ workflows: cmd := models.PolicyCheckCommand t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ Log: logger, Pull: models.PullRequest{ BaseRepo: baseRepo, diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 33f5cd10f..1301fd868 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -162,7 +162,7 @@ projects: logger, ) - ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{ + ctxs, err := builder.BuildAutoplanCommands(&models.CommandContext{ PullRequestStatus: models.PullReqStatus{ Mergeable: true, }, @@ -433,12 +433,12 @@ projects: var actCtxs []models.ProjectCommandContext var err error if cmdName == models.PlanCommand { - actCtxs, err = builder.BuildPlanCommands(&events.CommandContext{ + actCtxs, err = builder.BuildPlanCommands(&models.CommandContext{ Log: logger, Scope: scope, }, &c.Cmd) } else { - actCtxs, err = builder.BuildApplyCommands(&events.CommandContext{Log: logger, Scope: scope}, &c.Cmd) + actCtxs, err = builder.BuildApplyCommands(&models.CommandContext{Log: logger, Scope: scope}, &c.Cmd) } if c.ExpErr != "" { @@ -586,7 +586,7 @@ projects: ) ctxs, err := builder.BuildPlanCommands( - &events.CommandContext{ + &models.CommandContext{ Log: logger, Scope: scope, }, @@ -677,7 +677,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiApply(t *testing.T) { ) ctxs, err := builder.BuildApplyCommands( - &events.CommandContext{ + &models.CommandContext{ Log: logger, Scope: scope, }, @@ -761,7 +761,7 @@ projects: logger, ) - ctx := &events.CommandContext{ + ctx := &models.CommandContext{ HeadRepo: models.Repo{}, Pull: models.PullRequest{}, User: models.User{}, @@ -842,7 +842,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { var actCtxs []models.ProjectCommandContext var err error - actCtxs, err = builder.BuildPlanCommands(&events.CommandContext{ + actCtxs, err = builder.BuildPlanCommands(&models.CommandContext{ Log: logger, Scope: scope, }, &events.CommentCommand{ @@ -1024,7 +1024,7 @@ projects: ) actCtxs, err := builder.BuildPlanCommands( - &events.CommandContext{ + &models.CommandContext{ Log: logger, Scope: scope, }, @@ -1092,7 +1092,7 @@ projects: var actCtxs []models.ProjectCommandContext var err error - actCtxs, err = builder.BuildAutoplanCommands(&events.CommandContext{ + actCtxs, err = builder.BuildAutoplanCommands(&models.CommandContext{ HeadRepo: models.Repo{}, Pull: models.PullRequest{}, User: models.User{}, @@ -1148,7 +1148,7 @@ func TestDefaultProjectCommandBuilder_WithPolicyCheckEnabled_BuildAutoplanComman logger, ) - ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{ + ctxs, err := builder.BuildAutoplanCommands(&models.CommandContext{ PullRequestStatus: models.PullReqStatus{ Mergeable: true, }, @@ -1231,7 +1231,7 @@ func TestDefaultProjectCommandBuilder_BuildVersionCommand(t *testing.T) { ) ctxs, err := builder.BuildVersionCommands( - &events.CommandContext{ + &models.CommandContext{ Log: logger, }, &events.CommentCommand{ diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index 368579702..1db3419fb 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -44,7 +44,7 @@ type ContextFlags struct { type ProjectCommandContextBuilder interface { // BuildProjectContext builds project command contexts for atlantis commands BuildProjectContext( - ctx *CommandContext, + ctx *models.CommandContext, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -63,7 +63,7 @@ type CommandScopedStatsProjectCommandContextBuilder struct { // BuildProjectContext builds the context and injects the appropriate command level scope after the fact. func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( - ctx *CommandContext, + ctx *models.CommandContext, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -95,7 +95,7 @@ type DefaultProjectCommandContextBuilder struct { } func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( - ctx *CommandContext, + ctx *models.CommandContext, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -149,7 +149,7 @@ type PolicyCheckProjectCommandContextBuilder struct { } func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( - ctx *CommandContext, + ctx *models.CommandContext, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -198,7 +198,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( // newProjectCommandContext is a initializer method that handles constructing the // ProjectCommandContext. -func newProjectCommandContext(ctx *CommandContext, +func newProjectCommandContext(ctx *models.CommandContext, cmd models.CommandName, applyCmd string, planCmd string, @@ -277,7 +277,7 @@ func escapeArgs(args []string) []string { // Extracts required_version from Terraform configuration. // Returns nil if unable to determine version from configuration. -func getTfVersion(ctx *CommandContext, absProjDir string) *version.Version { +func getTfVersion(ctx *models.CommandContext, absProjDir string) *version.Version { module, diags := tfconfig.LoadModule(absProjDir) if diags.HasErrors() { ctx.Log.Err("trying to detect required version: %s", diags.Error()) diff --git a/server/events/project_command_context_builder_test.go b/server/events/project_command_context_builder_test.go index 6f0e3f46e..e5ce97436 100644 --- a/server/events/project_command_context_builder_test.go +++ b/server/events/project_command_context_builder_test.go @@ -37,7 +37,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { Projects: []models.ProjectStatus{}, } - commandCtx := &events.CommandContext{ + commandCtx := &models.CommandContext{ Log: logging.NewNoopLogger(t), PullStatus: pullStatus, } diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index 1c1eb2484..502cbfe07 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -13,7 +13,7 @@ func runProjectCmdsParallel( cmds []models.ProjectCommandContext, runnerFunc prjCmdRunnerFunc, poolSize int, -) CommandResult { +) models.CommandResult { var results []models.ProjectResult mux := &sync.Mutex{} @@ -35,18 +35,18 @@ func runProjectCmdsParallel( } wg.Wait() - return CommandResult{ProjectResults: results} + return models.CommandResult{ProjectResults: results} } func runProjectCmds( cmds []models.ProjectCommandContext, runnerFunc prjCmdRunnerFunc, -) CommandResult { +) models.CommandResult { var results []models.ProjectResult for _, pCmd := range cmds { res := runnerFunc(pCmd) results = append(results, res) } - return CommandResult{ProjectResults: results} + return models.CommandResult{ProjectResults: results} } diff --git a/server/events/pull_updater.go b/server/events/pull_updater.go index 65a42c7ec..47723d170 100644 --- a/server/events/pull_updater.go +++ b/server/events/pull_updater.go @@ -1,8 +1,9 @@ package events import ( - "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/vcs" ) type PullUpdater struct { @@ -12,7 +13,7 @@ type PullUpdater struct { GlobalCfg valid.GlobalCfg } -func (c *PullUpdater) updatePull(ctx *CommandContext, command PullCommand, res CommandResult) { +func (c *PullUpdater) updatePull(ctx *models.CommandContext, command PullCommand, res models.CommandResult) { // Log if we got any errors or failures. if res.Error != nil { ctx.Log.Err(res.Error.Error()) diff --git a/server/events/size_limited_project_command_builder.go b/server/events/size_limited_project_command_builder.go index 909dbf425..5a19e941a 100644 --- a/server/events/size_limited_project_command_builder.go +++ b/server/events/size_limited_project_command_builder.go @@ -12,7 +12,7 @@ type SizeLimitedProjectCommandBuilder struct { ProjectCommandBuilder } -func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandContext) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { projects, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) if err != nil { @@ -22,7 +22,7 @@ func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *CommandCon return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { projects, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) if err != nil { diff --git a/server/events/size_limited_project_command_builder_test.go b/server/events/size_limited_project_command_builder_test.go index 7f77a64df..b99c12296 100644 --- a/server/events/size_limited_project_command_builder_test.go +++ b/server/events/size_limited_project_command_builder_test.go @@ -15,7 +15,7 @@ func TestSizeLimitedProjectCommandBuilder_autoplan(t *testing.T) { delegate := mocks.NewMockProjectCommandBuilder() - ctx := &events.CommandContext{} + ctx := &models.CommandContext{} project1 := models.ProjectCommandContext{ ProjectName: "test1", @@ -104,7 +104,7 @@ func TestSizeLimitedProjectCommandBuilder_planComment(t *testing.T) { delegate := mocks.NewMockProjectCommandBuilder() - ctx := &events.CommandContext{} + ctx := &models.CommandContext{} comment := &events.CommentCommand{} diff --git a/server/events/stale_command_handler.go b/server/events/stale_command_handler.go index 73d4e7184..dd405fdc6 100644 --- a/server/events/stale_command_handler.go +++ b/server/events/stale_command_handler.go @@ -1,6 +1,7 @@ package events import ( + "github.com/runatlantis/atlantis/server/events/models" "github.com/uber-go/tally" ) @@ -8,7 +9,7 @@ type StaleCommandHandler struct { StaleStatsScope tally.Scope } -func (s *StaleCommandHandler) CommandIsStale(ctx *CommandContext) bool { +func (s *StaleCommandHandler) CommandIsStale(ctx *models.CommandContext) bool { status := ctx.PullStatus if status != nil && status.UpdatedAt > ctx.TriggerTimestamp.Unix() { s.StaleStatsScope.Counter("dropped_commands").Inc(1) diff --git a/server/events/stale_command_handler_test.go b/server/events/stale_command_handler_test.go index 36dfc7a1c..4b4b1acf4 100644 --- a/server/events/stale_command_handler_test.go +++ b/server/events/stale_command_handler_test.go @@ -40,7 +40,7 @@ func TestStaleCommandHandler_CommandIsStale(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { RegisterMockTestingT(t) - ctx := &events.CommandContext{ + ctx := &models.CommandContext{ TriggerTimestamp: c.CommandTimestamp, PullStatus: &c.PullStatus, } @@ -60,7 +60,7 @@ func TestStaleCommandHandler_CommandIsStale_NilPullModel(t *testing.T) { staleCommandHandler := &events.StaleCommandHandler{ StaleStatsScope: testScope, } - Assert(t, staleCommandHandler.CommandIsStale(&events.CommandContext{}) == false, + Assert(t, staleCommandHandler.CommandIsStale(&models.CommandContext{}) == false, "CommandIsStale returned value should be false") Assert(t, len(testScope.Snapshot().Counters()) == 0, "no counters should have started") } diff --git a/server/events/unlock_command_runner.go b/server/events/unlock_command_runner.go index f95397ef5..de758fc00 100644 --- a/server/events/unlock_command_runner.go +++ b/server/events/unlock_command_runner.go @@ -26,7 +26,7 @@ type UnlockCommandRunner struct { } func (u *UnlockCommandRunner) Run( - ctx *CommandContext, + ctx *models.CommandContext, cmd *CommentCommand, ) { baseRepo := ctx.Pull.BaseRepo diff --git a/server/events/version_command_runner.go b/server/events/version_command_runner.go index b1b7e029b..59b684d3a 100644 --- a/server/events/version_command_runner.go +++ b/server/events/version_command_runner.go @@ -28,7 +28,7 @@ type VersionCommandRunner struct { silenceVCSStatusNoProjects bool } -func (v *VersionCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { +func (v *VersionCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { var err error var projectCmds []models.ProjectCommandContext projectCmds, err = v.prjCmdBuilder.BuildVersionCommands(ctx, cmd) @@ -42,7 +42,7 @@ func (v *VersionCommandRunner) Run(ctx *CommandContext, cmd *CommentCommand) { } // Only run commands in parallel if enabled - var result CommandResult + var result models.CommandResult if v.isParallelEnabled(projectCmds) { ctx.Log.Info("Running version in parallel") result = runProjectCmdsParallel(projectCmds, v.prjCmdRunner.Version, v.parallelPoolSize) From 9b1f1a8e617e22015f25db02a09ee2c4a50a0a75 Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Thu, 24 Feb 2022 15:34:09 -0800 Subject: [PATCH 2/7] move from models to command rename CommandContext -> Context rename CommandResult -> Result --- CONTRIBUTING.md | 2 +- server/core/config/valid/repo_cfg.go | 2 +- server/events/apply_command_runner.go | 9 +-- server/events/apply_command_runner_test.go | 3 +- .../events/approve_policies_command_runner.go | 9 +-- server/events/automerger.go | 3 +- .../command_context.go => command/context.go} | 17 ++--- .../command_result.go => command/result.go} | 12 ++-- .../result_test.go} | 22 +++---- server/events/command_runner.go | 22 +++---- server/events/command_runner_internal_test.go | 5 +- server/events/db_updater.go | 3 +- .../instrumented_project_command_builder.go | 7 +- server/events/markdown_renderer.go | 2 +- server/events/markdown_renderer_test.go | 36 +++++----- .../mocks/matchers/azuredevops_event.go | 3 +- .../matchers/events_commentparseresult.go | 3 +- .../matchers/go_gitlab_mergecommentevent.go | 3 +- .../mocks/matchers/go_gitlab_mergeevent.go | 3 +- server/events/mocks/matchers/jobs_pullinfo.go | 3 +- .../mocks/matchers/logging_simplelogging.go | 3 +- .../mocks/matchers/map_of_string_to_string.go | 3 +- .../mocks/matchers/models_commandname.go | 3 +- .../mocks/matchers/models_commitstatus.go | 3 +- .../events/mocks/matchers/models_project.go | 3 +- .../matchers/models_projectcommandcontext.go | 3 +- .../mocks/matchers/models_projectresult.go | 3 +- .../mocks/matchers/models_pullrequest.go | 3 +- .../matchers/models_pullrequesteventtype.go | 3 +- server/events/mocks/matchers/models_repo.go | 3 +- server/events/mocks/matchers/models_user.go | 3 +- .../mocks/matchers/models_vcshosttype.go | 3 +- .../ptr_to_azuredevops_gitpullrequest.go | 3 +- .../ptr_to_azuredevops_gitrepository.go | 3 +- .../matchers/ptr_to_events_commandcontext.go | 22 +++---- .../matchers/ptr_to_events_commentcommand.go | 3 +- .../matchers/ptr_to_events_trylockresponse.go | 3 +- .../ptr_to_github_issuecommentevent.go | 3 +- .../matchers/ptr_to_github_pullrequest.go | 3 +- .../ptr_to_github_pullrequestevent.go | 3 +- .../matchers/ptr_to_github_repository.go | 3 +- .../matchers/ptr_to_go_gitlab_mergerequest.go | 3 +- .../matchers/ptr_to_logging_simplelogger.go | 3 +- .../matchers/ptr_to_models_commandcontext.go | 15 +++-- .../matchers/ptr_to_models_projectlock.go | 3 +- .../matchers/ptr_to_models_pullrequest.go | 3 +- .../mocks/matchers/ptr_to_models_repo.go | 3 +- server/events/mocks/matchers/slice_of_byte.go | 3 +- .../matchers/slice_of_events_pendingplan.go | 3 +- .../slice_of_models_projectcommandcontext.go | 3 +- .../events/mocks/matchers/slice_of_string.go | 3 +- server/events/mocks/matchers/time_time.go | 3 +- .../mocks/matchers/webhooks_applyresult.go | 3 +- .../events/mocks/mock_apply_command_locker.go | 17 ++--- server/events/mocks/mock_apply_handler.go | 5 +- .../mocks/mock_azuredevops_pull_getter.go | 5 +- server/events/mocks/mock_command_runner.go | 5 +- server/events/mocks/mock_comment_building.go | 3 +- server/events/mocks/mock_comment_parsing.go | 5 +- .../mocks/mock_commit_status_updater.go | 5 +- .../events/mocks/mock_custom_step_runner.go | 5 +- .../events/mocks/mock_delete_lock_command.go | 5 +- server/events/mocks/mock_env_step_runner.go | 5 +- server/events/mocks/mock_event_parsing.go | 5 +- .../events/mocks/mock_github_pull_getter.go | 5 +- .../mocks/mock_gitlab_merge_request_getter.go | 5 +- server/events/mocks/mock_job_closer.go | 3 +- server/events/mocks/mock_job_id_generator.go | 3 +- .../events/mocks/mock_job_message_sender.go | 5 +- server/events/mocks/mock_job_url_setter.go | 5 +- .../events/mocks/mock_lock_url_generator.go | 3 +- .../mocks/mock_log_stream_url_generator.go | 5 +- .../events/mocks/mock_pending_plan_finder.go | 5 +- ...mock_pre_workflows_hooks_command_runner.go | 5 +- .../mocks/mock_project_command_builder.go | 66 ++++++++++--------- .../mocks/mock_project_command_runner.go | 5 +- server/events/mocks/mock_project_lock.go | 5 +- server/events/mocks/mock_pull_cleaner.go | 5 +- .../events/mocks/mock_pull_status_fetcher.go | 5 +- server/events/mocks/mock_resource_cleaner.go | 5 +- .../mocks/mock_stale_command_checker.go | 17 ++--- server/events/mocks/mock_step_runner.go | 5 +- server/events/mocks/mock_webhooks_sender.go | 5 +- server/events/mocks/mock_working_dir.go | 5 +- .../events/mocks/mock_working_dir_locker.go | 3 +- server/events/plan_command_runner.go | 21 +++--- server/events/policy_check_command_runner.go | 11 ++-- .../pre_workflow_hooks_command_runner.go | 5 +- .../pre_workflow_hooks_command_runner_test.go | 3 +- server/events/project_command_builder.go | 35 +++++----- .../project_command_builder_internal_test.go | 7 +- server/events/project_command_builder_test.go | 23 +++---- .../events/project_command_context_builder.go | 13 ++-- .../project_command_context_builder_test.go | 3 +- .../events/project_command_pool_executor.go | 8 +-- server/events/pull_closed_executor_test.go | 5 +- server/events/pull_updater.go | 3 +- .../mocks/matchers/models_approvalstatus.go | 3 +- .../size_limited_project_command_builder.go | 5 +- ...ze_limited_project_command_builder_test.go | 5 +- server/events/stale_command_handler.go | 4 +- server/events/stale_command_handler_test.go | 10 +-- server/events/unlock_command_runner.go | 3 +- server/events/vcs/github_client_test.go | 4 +- server/events/vcs/inject.go | 6 +- server/events/vcs/instrumented_client.go | 3 +- .../mocks/matchers/models_approvalstatus.go | 3 +- .../vcs/mocks/matchers/models_commitstatus.go | 3 +- .../vcs/mocks/matchers/models_pullrequest.go | 3 +- .../matchers/models_pullrequestoptions.go | 3 +- .../events/vcs/mocks/matchers/models_repo.go | 3 +- .../matchers/ptr_to_github_pullrequest.go | 3 +- .../vcs/mocks/matchers/ptr_to_http_client.go | 3 +- .../vcs/mocks/matchers/slice_of_byte.go | 3 +- .../slice_of_ptr_to_github_checkrun.go | 3 +- .../slice_of_ptr_to_github_repostatus.go | 3 +- .../vcs/mocks/matchers/slice_of_string.go | 3 +- .../events/vcs/mocks/mock_IGithub_client.go | 5 +- server/events/vcs/mocks/mock_client.go | 5 +- .../vcs/mocks/mock_github_credentials.go | 3 +- .../mocks/mock_github_pull_request_getter.go | 5 +- server/events/version_command_runner.go | 9 ++- .../mocks/matchers/logging_simplelogging.go | 3 +- .../matchers/ptr_to_logging_simplelogger.go | 3 +- .../matchers/ptr_to_slack_authtestresponse.go | 3 +- ...ptr_to_slack_getconversationsparameters.go | 3 +- .../matchers/slack_postmessageparameters.go | 3 +- .../mocks/matchers/slice_of_slack_channel.go | 3 +- .../mocks/matchers/webhooks_applyresult.go | 3 +- server/events/webhooks/mocks/mock_sender.go | 5 +- .../webhooks/mocks/mock_slack_client.go | 5 +- .../mocks/mock_underlying_slack_client.go | 5 +- 132 files changed, 467 insertions(+), 343 deletions(-) rename server/events/{models/command_context.go => command/context.go} (74%) rename server/events/{models/command_result.go => command/result.go} (71%) rename server/events/{models/command_result_test.go => command/result_test.go} (83%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 01e7a3ab7..e31457083 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,7 +160,7 @@ Each interface that is mocked has a `go:generate` command above it, e.g. //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder type ProjectCommandBuilder interface { - BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) } ``` diff --git a/server/core/config/valid/repo_cfg.go b/server/core/config/valid/repo_cfg.go index 77c692546..b12c41fbf 100644 --- a/server/core/config/valid/repo_cfg.go +++ b/server/core/config/valid/repo_cfg.go @@ -154,7 +154,7 @@ func (r RepoCfg) ValidatePRWorkflows(workflows map[string]Workflow, allowedWorkf return err } } - + if len(allowedWorkflows) == 0 { return nil } diff --git a/server/events/apply_command_runner.go b/server/events/apply_command_runner.go index dfa5459ad..5ffef5369 100644 --- a/server/events/apply_command_runner.go +++ b/server/events/apply_command_runner.go @@ -3,6 +3,7 @@ package events import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/core/locking" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -62,7 +63,7 @@ type ApplyCommandRunner struct { silenceVCSStatusNoProjects bool } -func (a *ApplyCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { +func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { var err error baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -118,7 +119,7 @@ func (a *ApplyCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, cmd.CommandName()); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - a.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) + a.pullUpdater.updatePull(ctx, cmd, command.Result{Error: err}) return } @@ -138,7 +139,7 @@ func (a *ApplyCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand } // Only run commands in parallel if enabled - var result models.CommandResult + var result command.Result if a.isParallelEnabled(projectCmds) { ctx.Log.Info("Running applies in parallel") result = runProjectCmdsParallel(projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize) @@ -174,7 +175,7 @@ func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []models.ProjectComma return len(projectCmds) > 0 && projectCmds[0].ParallelApplyEnabled } -func (a *ApplyCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { +func (a *ApplyCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/apply_command_runner_test.go b/server/events/apply_command_runner_test.go index ee5957449..e9240e859 100644 --- a/server/events/apply_command_runner_test.go +++ b/server/events/apply_command_runner_test.go @@ -8,6 +8,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/models/fixtures" "github.com/runatlantis/atlantis/server/logging" @@ -57,7 +58,7 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil) When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - ctx := &models.CommandContext{ + ctx := &command.Context{ User: fixtures.User, Log: logger, Pull: modelPull, diff --git a/server/events/approve_policies_command_runner.go b/server/events/approve_policies_command_runner.go index a03172439..be4f2049e 100644 --- a/server/events/approve_policies_command_runner.go +++ b/server/events/approve_policies_command_runner.go @@ -3,6 +3,7 @@ package events import ( "fmt" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -38,7 +39,7 @@ type ApprovePoliciesCommandRunner struct { silenceVCSStatusNoProjects bool } -func (a *ApprovePoliciesCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { +func (a *ApprovePoliciesCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -51,7 +52,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *models.CommandContext, cmd *Comm if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PolicyCheckCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - a.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) + a.pullUpdater.updatePull(ctx, cmd, command.Result{Error: err}) return } @@ -86,7 +87,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *models.CommandContext, cmd *Comm a.updateCommitStatus(ctx, pullStatus) } -func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *models.CommandContext, prjCmds []models.ProjectCommandContext) (result models.CommandResult) { +func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *command.Context, prjCmds []models.ProjectCommandContext) (result command.Result) { // Check if vcs user is in the owner list of the PolicySets. All projects // share the same Owners list at this time so no reason to iterate over each // project. @@ -105,7 +106,7 @@ func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *mod return } -func (a *ApprovePoliciesCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { +func (a *ApprovePoliciesCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/automerger.go b/server/events/automerger.go index f5e39989a..e5012581f 100644 --- a/server/events/automerger.go +++ b/server/events/automerger.go @@ -3,6 +3,7 @@ package events import ( "fmt" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -12,7 +13,7 @@ type AutoMerger struct { GlobalAutomerge bool } -func (c *AutoMerger) automerge(ctx *models.CommandContext, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool) { +func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool) { // We only automerge if all projects have been successfully applied. for _, p := range pullStatus.Projects { if p.Status != models.AppliedPlanStatus { diff --git a/server/events/models/command_context.go b/server/events/command/context.go similarity index 74% rename from server/events/models/command_context.go rename to server/events/command/context.go index 7d51d3b8f..da23e6c1f 100644 --- a/server/events/models/command_context.go +++ b/server/events/command/context.go @@ -1,8 +1,9 @@ -package models +package command import ( "time" + "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" "github.com/uber-go/tally" ) @@ -18,24 +19,24 @@ const ( Comment ) -// CommandContext represents the context of a command that should be executed +// Context represents the context of a command that should be executed // for a pull request. -type CommandContext struct { +type Context struct { // HeadRepo is the repository that is getting merged into the BaseRepo. // If the pull request branch is from the same repository then HeadRepo will // be the same as BaseRepo. // See https://help.github.com/articles/about-pull-request-merges/. - HeadRepo Repo - Pull PullRequest + HeadRepo models.Repo + Pull models.PullRequest Scope tally.Scope // User is the user that triggered this command. - User User + User models.User Log logging.SimpleLogging // Current PR state - PullRequestStatus PullReqStatus + PullRequestStatus models.PullReqStatus - PullStatus *PullStatus + PullStatus *models.PullStatus Trigger CommandTrigger diff --git a/server/events/models/command_result.go b/server/events/command/result.go similarity index 71% rename from server/events/models/command_result.go rename to server/events/command/result.go index 97fa0c216..49ba4db1c 100644 --- a/server/events/models/command_result.go +++ b/server/events/command/result.go @@ -1,10 +1,12 @@ -package models +package command -// CommandResult is the result of running a Command. -type CommandResult struct { +import "github.com/runatlantis/atlantis/server/events/models" + +// Result is the result of running a Command. +type Result struct { Error error Failure string - ProjectResults []ProjectResult + ProjectResults []models.ProjectResult // PlansDeleted is true if all plans created during this command were // deleted. This happens if automerging is enabled and one project has an // error since automerging requires all plans to succeed. @@ -13,7 +15,7 @@ type CommandResult struct { // HasErrors returns true if there were any errors during the execution, // even if it was only in one project. -func (c CommandResult) HasErrors() bool { +func (c Result) HasErrors() bool { if c.Error != nil || c.Failure != "" { return true } diff --git a/server/events/models/command_result_test.go b/server/events/command/result_test.go similarity index 83% rename from server/events/models/command_result_test.go rename to server/events/command/result_test.go index 5985efe32..a238ba977 100644 --- a/server/events/models/command_result_test.go +++ b/server/events/command/result_test.go @@ -1,4 +1,4 @@ -package models_test +package command_test import ( "errors" @@ -10,29 +10,29 @@ import ( func TestCommandResult_HasErrors(t *testing.T) { cases := map[string]struct { - cr models.CommandResult + cr command.Result exp bool }{ "error": { - cr: models.CommandResult{ + cr: command.Result{ Error: errors.New("err"), }, exp: true, }, "failure": { - cr: models.CommandResult{ + cr: command.Result{ Failure: "failure", }, exp: true, }, "empty results list": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{}, }, exp: false, }, "successful plan": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, @@ -42,7 +42,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "successful apply": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { ApplySuccess: "success", @@ -52,7 +52,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "single errored project": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { Error: errors.New("err"), @@ -62,7 +62,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: true, }, "single failed project": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { Failure: "failure", @@ -72,7 +72,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: true, }, "two successful projects": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, @@ -85,7 +85,7 @@ func TestCommandResult_HasErrors(t *testing.T) { exp: false, }, "one successful, one failed project": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, diff --git a/server/events/command_runner.go b/server/events/command_runner.go index 408d5ac6e..aa01f50d5 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -22,11 +22,11 @@ import ( "github.com/mcdafydd/go-azuredevops/azuredevops" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/metrics" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/logging" - "github.com/runatlantis/atlantis/server/lyft/feature" "github.com/runatlantis/atlantis/server/recovery" "github.com/uber-go/tally" gitlab "github.com/xanzy/go-gitlab" @@ -52,7 +52,7 @@ type CommandRunner interface { // StaleCommandChecker handles checks to validate if current command is stale and can be dropped. type StaleCommandChecker interface { // CommandIsStale returns true if currentEventTimestamp is earlier than timestamp set in DB's latest pull model. - CommandIsStale(ctx *models.CommandContext) bool + CommandIsStale(ctx *command.Context) bool } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_github_pull_getter.go GithubPullGetter @@ -81,7 +81,7 @@ type GitlabMergeRequestGetter interface { // CommentCommandRunner runs individual command workflows. type CommentCommandRunner interface { - Run(*models.CommandContext, *CommentCommand) + Run(*command.Context, *CommentCommand) } func buildCommentCommandRunner( @@ -154,7 +154,7 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo timer := scope.Timer(metrics.ExecutionTimeMetric).Start() defer timer.Stop() - ctx := &models.CommandContext{ + ctx := &command.Context{ User: user, Log: log, Scope: scope, @@ -222,7 +222,7 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead log.Err("Unable to fetch pull status, this is likely a bug.", err) } - ctx := &models.CommandContext{ + ctx := &command.Context{ User: user, Log: log, Pull: pull, @@ -343,7 +343,7 @@ func (c *DefaultCommandRunner) ensureValidRepoMetadata( return } -func (c *DefaultCommandRunner) validateCtxAndComment(ctx *models.CommandContext) bool { +func (c *DefaultCommandRunner) validateCtxAndComment(ctx *command.Context) bool { if !c.AllowForkPRs && ctx.HeadRepo.Owner != ctx.Pull.BaseRepo.Owner { if c.SilenceForkPRErrors { return false @@ -390,15 +390,13 @@ func (c *DefaultCommandRunner) logPanics(baseRepo models.Repo, pullNum int, logg var automergeComment = `Automatically merging because all plans have been successfully applied.` -type FeatureAwareCommandRunner struct { +type ForceApplyCommandRunner struct { CommandRunner - FeatureAllocator feature.Allocator - Logger logging.SimpleLogging - VCSClient vcs.Client + Logger logging.SimpleLogging + VCSClient vcs.Client } -func (f *FeatureAwareCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, cmd *CommentCommand, timestamp time.Time) { - +func (f *ForceApplyCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, cmd *CommentCommand, timestamp time.Time) { if cmd.ForceApply { warningMessage := "⚠️ WARNING ⚠️\n\n You have bypassed all apply requirements for this PR 🚀 . This can have unpredictable consequences 🙏🏽 and should only be used in an emergency 🆘 .\n\n 𝐓𝐡𝐢𝐬 𝐚𝐜𝐭𝐢𝐨𝐧 𝐰𝐢𝐥𝐥 𝐛𝐞 𝐚𝐮𝐝𝐢𝐭𝐞𝐝.\n" if commentErr := f.VCSClient.CreateComment(baseRepo, pullNum, warningMessage, ""); commentErr != nil { diff --git a/server/events/command_runner_internal_test.go b/server/events/command_runner_internal_test.go index a8d0ddf53..c99ce221b 100644 --- a/server/events/command_runner_internal_test.go +++ b/server/events/command_runner_internal_test.go @@ -3,6 +3,7 @@ package events import ( "testing" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -74,7 +75,7 @@ func TestApplyUpdateCommitStatus(t *testing.T) { cr := &ApplyCommandRunner{ commitStatusUpdater: csu, } - cr.updateCommitStatus(&models.CommandContext{}, c.pullStatus) + cr.updateCommitStatus(&command.Context{}, c.pullStatus) Equals(t, models.Repo{}, csu.CalledRepo) Equals(t, models.PullRequest{}, csu.CalledPull) Equals(t, c.expStatus, csu.CalledStatus) @@ -136,7 +137,7 @@ func TestPlanUpdateCommitStatus(t *testing.T) { cr := &PlanCommandRunner{ commitStatusUpdater: csu, } - cr.updateCommitStatus(&models.CommandContext{}, c.pullStatus) + cr.updateCommitStatus(&command.Context{}, c.pullStatus) Equals(t, models.Repo{}, csu.CalledRepo) Equals(t, models.PullRequest{}, csu.CalledPull) Equals(t, c.expStatus, csu.CalledStatus) diff --git a/server/events/db_updater.go b/server/events/db_updater.go index abf01df65..20c9c59c3 100644 --- a/server/events/db_updater.go +++ b/server/events/db_updater.go @@ -2,6 +2,7 @@ package events import ( "github.com/runatlantis/atlantis/server/core/db" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -9,7 +10,7 @@ type DBUpdater struct { DB *db.BoltDB } -func (c *DBUpdater) updateDB(ctx *models.CommandContext, pull models.PullRequest, results []models.ProjectResult) (models.PullStatus, error) { +func (c *DBUpdater) updateDB(ctx *command.Context, pull models.PullRequest, results []models.ProjectResult) (models.PullStatus, error) { // Filter out results that errored due to the directory not existing. We // don't store these in the database because they would never be "apply-able" // and so the pull request would always have errors. diff --git a/server/events/instrumented_project_command_builder.go b/server/events/instrumented_project_command_builder.go index 7fcdc6a2c..1c6e7ef0d 100644 --- a/server/events/instrumented_project_command_builder.go +++ b/server/events/instrumented_project_command_builder.go @@ -1,6 +1,7 @@ package events import ( + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/metrics" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -11,7 +12,7 @@ type InstrumentedProjectCommandBuilder struct { Logger logging.SimpleLogging } -func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -32,7 +33,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *models.Comma return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -53,7 +54,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.Co return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index b06a54774..fb796797c 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -102,7 +102,7 @@ type projectResultTmplData struct { // Render formats the data into a markdown string. // nolint: interfacer -func (m *MarkdownRenderer) Render(res models.CommandResult, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { +func (m *MarkdownRenderer) Render(res command.Result, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { commandStr := strings.Title(strings.Replace(cmdName.String(), "_", " ", -1)) common := commonData{ Command: commandStr, diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 422256538..844a766fa 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -163,7 +163,7 @@ $$$ } r := events.MarkdownRenderer{} for _, c := range cases { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) @@ -206,7 +206,7 @@ func TestRenderErr(t *testing.T) { r := events.MarkdownRenderer{} for _, c := range cases { - res := models.CommandResult{ + res := command.Result{ Error: c.Error, } for _, verbose := range []bool{true, false} { @@ -251,7 +251,7 @@ func TestRenderFailure(t *testing.T) { r := events.MarkdownRenderer{} for _, c := range cases { - res := models.CommandResult{ + res := command.Result{ Failure: c.Failure, } for _, verbose := range []bool{true, false} { @@ -269,7 +269,7 @@ func TestRenderFailure(t *testing.T) { func TestRenderErrAndFailure(t *testing.T) { r := events.MarkdownRenderer{} - res := models.CommandResult{ + res := command.Result{ Error: errors.New("error"), Failure: "failure", } @@ -906,7 +906,7 @@ $$$ r := events.MarkdownRenderer{} for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1059,7 +1059,7 @@ $$$ } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1205,7 +1205,7 @@ $$$ } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -1229,7 +1229,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { DisableMarkdownFolding: true, } - rendered := mr.Render(models.CommandResult{ + rendered := mr.Render(command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1313,7 +1313,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { GitlabSupportsCommonMark: c.GitlabCommonMarkSupport, } - rendered := mr.Render(models.CommandResult{ + rendered := mr.Render(command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1444,7 +1444,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { ApplySuccess: c.Output, } } - rendered := mr.Render(models.CommandResult{ + rendered := mr.Render(command.Result{ ProjectResults: []models.ProjectResult{pr}, }, cmd, "log", false, c.VCSHost, make(map[string]string)) @@ -1528,7 +1528,7 @@ $$$ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) - rendered := mr.Render(models.CommandResult{ + rendered := mr.Render(command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1574,7 +1574,7 @@ $$$ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) + "Plan: 1 to add, 0 to change, 0 to destroy." - rendered := mr.Render(models.CommandResult{ + rendered := mr.Render(command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1648,11 +1648,11 @@ Plan: 1 to add, 0 to change, 0 to destroy. // all the plans as a result. func TestRenderProjectResults_PlansDeleted(t *testing.T) { cases := map[string]struct { - cr models.CommandResult + cr command.Result exp string }{ "one failure": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1669,7 +1669,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { `, }, "two failures": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -1701,7 +1701,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { `, }, "one failure, one success": { - cr: models.CommandResult{ + cr: command.Result{ ProjectResults: []models.ProjectResult{ { RepoRelDir: ".", @@ -2209,7 +2209,7 @@ $$$ r.DisableRepoLocking = true for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { @@ -2489,7 +2489,7 @@ Plan: 1 to add, 1 to change, 1 to destroy. } for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - res := models.CommandResult{ + res := command.Result{ ProjectResults: c.ProjectResults, } for _, verbose := range []bool{true, false} { diff --git a/server/events/mocks/matchers/azuredevops_event.go b/server/events/mocks/matchers/azuredevops_event.go index c6b599082..64df2a4ff 100644 --- a/server/events/mocks/matchers/azuredevops_event.go +++ b/server/events/mocks/matchers/azuredevops_event.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + azuredevops "github.com/mcdafydd/go-azuredevops/azuredevops" ) diff --git a/server/events/mocks/matchers/events_commentparseresult.go b/server/events/mocks/matchers/events_commentparseresult.go index 194da76f3..a94641eb6 100644 --- a/server/events/mocks/matchers/events_commentparseresult.go +++ b/server/events/mocks/matchers/events_commentparseresult.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + events "github.com/runatlantis/atlantis/server/events" ) diff --git a/server/events/mocks/matchers/go_gitlab_mergecommentevent.go b/server/events/mocks/matchers/go_gitlab_mergecommentevent.go index 37e79a883..55b1550aa 100644 --- a/server/events/mocks/matchers/go_gitlab_mergecommentevent.go +++ b/server/events/mocks/matchers/go_gitlab_mergecommentevent.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_gitlab "github.com/xanzy/go-gitlab" ) diff --git a/server/events/mocks/matchers/go_gitlab_mergeevent.go b/server/events/mocks/matchers/go_gitlab_mergeevent.go index 4276b1f06..364df9b4b 100644 --- a/server/events/mocks/matchers/go_gitlab_mergeevent.go +++ b/server/events/mocks/matchers/go_gitlab_mergeevent.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_gitlab "github.com/xanzy/go-gitlab" ) diff --git a/server/events/mocks/matchers/jobs_pullinfo.go b/server/events/mocks/matchers/jobs_pullinfo.go index 95e16a16f..64141c6b3 100644 --- a/server/events/mocks/matchers/jobs_pullinfo.go +++ b/server/events/mocks/matchers/jobs_pullinfo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) diff --git a/server/events/mocks/matchers/logging_simplelogging.go b/server/events/mocks/matchers/logging_simplelogging.go index 502456e7c..c3b96f61f 100644 --- a/server/events/mocks/matchers/logging_simplelogging.go +++ b/server/events/mocks/matchers/logging_simplelogging.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/events/mocks/matchers/map_of_string_to_string.go b/server/events/mocks/matchers/map_of_string_to_string.go index 65175de1a..e1683b5df 100644 --- a/server/events/mocks/matchers/map_of_string_to_string.go +++ b/server/events/mocks/matchers/map_of_string_to_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnyMapOfStringToString() map[string]string { diff --git a/server/events/mocks/matchers/models_commandname.go b/server/events/mocks/matchers/models_commandname.go index f586b4d21..a40ed59a8 100644 --- a/server/events/mocks/matchers/models_commandname.go +++ b/server/events/mocks/matchers/models_commandname.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_commitstatus.go b/server/events/mocks/matchers/models_commitstatus.go index 1e10ed782..5ebf733ee 100644 --- a/server/events/mocks/matchers/models_commitstatus.go +++ b/server/events/mocks/matchers/models_commitstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_project.go b/server/events/mocks/matchers/models_project.go index a5a87e6f0..0cc4104e5 100644 --- a/server/events/mocks/matchers/models_project.go +++ b/server/events/mocks/matchers/models_project.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_projectcommandcontext.go b/server/events/mocks/matchers/models_projectcommandcontext.go index 535f8b967..8972dd412 100644 --- a/server/events/mocks/matchers/models_projectcommandcontext.go +++ b/server/events/mocks/matchers/models_projectcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_projectresult.go b/server/events/mocks/matchers/models_projectresult.go index 0eee757ef..368a046f4 100644 --- a/server/events/mocks/matchers/models_projectresult.go +++ b/server/events/mocks/matchers/models_projectresult.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_pullrequest.go b/server/events/mocks/matchers/models_pullrequest.go index 9ae2a7e92..db2666f02 100644 --- a/server/events/mocks/matchers/models_pullrequest.go +++ b/server/events/mocks/matchers/models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_pullrequesteventtype.go b/server/events/mocks/matchers/models_pullrequesteventtype.go index 5952b4189..70d8f9e98 100644 --- a/server/events/mocks/matchers/models_pullrequesteventtype.go +++ b/server/events/mocks/matchers/models_pullrequesteventtype.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_repo.go b/server/events/mocks/matchers/models_repo.go index fd44665f8..2ca60819c 100644 --- a/server/events/mocks/matchers/models_repo.go +++ b/server/events/mocks/matchers/models_repo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_user.go b/server/events/mocks/matchers/models_user.go index 0aa92b5d8..e9bf1384b 100644 --- a/server/events/mocks/matchers/models_user.go +++ b/server/events/mocks/matchers/models_user.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/models_vcshosttype.go b/server/events/mocks/matchers/models_vcshosttype.go index a54447f7d..e9af870aa 100644 --- a/server/events/mocks/matchers/models_vcshosttype.go +++ b/server/events/mocks/matchers/models_vcshosttype.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/ptr_to_azuredevops_gitpullrequest.go b/server/events/mocks/matchers/ptr_to_azuredevops_gitpullrequest.go index 7a3bf3a69..e6dcaa96a 100644 --- a/server/events/mocks/matchers/ptr_to_azuredevops_gitpullrequest.go +++ b/server/events/mocks/matchers/ptr_to_azuredevops_gitpullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + azuredevops "github.com/mcdafydd/go-azuredevops/azuredevops" ) diff --git a/server/events/mocks/matchers/ptr_to_azuredevops_gitrepository.go b/server/events/mocks/matchers/ptr_to_azuredevops_gitrepository.go index d9f81edff..8b0fd47ab 100644 --- a/server/events/mocks/matchers/ptr_to_azuredevops_gitrepository.go +++ b/server/events/mocks/matchers/ptr_to_azuredevops_gitrepository.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + azuredevops "github.com/mcdafydd/go-azuredevops/azuredevops" ) diff --git a/server/events/mocks/matchers/ptr_to_events_commandcontext.go b/server/events/mocks/matchers/ptr_to_events_commandcontext.go index 84b5b2533..98eee775b 100644 --- a/server/events/mocks/matchers/ptr_to_events_commandcontext.go +++ b/server/events/mocks/matchers/ptr_to_events_commandcontext.go @@ -2,32 +2,32 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyPtrToEventsCommandContext() *models.CommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*models.CommandContext))(nil)).Elem())) - var nullValue *models.CommandContext +func AnyPtrToEventsCommandContext() *command.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*command.Context))(nil)).Elem())) + var nullValue *command.Context return nullValue } -func EqPtrToEventsCommandContext(value *models.CommandContext) *models.CommandContext { +func EqPtrToEventsCommandContext(value *command.Context) *command.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue *models.CommandContext + var nullValue *command.Context return nullValue } -func NotEqPtrToEventsCommandContext(value *models.CommandContext) *models.CommandContext { +func NotEqPtrToEventsCommandContext(value *command.Context) *command.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue *models.CommandContext + var nullValue *command.Context return nullValue } -func PtrToEventsCommandContextThat(matcher pegomock.ArgumentMatcher) *models.CommandContext { +func PtrToEventsCommandContextThat(matcher pegomock.ArgumentMatcher) *command.Context { pegomock.RegisterMatcher(matcher) - var nullValue *models.CommandContext + var nullValue *command.Context return nullValue } diff --git a/server/events/mocks/matchers/ptr_to_events_commentcommand.go b/server/events/mocks/matchers/ptr_to_events_commentcommand.go index 55b3b5ba6..23d7794d0 100644 --- a/server/events/mocks/matchers/ptr_to_events_commentcommand.go +++ b/server/events/mocks/matchers/ptr_to_events_commentcommand.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + events "github.com/runatlantis/atlantis/server/events" ) diff --git a/server/events/mocks/matchers/ptr_to_events_trylockresponse.go b/server/events/mocks/matchers/ptr_to_events_trylockresponse.go index 71d8a4721..7abec1dcf 100644 --- a/server/events/mocks/matchers/ptr_to_events_trylockresponse.go +++ b/server/events/mocks/matchers/ptr_to_events_trylockresponse.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + events "github.com/runatlantis/atlantis/server/events" ) diff --git a/server/events/mocks/matchers/ptr_to_github_issuecommentevent.go b/server/events/mocks/matchers/ptr_to_github_issuecommentevent.go index 919b42f26..dfc9029af 100644 --- a/server/events/mocks/matchers/ptr_to_github_issuecommentevent.go +++ b/server/events/mocks/matchers/ptr_to_github_issuecommentevent.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/mocks/matchers/ptr_to_github_pullrequest.go b/server/events/mocks/matchers/ptr_to_github_pullrequest.go index d7cc48f64..0ac17c2a2 100644 --- a/server/events/mocks/matchers/ptr_to_github_pullrequest.go +++ b/server/events/mocks/matchers/ptr_to_github_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/mocks/matchers/ptr_to_github_pullrequestevent.go b/server/events/mocks/matchers/ptr_to_github_pullrequestevent.go index 5a247a90c..9bf4f7947 100644 --- a/server/events/mocks/matchers/ptr_to_github_pullrequestevent.go +++ b/server/events/mocks/matchers/ptr_to_github_pullrequestevent.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/mocks/matchers/ptr_to_github_repository.go b/server/events/mocks/matchers/ptr_to_github_repository.go index 322d3d0fd..34a0529af 100644 --- a/server/events/mocks/matchers/ptr_to_github_repository.go +++ b/server/events/mocks/matchers/ptr_to_github_repository.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/mocks/matchers/ptr_to_go_gitlab_mergerequest.go b/server/events/mocks/matchers/ptr_to_go_gitlab_mergerequest.go index 245737cfa..bece355ab 100644 --- a/server/events/mocks/matchers/ptr_to_go_gitlab_mergerequest.go +++ b/server/events/mocks/matchers/ptr_to_go_gitlab_mergerequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_gitlab "github.com/xanzy/go-gitlab" ) diff --git a/server/events/mocks/matchers/ptr_to_logging_simplelogger.go b/server/events/mocks/matchers/ptr_to_logging_simplelogger.go index cf9bb5453..e7c8b942f 100644 --- a/server/events/mocks/matchers/ptr_to_logging_simplelogger.go +++ b/server/events/mocks/matchers/ptr_to_logging_simplelogger.go @@ -2,9 +2,10 @@ package matchers import ( + "reflect" + "github.com/petergtz/pegomock" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" ) func AnyPtrToLoggingSimpleLogger() logging.SimpleLogging { diff --git a/server/events/mocks/matchers/ptr_to_models_commandcontext.go b/server/events/mocks/matchers/ptr_to_models_commandcontext.go index 877258086..bab386e87 100644 --- a/server/events/mocks/matchers/ptr_to_models_commandcontext.go +++ b/server/events/mocks/matchers/ptr_to_models_commandcontext.go @@ -2,19 +2,20 @@ package matchers import ( - "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" + + "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyPtrToModelsCommandContext() *models.CommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*models.CommandContext))(nil)).Elem())) - var nullValue *models.CommandContext +func AnyPtrToModelsCommandContext() *command.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*command.Context))(nil)).Elem())) + var nullValue *command.Context return nullValue } -func EqPtrToModelsCommandContext(value *models.CommandContext) *models.CommandContext { +func EqPtrToModelsCommandContext(value *command.Context) *command.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue *models.CommandContext + var nullValue *command.Context return nullValue } diff --git a/server/events/mocks/matchers/ptr_to_models_projectlock.go b/server/events/mocks/matchers/ptr_to_models_projectlock.go index 7b0b6f108..c33537f97 100644 --- a/server/events/mocks/matchers/ptr_to_models_projectlock.go +++ b/server/events/mocks/matchers/ptr_to_models_projectlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/ptr_to_models_pullrequest.go b/server/events/mocks/matchers/ptr_to_models_pullrequest.go index 1f8678a09..435081d1a 100644 --- a/server/events/mocks/matchers/ptr_to_models_pullrequest.go +++ b/server/events/mocks/matchers/ptr_to_models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/ptr_to_models_repo.go b/server/events/mocks/matchers/ptr_to_models_repo.go index a85a0629a..720b22214 100644 --- a/server/events/mocks/matchers/ptr_to_models_repo.go +++ b/server/events/mocks/matchers/ptr_to_models_repo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/slice_of_byte.go b/server/events/mocks/matchers/slice_of_byte.go index 951531345..7ff2e45ca 100644 --- a/server/events/mocks/matchers/slice_of_byte.go +++ b/server/events/mocks/matchers/slice_of_byte.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfByte() []byte { diff --git a/server/events/mocks/matchers/slice_of_events_pendingplan.go b/server/events/mocks/matchers/slice_of_events_pendingplan.go index 59eb3d579..b7523e455 100644 --- a/server/events/mocks/matchers/slice_of_events_pendingplan.go +++ b/server/events/mocks/matchers/slice_of_events_pendingplan.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + events "github.com/runatlantis/atlantis/server/events" ) diff --git a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go index 2eb2ecbfd..7dd1ec51b 100644 --- a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go +++ b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/mocks/matchers/slice_of_string.go b/server/events/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/events/mocks/matchers/slice_of_string.go +++ b/server/events/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/events/mocks/matchers/time_time.go b/server/events/mocks/matchers/time_time.go index 461e1dd6d..755cf1bf8 100644 --- a/server/events/mocks/matchers/time_time.go +++ b/server/events/mocks/matchers/time_time.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + time "time" ) diff --git a/server/events/mocks/matchers/webhooks_applyresult.go b/server/events/mocks/matchers/webhooks_applyresult.go index adbcf9817..6b1878e32 100644 --- a/server/events/mocks/matchers/webhooks_applyresult.go +++ b/server/events/mocks/matchers/webhooks_applyresult.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + webhooks "github.com/runatlantis/atlantis/server/events/webhooks" ) diff --git a/server/events/mocks/mock_apply_command_locker.go b/server/events/mocks/mock_apply_command_locker.go index 1e932abde..28c3cd441 100644 --- a/server/events/mocks/mock_apply_command_locker.go +++ b/server/events/mocks/mock_apply_command_locker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) type MockApplyCommandLocker struct { @@ -25,7 +26,7 @@ func NewMockApplyCommandLocker(options ...pegomock.Option) *MockApplyCommandLock func (mock *MockApplyCommandLocker) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockApplyCommandLocker) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockApplyCommandLocker) IsDisabled(ctx *models.CommandContext) bool { +func (mock *MockApplyCommandLocker) IsDisabled(ctx *command.Context) bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockApplyCommandLocker().") } @@ -77,7 +78,7 @@ type VerifierMockApplyCommandLocker struct { timeout time.Duration } -func (verifier *VerifierMockApplyCommandLocker) IsDisabled(ctx *models.CommandContext) *MockApplyCommandLocker_IsDisabled_OngoingVerification { +func (verifier *VerifierMockApplyCommandLocker) IsDisabled(ctx *command.Context) *MockApplyCommandLocker_IsDisabled_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsDisabled", params, verifier.timeout) return &MockApplyCommandLocker_IsDisabled_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -88,17 +89,17 @@ type MockApplyCommandLocker_IsDisabled_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetCapturedArguments() *models.CommandContext { +func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetCapturedArguments() *command.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { +func (c *MockApplyCommandLocker_IsDisabled_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } } return diff --git a/server/events/mocks/mock_apply_handler.go b/server/events/mocks/mock_apply_handler.go index d9a62b29f..fb303e9bc 100644 --- a/server/events/mocks/mock_apply_handler.go +++ b/server/events/mocks/mock_apply_handler.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockApplyRequirement struct { diff --git a/server/events/mocks/mock_azuredevops_pull_getter.go b/server/events/mocks/mock_azuredevops_pull_getter.go index 5f7dde582..03aa6267e 100644 --- a/server/events/mocks/mock_azuredevops_pull_getter.go +++ b/server/events/mocks/mock_azuredevops_pull_getter.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + azuredevops "github.com/mcdafydd/go-azuredevops/azuredevops" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockAzureDevopsPullGetter struct { diff --git a/server/events/mocks/mock_command_runner.go b/server/events/mocks/mock_command_runner.go index 80890c1af..ec7b5587c 100644 --- a/server/events/mocks/mock_command_runner.go +++ b/server/events/mocks/mock_command_runner.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockCommandRunner struct { diff --git a/server/events/mocks/mock_comment_building.go b/server/events/mocks/mock_comment_building.go index 422140205..59c3ecbbb 100644 --- a/server/events/mocks/mock_comment_building.go +++ b/server/events/mocks/mock_comment_building.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockCommentBuilder struct { diff --git a/server/events/mocks/mock_comment_parsing.go b/server/events/mocks/mock_comment_parsing.go index f92f3abaa..dc50085b5 100644 --- a/server/events/mocks/mock_comment_parsing.go +++ b/server/events/mocks/mock_comment_parsing.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockCommentParsing struct { diff --git a/server/events/mocks/mock_commit_status_updater.go b/server/events/mocks/mock_commit_status_updater.go index 67395a36e..0e560f534 100644 --- a/server/events/mocks/mock_commit_status_updater.go +++ b/server/events/mocks/mock_commit_status_updater.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockCommitStatusUpdater struct { diff --git a/server/events/mocks/mock_custom_step_runner.go b/server/events/mocks/mock_custom_step_runner.go index 21d1fffa8..5a4f22a59 100644 --- a/server/events/mocks/mock_custom_step_runner.go +++ b/server/events/mocks/mock_custom_step_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockCustomStepRunner struct { diff --git a/server/events/mocks/mock_delete_lock_command.go b/server/events/mocks/mock_delete_lock_command.go index 42fb42b2f..405e03983 100644 --- a/server/events/mocks/mock_delete_lock_command.go +++ b/server/events/mocks/mock_delete_lock_command.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockDeleteLockCommand struct { diff --git a/server/events/mocks/mock_env_step_runner.go b/server/events/mocks/mock_env_step_runner.go index 23c17624a..1d8188d3a 100644 --- a/server/events/mocks/mock_env_step_runner.go +++ b/server/events/mocks/mock_env_step_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockEnvStepRunner struct { diff --git a/server/events/mocks/mock_event_parsing.go b/server/events/mocks/mock_event_parsing.go index 8aabb4291..0a0b4aad1 100644 --- a/server/events/mocks/mock_event_parsing.go +++ b/server/events/mocks/mock_event_parsing.go @@ -4,13 +4,14 @@ package mocks import ( + "reflect" + "time" + github "github.com/google/go-github/v31/github" azuredevops "github.com/mcdafydd/go-azuredevops/azuredevops" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" go_gitlab "github.com/xanzy/go-gitlab" - "reflect" - "time" ) type MockEventParsing struct { diff --git a/server/events/mocks/mock_github_pull_getter.go b/server/events/mocks/mock_github_pull_getter.go index 6eac00167..357e727b9 100644 --- a/server/events/mocks/mock_github_pull_getter.go +++ b/server/events/mocks/mock_github_pull_getter.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + github "github.com/google/go-github/v31/github" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockGithubPullGetter struct { diff --git a/server/events/mocks/mock_gitlab_merge_request_getter.go b/server/events/mocks/mock_gitlab_merge_request_getter.go index 96d509eb3..188559730 100644 --- a/server/events/mocks/mock_gitlab_merge_request_getter.go +++ b/server/events/mocks/mock_gitlab_merge_request_getter.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - go_gitlab "github.com/xanzy/go-gitlab" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + go_gitlab "github.com/xanzy/go-gitlab" ) type MockGitlabMergeRequestGetter struct { diff --git a/server/events/mocks/mock_job_closer.go b/server/events/mocks/mock_job_closer.go index 32c97424a..6f2c66463 100644 --- a/server/events/mocks/mock_job_closer.go +++ b/server/events/mocks/mock_job_closer.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockJobCloser struct { diff --git a/server/events/mocks/mock_job_id_generator.go b/server/events/mocks/mock_job_id_generator.go index 001d437f7..6d17130ee 100644 --- a/server/events/mocks/mock_job_id_generator.go +++ b/server/events/mocks/mock_job_id_generator.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockJobIDGenerator struct { diff --git a/server/events/mocks/mock_job_message_sender.go b/server/events/mocks/mock_job_message_sender.go index e4d0c8fef..224f05c99 100644 --- a/server/events/mocks/mock_job_message_sender.go +++ b/server/events/mocks/mock_job_message_sender.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockJobMessageSender struct { diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index b1df846f1..ad7fc6c5e 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockJobURLSetter struct { diff --git a/server/events/mocks/mock_lock_url_generator.go b/server/events/mocks/mock_lock_url_generator.go index a126da24f..5598ba2d7 100644 --- a/server/events/mocks/mock_lock_url_generator.go +++ b/server/events/mocks/mock_lock_url_generator.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockLockURLGenerator struct { diff --git a/server/events/mocks/mock_log_stream_url_generator.go b/server/events/mocks/mock_log_stream_url_generator.go index 2742aa801..0707eab5c 100644 --- a/server/events/mocks/mock_log_stream_url_generator.go +++ b/server/events/mocks/mock_log_stream_url_generator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockJobsUrlGenerator struct { diff --git a/server/events/mocks/mock_pending_plan_finder.go b/server/events/mocks/mock_pending_plan_finder.go index 7a2974dc5..31be58463 100644 --- a/server/events/mocks/mock_pending_plan_finder.go +++ b/server/events/mocks/mock_pending_plan_finder.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - events "github.com/runatlantis/atlantis/server/events" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + events "github.com/runatlantis/atlantis/server/events" ) type MockPendingPlanFinder struct { diff --git a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go index a7197944b..a73f4cfeb 100644 --- a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go +++ b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPreWorkflowHooksCommandRunner struct { diff --git a/server/events/mocks/mock_project_command_builder.go b/server/events/mocks/mock_project_command_builder.go index 78522cba0..6e4178b70 100644 --- a/server/events/mocks/mock_project_command_builder.go +++ b/server/events/mocks/mock_project_command_builder.go @@ -4,11 +4,13 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockProjectCommandBuilder struct { @@ -26,7 +28,7 @@ func NewMockProjectCommandBuilder(options ...pegomock.Option) *MockProjectComman func (mock *MockProjectCommandBuilder) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandBuilder) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -45,7 +47,7 @@ func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *models.Command return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -64,7 +66,7 @@ func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandCont return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -83,7 +85,7 @@ func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandCon return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -102,7 +104,7 @@ func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models. return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } @@ -158,7 +160,7 @@ type VerifierMockProjectCommandBuilder struct { timeout time.Duration } -func (verifier *VerifierMockProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildAutoplanCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -169,23 +171,23 @@ type MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification struct methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetCapturedArguments() *models.CommandContext { +func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetCapturedArguments() *command.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { +func (c *MockProjectCommandBuilder_BuildAutoplanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } } return } -func (verifier *VerifierMockProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildPlanCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -196,17 +198,17 @@ type MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetCapturedArguments() (*command.Context, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -216,7 +218,7 @@ func (c *MockProjectCommandBuilder_BuildPlanCommands_OngoingVerification) GetAll return } -func (verifier *VerifierMockProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApplyCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -227,17 +229,17 @@ type MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetCapturedArguments() (*command.Context, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -247,7 +249,7 @@ func (c *MockProjectCommandBuilder_BuildApplyCommands_OngoingVerification) GetAl return } -func (verifier *VerifierMockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildApprovePoliciesCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -258,17 +260,17 @@ type MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetCapturedArguments() (*command.Context, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { @@ -278,7 +280,7 @@ func (c *MockProjectCommandBuilder_BuildApprovePoliciesCommands_OngoingVerificat return } -func (verifier *VerifierMockProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification { +func (verifier *VerifierMockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification { params := []pegomock.Param{ctx, comment} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "BuildVersionCommands", params, verifier.timeout) return &MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -289,17 +291,17 @@ type MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetCapturedArguments() (*models.CommandContext, *events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetCapturedArguments() (*command.Context, *events.CommentCommand) { ctx, comment := c.GetAllCapturedArguments() return ctx[len(ctx)-1], comment[len(comment)-1] } -func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext, _param1 []*events.CommentCommand) { +func (c *MockProjectCommandBuilder_BuildVersionCommands_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context, _param1 []*events.CommentCommand) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } _param1 = make([]*events.CommentCommand, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_project_command_runner.go b/server/events/mocks/mock_project_command_runner.go index 052226a37..9fd049fdd 100644 --- a/server/events/mocks/mock_project_command_runner.go +++ b/server/events/mocks/mock_project_command_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockProjectCommandRunner struct { diff --git a/server/events/mocks/mock_project_lock.go b/server/events/mocks/mock_project_lock.go index c280b4955..c1e6109c4 100644 --- a/server/events/mocks/mock_project_lock.go +++ b/server/events/mocks/mock_project_lock.go @@ -4,12 +4,13 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" models "github.com/runatlantis/atlantis/server/events/models" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockProjectLocker struct { diff --git a/server/events/mocks/mock_pull_cleaner.go b/server/events/mocks/mock_pull_cleaner.go index 1691f8738..91d040074 100644 --- a/server/events/mocks/mock_pull_cleaner.go +++ b/server/events/mocks/mock_pull_cleaner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPullCleaner struct { diff --git a/server/events/mocks/mock_pull_status_fetcher.go b/server/events/mocks/mock_pull_status_fetcher.go index 8fca408e1..1cceabe93 100644 --- a/server/events/mocks/mock_pull_status_fetcher.go +++ b/server/events/mocks/mock_pull_status_fetcher.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPullStatusFetcher struct { diff --git a/server/events/mocks/mock_resource_cleaner.go b/server/events/mocks/mock_resource_cleaner.go index bd4d5d129..297a77433 100644 --- a/server/events/mocks/mock_resource_cleaner.go +++ b/server/events/mocks/mock_resource_cleaner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - jobs "github.com/runatlantis/atlantis/server/jobs" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) type MockResourceCleaner struct { diff --git a/server/events/mocks/mock_stale_command_checker.go b/server/events/mocks/mock_stale_command_checker.go index c716bb1c0..b6a205c6b 100644 --- a/server/events/mocks/mock_stale_command_checker.go +++ b/server/events/mocks/mock_stale_command_checker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) type MockStaleCommandChecker struct { @@ -25,7 +26,7 @@ func NewMockStaleCommandChecker(options ...pegomock.Option) *MockStaleCommandChe func (mock *MockStaleCommandChecker) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockStaleCommandChecker) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockStaleCommandChecker) CommandIsStale(ctx *models.CommandContext) bool { +func (mock *MockStaleCommandChecker) CommandIsStale(ctx *command.Context) bool { if mock == nil { panic("mock must not be nil. Use myMock := NewMockStaleCommandChecker().") } @@ -77,7 +78,7 @@ type VerifierMockStaleCommandChecker struct { timeout time.Duration } -func (verifier *VerifierMockStaleCommandChecker) CommandIsStale(ctx *models.CommandContext) *MockStaleCommandChecker_CommandIsStale_OngoingVerification { +func (verifier *VerifierMockStaleCommandChecker) CommandIsStale(ctx *command.Context) *MockStaleCommandChecker_CommandIsStale_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CommandIsStale", params, verifier.timeout) return &MockStaleCommandChecker_CommandIsStale_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -88,17 +89,17 @@ type MockStaleCommandChecker_CommandIsStale_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetCapturedArguments() *models.CommandContext { +func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetCapturedArguments() *command.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { +func (c *MockStaleCommandChecker_CommandIsStale_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } } return diff --git a/server/events/mocks/mock_step_runner.go b/server/events/mocks/mock_step_runner.go index 5fa0f7b0a..aed553c40 100644 --- a/server/events/mocks/mock_step_runner.go +++ b/server/events/mocks/mock_step_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockStepRunner struct { diff --git a/server/events/mocks/mock_webhooks_sender.go b/server/events/mocks/mock_webhooks_sender.go index fcbc85503..6a24b86ce 100644 --- a/server/events/mocks/mock_webhooks_sender.go +++ b/server/events/mocks/mock_webhooks_sender.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" webhooks "github.com/runatlantis/atlantis/server/events/webhooks" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockWebhooksSender struct { diff --git a/server/events/mocks/mock_working_dir.go b/server/events/mocks/mock_working_dir.go index d9aca75a2..e5f976a01 100644 --- a/server/events/mocks/mock_working_dir.go +++ b/server/events/mocks/mock_working_dir.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockWorkingDir struct { diff --git a/server/events/mocks/mock_working_dir_locker.go b/server/events/mocks/mock_working_dir_locker.go index 57ffe9f5d..2b8f628ff 100644 --- a/server/events/mocks/mock_working_dir_locker.go +++ b/server/events/mocks/mock_working_dir_locker.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockWorkingDirLocker struct { diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 7fe5ca78f..333637319 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -1,6 +1,7 @@ package events import ( + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -65,7 +66,7 @@ type PlanCommandRunner struct { pullStatusFetcher PullStatusFetcher } -func (p *PlanCommandRunner) runAutoplan(ctx *models.CommandContext) { +func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) { baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -74,7 +75,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *models.CommandContext) { if statusErr := p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - p.pullUpdater.updatePull(ctx, AutoplanCommand{}, models.CommandResult{Error: err}) + p.pullUpdater.updatePull(ctx, AutoplanCommand{}, command.Result{Error: err}) return } @@ -106,7 +107,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *models.CommandContext) { } // Only run commands in parallel if enabled - var result models.CommandResult + var result command.Result if p.isParallelEnabled(projectCmds) { ctx.Log.Info("Running plans in parallel") result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize) @@ -145,7 +146,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *models.CommandContext) { } } -func (p *PlanCommandRunner) run(ctx *models.CommandContext, cmd *CommentCommand) { +func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { var err error baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull @@ -159,7 +160,7 @@ func (p *PlanCommandRunner) run(ctx *models.CommandContext, cmd *CommentCommand) if statusErr := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } - p.pullUpdater.updatePull(ctx, cmd, models.CommandResult{Error: err}) + p.pullUpdater.updatePull(ctx, cmd, command.Result{Error: err}) return } @@ -180,7 +181,7 @@ func (p *PlanCommandRunner) run(ctx *models.CommandContext, cmd *CommentCommand) projectCmds, policyCheckCmds := p.partitionProjectCmds(ctx, projectCmds) // Only run commands in parallel if enabled - var result models.CommandResult + var result command.Result if p.isParallelEnabled(projectCmds) { ctx.Log.Info("Running applies in parallel") result = runProjectCmdsParallel(projectCmds, p.prjCmdRunner.Plan, p.parallelPoolSize) @@ -216,7 +217,7 @@ func (p *PlanCommandRunner) run(ctx *models.CommandContext, cmd *CommentCommand) } } -func (p *PlanCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { +func (p *PlanCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { if ctx.Trigger == models.Auto { p.runAutoplan(ctx) } else { @@ -224,7 +225,7 @@ func (p *PlanCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) } } -func (p *PlanCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { +func (p *PlanCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus @@ -252,7 +253,7 @@ func (p *PlanCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullS } // deletePlans deletes all plans generated in this ctx. -func (p *PlanCommandRunner) deletePlans(ctx *models.CommandContext) { +func (p *PlanCommandRunner) deletePlans(ctx *command.Context) { pullDir, err := p.workingDir.GetPullDir(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { ctx.Log.Err("getting pull dir: %s", err) @@ -263,7 +264,7 @@ func (p *PlanCommandRunner) deletePlans(ctx *models.CommandContext) { } func (p *PlanCommandRunner) partitionProjectCmds( - ctx *models.CommandContext, + ctx *command.Context, cmds []models.ProjectCommandContext, ) ( projectCmds []models.ProjectCommandContext, diff --git a/server/events/policy_check_command_runner.go b/server/events/policy_check_command_runner.go index 82f4e2f73..2a0162b5c 100644 --- a/server/events/policy_check_command_runner.go +++ b/server/events/policy_check_command_runner.go @@ -1,6 +1,9 @@ package events -import "github.com/runatlantis/atlantis/server/events/models" +import ( + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" +) func NewPolicyCheckCommandRunner( dbUpdater *DBUpdater, @@ -31,7 +34,7 @@ type PolicyCheckCommandRunner struct { silenceVCSStatusNoProjects bool } -func (p *PolicyCheckCommandRunner) Run(ctx *models.CommandContext, cmds []models.ProjectCommandContext) { +func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []models.ProjectCommandContext) { if len(cmds) == 0 { ctx.Log.Info("no projects to run policy_check in") if !p.silenceVCSStatusNoProjects { @@ -51,7 +54,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *models.CommandContext, cmds []models ctx.Log.Warn("unable to update commit status: %s", err) } - var result models.CommandResult + var result command.Result if p.isParallelEnabled(cmds) { ctx.Log.Info("Running policy_checks in parallel") result = runProjectCmdsParallel(cmds, p.prjCmdRunner.PolicyCheck, p.parallelPoolSize) @@ -69,7 +72,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *models.CommandContext, cmds []models p.updateCommitStatus(ctx, pullStatus) } -func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *models.CommandContext, pullStatus models.PullStatus) { +func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus models.PullStatus) { var numSuccess int var numErrored int status := models.SuccessCommitStatus diff --git a/server/events/pre_workflow_hooks_command_runner.go b/server/events/pre_workflow_hooks_command_runner.go index cd4b6cb99..ae54d1618 100644 --- a/server/events/pre_workflow_hooks_command_runner.go +++ b/server/events/pre_workflow_hooks_command_runner.go @@ -3,6 +3,7 @@ package events import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -10,7 +11,7 @@ import ( //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_pre_workflows_hooks_command_runner.go PreWorkflowHooksCommandRunner type PreWorkflowHooksCommandRunner interface { - RunPreHooks(ctx *models.CommandContext) error + RunPreHooks(ctx *command.Context) error } // DefaultPreWorkflowHooksCommandRunner is the first step when processing a workflow hook commands. @@ -24,7 +25,7 @@ type DefaultPreWorkflowHooksCommandRunner struct { // RunPreHooks runs pre_workflow_hooks when PR is opened or updated. func (w *DefaultPreWorkflowHooksCommandRunner) RunPreHooks( - ctx *models.CommandContext, + ctx *command.Context, ) error { pull := ctx.Pull baseRepo := pull.BaseRepo diff --git a/server/events/pre_workflow_hooks_command_runner_test.go b/server/events/pre_workflow_hooks_command_runner_test.go index 49fe52949..36fba461b 100644 --- a/server/events/pre_workflow_hooks_command_runner_test.go +++ b/server/events/pre_workflow_hooks_command_runner_test.go @@ -8,6 +8,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" runtime_mocks "github.com/runatlantis/atlantis/server/core/runtime/mocks" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/models/fixtures" @@ -47,7 +48,7 @@ func TestRunPreHooks_Clone(t *testing.T) { var newPull = fixtures.Pull newPull.BaseRepo = fixtures.GithubRepo - ctx := &models.CommandContext{ + ctx := &command.Context{ Pull: newPull, HeadRepo: fixtures.GithubRepo, User: fixtures.User, diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index a73a6e897..96c3b48e3 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/config" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -118,30 +119,30 @@ func NewProjectCommandBuilderWithLimit( type ProjectPlanCommandBuilder interface { // BuildAutoplanCommands builds project commands that will run plan on // the projects determined to be modified. - BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) // BuildPlanCommands builds project plan commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectApplyCommandBuilder interface { // BuildApplyCommands builds project Apply commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildApplyCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectApprovePoliciesCommandBuilder interface { // BuildApprovePoliciesCommands builds project PolicyCheck commands for this ctx and comment. - BuildApprovePoliciesCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApprovePoliciesCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) } type ProjectVersionCommandBuilder interface { // BuildVersionCommands builds project Version commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildVersionCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildVersionCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder @@ -173,7 +174,7 @@ type DefaultProjectCommandBuilder struct { } // See ProjectCommandBuilder.BuildAutoplanCommands. -func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { projCtxs, err := p.buildPlanAllCommands(ctx, nil, false, false) if err != nil { return nil, err @@ -190,7 +191,7 @@ func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *models.Command } // See ProjectCommandBuilder.BuildPlanCommands. -func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildPlanAllCommands(ctx, cmd.Flags, cmd.Verbose, cmd.ForceApply) } @@ -199,7 +200,7 @@ func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandCont } // See ProjectCommandBuilder.BuildApplyCommands. -func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -207,11 +208,11 @@ func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *models.CommandCon return pac, err } -func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { return p.buildAllProjectCommands(ctx, cmd) } -func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -221,7 +222,7 @@ func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *models.CommandC // buildPlanAllCommands builds plan contexts for all projects we determine were // modified in this ctx. -func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *models.CommandContext, commentFlags []string, verbose bool, forceApply bool) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context, commentFlags []string, verbose bool, forceApply bool) ([]models.ProjectCommandContext, error) { // We'll need the list of modified files. modifiedFiles, err := p.VCSClient.GetModifiedFiles(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { @@ -353,7 +354,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *models.CommandC // buildProjectPlanCommand builds a plan context for a single project. // cmd must be for only one project. -func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -400,7 +401,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *models.Comma // getCfg returns the atlantis.yaml config (if it exists) for this project. If // there is no config, then projectCfg and repoCfg will be nil. -func (p *DefaultProjectCommandBuilder) getCfg(ctx *models.CommandContext, projectName string, dir string, workspace string, repoDir string) (projectsCfg []valid.Project, repoCfg *valid.RepoCfg, err error) { +func (p *DefaultProjectCommandBuilder) getCfg(ctx *command.Context, projectName string, dir string, workspace string, repoDir string) (projectsCfg []valid.Project, repoCfg *valid.RepoCfg, err error) { hasConfigFile, err := p.ParserValidator.HasRepoCfg(repoDir) if err != nil { err = errors.Wrapf(err, "looking for %s file in %q", config.AtlantisYAMLFilename, repoDir) @@ -452,7 +453,7 @@ func (p *DefaultProjectCommandBuilder) getCfg(ctx *models.CommandContext, projec // buildAllProjectCommands builds contexts for a command for every project that has // pending plans in this ctx. -func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *models.CommandContext, commentCmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Context, commentCmd *CommentCommand) ([]models.ProjectCommandContext, error) { // Lock all dirs in this pull request (instead of a single dir) because we // don't know how many dirs we'll need to run the command in. unlockFn, err := p.WorkingDirLocker.TryLockPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num) @@ -491,7 +492,7 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *models.Comma // buildProjectApplyCommand builds an apply command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -533,7 +534,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *models.Comm // buildProjectVersionCommand builds a version command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *models.CommandContext, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace @@ -575,7 +576,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *models.Co // buildProjectCommandCtx builds a context for a single or several projects identified // by the parameters. -func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *models.CommandContext, +func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Context, cmd models.CommandName, projectName string, commentFlags []string, diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index 4e2250661..0530d9bf7 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -10,6 +10,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -622,7 +623,7 @@ projects: // We run a test for each type of command. for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Log: logger, Pull: models.PullRequest{ BaseRepo: baseRepo, @@ -817,7 +818,7 @@ projects: // We run a test for each type of command, again specific projects for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Pull: models.PullRequest{ BaseRepo: baseRepo, }, @@ -1042,7 +1043,7 @@ workflows: cmd := models.PolicyCheckCommand t.Run(cmd.String(), func(t *testing.T) { - ctxs, err := builder.buildProjectCommandCtx(&models.CommandContext{ + ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Log: logger, Pull: models.PullRequest{ BaseRepo: baseRepo, diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 1301fd868..fe61ffc4b 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -11,6 +11,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" @@ -162,7 +163,7 @@ projects: logger, ) - ctxs, err := builder.BuildAutoplanCommands(&models.CommandContext{ + ctxs, err := builder.BuildAutoplanCommands(&command.Context{ PullRequestStatus: models.PullReqStatus{ Mergeable: true, }, @@ -433,12 +434,12 @@ projects: var actCtxs []models.ProjectCommandContext var err error if cmdName == models.PlanCommand { - actCtxs, err = builder.BuildPlanCommands(&models.CommandContext{ + actCtxs, err = builder.BuildPlanCommands(&command.Context{ Log: logger, Scope: scope, }, &c.Cmd) } else { - actCtxs, err = builder.BuildApplyCommands(&models.CommandContext{Log: logger, Scope: scope}, &c.Cmd) + actCtxs, err = builder.BuildApplyCommands(&command.Context{Log: logger, Scope: scope}, &c.Cmd) } if c.ExpErr != "" { @@ -586,7 +587,7 @@ projects: ) ctxs, err := builder.BuildPlanCommands( - &models.CommandContext{ + &command.Context{ Log: logger, Scope: scope, }, @@ -677,7 +678,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiApply(t *testing.T) { ) ctxs, err := builder.BuildApplyCommands( - &models.CommandContext{ + &command.Context{ Log: logger, Scope: scope, }, @@ -761,7 +762,7 @@ projects: logger, ) - ctx := &models.CommandContext{ + ctx := &command.Context{ HeadRepo: models.Repo{}, Pull: models.PullRequest{}, User: models.User{}, @@ -842,7 +843,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { var actCtxs []models.ProjectCommandContext var err error - actCtxs, err = builder.BuildPlanCommands(&models.CommandContext{ + actCtxs, err = builder.BuildPlanCommands(&command.Context{ Log: logger, Scope: scope, }, &events.CommentCommand{ @@ -1024,7 +1025,7 @@ projects: ) actCtxs, err := builder.BuildPlanCommands( - &models.CommandContext{ + &command.Context{ Log: logger, Scope: scope, }, @@ -1092,7 +1093,7 @@ projects: var actCtxs []models.ProjectCommandContext var err error - actCtxs, err = builder.BuildAutoplanCommands(&models.CommandContext{ + actCtxs, err = builder.BuildAutoplanCommands(&command.Context{ HeadRepo: models.Repo{}, Pull: models.PullRequest{}, User: models.User{}, @@ -1148,7 +1149,7 @@ func TestDefaultProjectCommandBuilder_WithPolicyCheckEnabled_BuildAutoplanComman logger, ) - ctxs, err := builder.BuildAutoplanCommands(&models.CommandContext{ + ctxs, err := builder.BuildAutoplanCommands(&command.Context{ PullRequestStatus: models.PullReqStatus{ Mergeable: true, }, @@ -1231,7 +1232,7 @@ func TestDefaultProjectCommandBuilder_BuildVersionCommand(t *testing.T) { ) ctxs, err := builder.BuildVersionCommands( - &models.CommandContext{ + &command.Context{ Log: logger, }, &events.CommentCommand{ diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index 1db3419fb..240879a29 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-config-inspect/tfconfig" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/uber-go/tally" ) @@ -44,7 +45,7 @@ type ContextFlags struct { type ProjectCommandContextBuilder interface { // BuildProjectContext builds project command contexts for atlantis commands BuildProjectContext( - ctx *models.CommandContext, + ctx *command.Context, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -63,7 +64,7 @@ type CommandScopedStatsProjectCommandContextBuilder struct { // BuildProjectContext builds the context and injects the appropriate command level scope after the fact. func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( - ctx *models.CommandContext, + ctx *command.Context, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -95,7 +96,7 @@ type DefaultProjectCommandContextBuilder struct { } func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( - ctx *models.CommandContext, + ctx *command.Context, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -149,7 +150,7 @@ type PolicyCheckProjectCommandContextBuilder struct { } func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( - ctx *models.CommandContext, + ctx *command.Context, cmdName models.CommandName, prjCfg valid.MergedProjectCfg, commentFlags []string, @@ -198,7 +199,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( // newProjectCommandContext is a initializer method that handles constructing the // ProjectCommandContext. -func newProjectCommandContext(ctx *models.CommandContext, +func newProjectCommandContext(ctx *command.Context, cmd models.CommandName, applyCmd string, planCmd string, @@ -277,7 +278,7 @@ func escapeArgs(args []string) []string { // Extracts required_version from Terraform configuration. // Returns nil if unable to determine version from configuration. -func getTfVersion(ctx *models.CommandContext, absProjDir string) *version.Version { +func getTfVersion(ctx *command.Context, absProjDir string) *version.Version { module, diags := tfconfig.LoadModule(absProjDir) if diags.HasErrors() { ctx.Log.Err("trying to detect required version: %s", diags.Error()) diff --git a/server/events/project_command_context_builder_test.go b/server/events/project_command_context_builder_test.go index e5ce97436..5275bd252 100644 --- a/server/events/project_command_context_builder_test.go +++ b/server/events/project_command_context_builder_test.go @@ -6,6 +6,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -37,7 +38,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { Projects: []models.ProjectStatus{}, } - commandCtx := &models.CommandContext{ + commandCtx := &command.Context{ Log: logging.NewNoopLogger(t), PullStatus: pullStatus, } diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index 502cbfe07..05b71fd63 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -13,7 +13,7 @@ func runProjectCmdsParallel( cmds []models.ProjectCommandContext, runnerFunc prjCmdRunnerFunc, poolSize int, -) models.CommandResult { +) command.Result { var results []models.ProjectResult mux := &sync.Mutex{} @@ -35,18 +35,18 @@ func runProjectCmdsParallel( } wg.Wait() - return models.CommandResult{ProjectResults: results} + return command.Result{ProjectResults: results} } func runProjectCmds( cmds []models.ProjectCommandContext, runnerFunc prjCmdRunnerFunc, -) models.CommandResult { +) command.Result { var results []models.ProjectResult for _, pCmd := range cmds { res := runnerFunc(pCmd) results = append(results, res) } - return models.CommandResult{ProjectResults: results} + return command.Result{ProjectResults: results} } diff --git a/server/events/pull_closed_executor_test.go b/server/events/pull_closed_executor_test.go index 4135f2d5e..c9c3340b2 100644 --- a/server/events/pull_closed_executor_test.go +++ b/server/events/pull_closed_executor_test.go @@ -14,11 +14,12 @@ package events_test import ( + "io/ioutil" + "testing" + "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/db" bolt "go.etcd.io/bbolt" - "io/ioutil" - "testing" "github.com/runatlantis/atlantis/server/jobs" "github.com/stretchr/testify/assert" diff --git a/server/events/pull_updater.go b/server/events/pull_updater.go index 47723d170..04b6a9a2b 100644 --- a/server/events/pull_updater.go +++ b/server/events/pull_updater.go @@ -2,6 +2,7 @@ package events import ( "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -13,7 +14,7 @@ type PullUpdater struct { GlobalCfg valid.GlobalCfg } -func (c *PullUpdater) updatePull(ctx *models.CommandContext, command PullCommand, res models.CommandResult) { +func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res command.Result) { // Log if we got any errors or failures. if res.Error != nil { ctx.Log.Err(res.Error.Error()) diff --git a/server/events/runtime/mocks/matchers/models_approvalstatus.go b/server/events/runtime/mocks/matchers/models_approvalstatus.go index 01b76dd96..e4ce9d9d7 100644 --- a/server/events/runtime/mocks/matchers/models_approvalstatus.go +++ b/server/events/runtime/mocks/matchers/models_approvalstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/size_limited_project_command_builder.go b/server/events/size_limited_project_command_builder.go index 5a19e941a..10323cc13 100644 --- a/server/events/size_limited_project_command_builder.go +++ b/server/events/size_limited_project_command_builder.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pkg/errors" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -12,7 +13,7 @@ type SizeLimitedProjectCommandBuilder struct { ProjectCommandBuilder } -func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.CommandContext) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { projects, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) if err != nil { @@ -22,7 +23,7 @@ func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *models.Com return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *models.CommandContext, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { projects, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) if err != nil { diff --git a/server/events/size_limited_project_command_builder_test.go b/server/events/size_limited_project_command_builder_test.go index b99c12296..18ad209b0 100644 --- a/server/events/size_limited_project_command_builder_test.go +++ b/server/events/size_limited_project_command_builder_test.go @@ -5,6 +5,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" @@ -15,7 +16,7 @@ func TestSizeLimitedProjectCommandBuilder_autoplan(t *testing.T) { delegate := mocks.NewMockProjectCommandBuilder() - ctx := &models.CommandContext{} + ctx := &command.Context{} project1 := models.ProjectCommandContext{ ProjectName: "test1", @@ -104,7 +105,7 @@ func TestSizeLimitedProjectCommandBuilder_planComment(t *testing.T) { delegate := mocks.NewMockProjectCommandBuilder() - ctx := &models.CommandContext{} + ctx := &command.Context{} comment := &events.CommentCommand{} diff --git a/server/events/stale_command_handler.go b/server/events/stale_command_handler.go index dd405fdc6..89d6899c0 100644 --- a/server/events/stale_command_handler.go +++ b/server/events/stale_command_handler.go @@ -1,7 +1,7 @@ package events import ( - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command" "github.com/uber-go/tally" ) @@ -9,7 +9,7 @@ type StaleCommandHandler struct { StaleStatsScope tally.Scope } -func (s *StaleCommandHandler) CommandIsStale(ctx *models.CommandContext) bool { +func (s *StaleCommandHandler) CommandIsStale(ctx *command.Context) bool { status := ctx.PullStatus if status != nil && status.UpdatedAt > ctx.TriggerTimestamp.Unix() { s.StaleStatsScope.Counter("dropped_commands").Inc(1) diff --git a/server/events/stale_command_handler_test.go b/server/events/stale_command_handler_test.go index 4b4b1acf4..324bdaeb5 100644 --- a/server/events/stale_command_handler_test.go +++ b/server/events/stale_command_handler_test.go @@ -1,13 +1,15 @@ package events_test import ( + "testing" + "time" + . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" "github.com/uber-go/tally" - "testing" - "time" ) func TestStaleCommandHandler_CommandIsStale(t *testing.T) { @@ -40,7 +42,7 @@ func TestStaleCommandHandler_CommandIsStale(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { RegisterMockTestingT(t) - ctx := &models.CommandContext{ + ctx := &command.Context{ TriggerTimestamp: c.CommandTimestamp, PullStatus: &c.PullStatus, } @@ -60,7 +62,7 @@ func TestStaleCommandHandler_CommandIsStale_NilPullModel(t *testing.T) { staleCommandHandler := &events.StaleCommandHandler{ StaleStatsScope: testScope, } - Assert(t, staleCommandHandler.CommandIsStale(&models.CommandContext{}) == false, + Assert(t, staleCommandHandler.CommandIsStale(&command.Context{}) == false, "CommandIsStale returned value should be false") Assert(t, len(testScope.Snapshot().Counters()) == 0, "no counters should have started") } diff --git a/server/events/unlock_command_runner.go b/server/events/unlock_command_runner.go index de758fc00..d6711a4f9 100644 --- a/server/events/unlock_command_runner.go +++ b/server/events/unlock_command_runner.go @@ -1,6 +1,7 @@ package events import ( + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -26,7 +27,7 @@ type UnlockCommandRunner struct { } func (u *UnlockCommandRunner) Run( - ctx *models.CommandContext, + ctx *command.Context, cmd *CommentCommand, ) { baseRepo := ctx.Pull.BaseRepo diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index 9f6a4f6f3..bb2d28375 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -506,7 +506,7 @@ func TestGithubClient_PullIsMergeable(t *testing.T) { "created_at": "2012-08-20T01:19:13Z", "updated_at": "2012-08-20T01:19:13Z" }` - checksJSON := `{ + checksJSON := `{ "check_runs": [ { "id": 4, @@ -608,7 +608,7 @@ func TestGithubClient_PullIsMergeable(t *testing.T) { Hostname: "github.com", }, }, models.PullRequest{ - Num: 1, + Num: 1, HeadCommit: "2", }) Ok(t, err) diff --git a/server/events/vcs/inject.go b/server/events/vcs/inject.go index 02518b609..46344044a 100644 --- a/server/events/vcs/inject.go +++ b/server/events/vcs/inject.go @@ -29,11 +29,11 @@ func newValidChecksFilters() []ValidChecksFilter { } func newSupplementalMergeabilityChecker( - statusFilters []ValidStatusFilter, + statusFilters []ValidStatusFilter, checksFilters []ValidChecksFilter, ) MergeabilityChecker { return &SupplementalMergabilityChecker{ - statusFilter: statusFilters, + statusFilter: statusFilters, checksFilters: checksFilters, } -} \ No newline at end of file +} diff --git a/server/events/vcs/instrumented_client.go b/server/events/vcs/instrumented_client.go index 32253074a..af5c9f45b 100644 --- a/server/events/vcs/instrumented_client.go +++ b/server/events/vcs/instrumented_client.go @@ -5,10 +5,10 @@ import ( "strconv" "github.com/google/go-github/v31/github" - "github.com/uber-go/tally" "github.com/runatlantis/atlantis/server/events/metrics" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" + "github.com/uber-go/tally" ) // NewInstrumentedGithubClient creates a client proxy responsible for gathering stats and logging @@ -112,7 +112,6 @@ func (c *InstrumentedGithubClient) GetPullRequestFromName(repoName string, repoO return pull, err } - func (c *InstrumentedGithubClient) GetRepoChecks(repo models.Repo, pull models.PullRequest) ([]*github.CheckRun, error) { scope := c.StatsScope.SubScope("get_repo_checks") logger := c.Logger.WithHistory(fmtLogSrc(repo, pull.Num)...) diff --git a/server/events/vcs/mocks/matchers/models_approvalstatus.go b/server/events/vcs/mocks/matchers/models_approvalstatus.go index 01b76dd96..e4ce9d9d7 100644 --- a/server/events/vcs/mocks/matchers/models_approvalstatus.go +++ b/server/events/vcs/mocks/matchers/models_approvalstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/vcs/mocks/matchers/models_commitstatus.go b/server/events/vcs/mocks/matchers/models_commitstatus.go index 1e10ed782..5ebf733ee 100644 --- a/server/events/vcs/mocks/matchers/models_commitstatus.go +++ b/server/events/vcs/mocks/matchers/models_commitstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/vcs/mocks/matchers/models_pullrequest.go b/server/events/vcs/mocks/matchers/models_pullrequest.go index 9ae2a7e92..db2666f02 100644 --- a/server/events/vcs/mocks/matchers/models_pullrequest.go +++ b/server/events/vcs/mocks/matchers/models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/vcs/mocks/matchers/models_pullrequestoptions.go b/server/events/vcs/mocks/matchers/models_pullrequestoptions.go index c2c240c7a..b20914719 100644 --- a/server/events/vcs/mocks/matchers/models_pullrequestoptions.go +++ b/server/events/vcs/mocks/matchers/models_pullrequestoptions.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/vcs/mocks/matchers/models_repo.go b/server/events/vcs/mocks/matchers/models_repo.go index fd44665f8..2ca60819c 100644 --- a/server/events/vcs/mocks/matchers/models_repo.go +++ b/server/events/vcs/mocks/matchers/models_repo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/vcs/mocks/matchers/ptr_to_github_pullrequest.go b/server/events/vcs/mocks/matchers/ptr_to_github_pullrequest.go index d7cc48f64..0ac17c2a2 100644 --- a/server/events/vcs/mocks/matchers/ptr_to_github_pullrequest.go +++ b/server/events/vcs/mocks/matchers/ptr_to_github_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/vcs/mocks/matchers/ptr_to_http_client.go b/server/events/vcs/mocks/matchers/ptr_to_http_client.go index 74766e888..4a4742755 100644 --- a/server/events/vcs/mocks/matchers/ptr_to_http_client.go +++ b/server/events/vcs/mocks/matchers/ptr_to_http_client.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + http "net/http" ) diff --git a/server/events/vcs/mocks/matchers/slice_of_byte.go b/server/events/vcs/mocks/matchers/slice_of_byte.go index 951531345..7ff2e45ca 100644 --- a/server/events/vcs/mocks/matchers/slice_of_byte.go +++ b/server/events/vcs/mocks/matchers/slice_of_byte.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfByte() []byte { diff --git a/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_checkrun.go b/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_checkrun.go index 52d7451ce..11852576d 100644 --- a/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_checkrun.go +++ b/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_checkrun.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_repostatus.go b/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_repostatus.go index 17c214130..e9f6fd3c2 100644 --- a/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_repostatus.go +++ b/server/events/vcs/mocks/matchers/slice_of_ptr_to_github_repostatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + github "github.com/google/go-github/v31/github" ) diff --git a/server/events/vcs/mocks/matchers/slice_of_string.go b/server/events/vcs/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/events/vcs/mocks/matchers/slice_of_string.go +++ b/server/events/vcs/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/events/vcs/mocks/mock_IGithub_client.go b/server/events/vcs/mocks/mock_IGithub_client.go index 9d6c688b6..5bc668455 100644 --- a/server/events/vcs/mocks/mock_IGithub_client.go +++ b/server/events/vcs/mocks/mock_IGithub_client.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + github "github.com/google/go-github/v31/github" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockIGithubClient struct { diff --git a/server/events/vcs/mocks/mock_client.go b/server/events/vcs/mocks/mock_client.go index 38123421b..f448da8ed 100644 --- a/server/events/vcs/mocks/mock_client.go +++ b/server/events/vcs/mocks/mock_client.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockClient struct { diff --git a/server/events/vcs/mocks/mock_github_credentials.go b/server/events/vcs/mocks/mock_github_credentials.go index d491009dc..ad7765d21 100644 --- a/server/events/vcs/mocks/mock_github_credentials.go +++ b/server/events/vcs/mocks/mock_github_credentials.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" http "net/http" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockGithubCredentials struct { diff --git a/server/events/vcs/mocks/mock_github_pull_request_getter.go b/server/events/vcs/mocks/mock_github_pull_request_getter.go index 9e3de0cfe..db05ecc19 100644 --- a/server/events/vcs/mocks/mock_github_pull_request_getter.go +++ b/server/events/vcs/mocks/mock_github_pull_request_getter.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + github "github.com/google/go-github/v31/github" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockGithubPullRequestGetter struct { diff --git a/server/events/version_command_runner.go b/server/events/version_command_runner.go index 59b684d3a..1fa6377e4 100644 --- a/server/events/version_command_runner.go +++ b/server/events/version_command_runner.go @@ -1,6 +1,9 @@ package events -import "github.com/runatlantis/atlantis/server/events/models" +import ( + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" +) func NewVersionCommandRunner( pullUpdater *PullUpdater, @@ -28,7 +31,7 @@ type VersionCommandRunner struct { silenceVCSStatusNoProjects bool } -func (v *VersionCommandRunner) Run(ctx *models.CommandContext, cmd *CommentCommand) { +func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { var err error var projectCmds []models.ProjectCommandContext projectCmds, err = v.prjCmdBuilder.BuildVersionCommands(ctx, cmd) @@ -42,7 +45,7 @@ func (v *VersionCommandRunner) Run(ctx *models.CommandContext, cmd *CommentComma } // Only run commands in parallel if enabled - var result models.CommandResult + var result command.Result if v.isParallelEnabled(projectCmds) { ctx.Log.Info("Running version in parallel") result = runProjectCmdsParallel(projectCmds, v.prjCmdRunner.Version, v.parallelPoolSize) diff --git a/server/events/webhooks/mocks/matchers/logging_simplelogging.go b/server/events/webhooks/mocks/matchers/logging_simplelogging.go index 502456e7c..c3b96f61f 100644 --- a/server/events/webhooks/mocks/matchers/logging_simplelogging.go +++ b/server/events/webhooks/mocks/matchers/logging_simplelogging.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/events/webhooks/mocks/matchers/ptr_to_logging_simplelogger.go b/server/events/webhooks/mocks/matchers/ptr_to_logging_simplelogger.go index ddb778473..49af91b55 100644 --- a/server/events/webhooks/mocks/matchers/ptr_to_logging_simplelogger.go +++ b/server/events/webhooks/mocks/matchers/ptr_to_logging_simplelogger.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/events/webhooks/mocks/matchers/ptr_to_slack_authtestresponse.go b/server/events/webhooks/mocks/matchers/ptr_to_slack_authtestresponse.go index 179abf628..958bfd2eb 100644 --- a/server/events/webhooks/mocks/matchers/ptr_to_slack_authtestresponse.go +++ b/server/events/webhooks/mocks/matchers/ptr_to_slack_authtestresponse.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + slack "github.com/nlopes/slack" ) diff --git a/server/events/webhooks/mocks/matchers/ptr_to_slack_getconversationsparameters.go b/server/events/webhooks/mocks/matchers/ptr_to_slack_getconversationsparameters.go index ca4220019..54831bd3d 100644 --- a/server/events/webhooks/mocks/matchers/ptr_to_slack_getconversationsparameters.go +++ b/server/events/webhooks/mocks/matchers/ptr_to_slack_getconversationsparameters.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + slack "github.com/nlopes/slack" ) diff --git a/server/events/webhooks/mocks/matchers/slack_postmessageparameters.go b/server/events/webhooks/mocks/matchers/slack_postmessageparameters.go index 1960cca69..e5ae68a61 100644 --- a/server/events/webhooks/mocks/matchers/slack_postmessageparameters.go +++ b/server/events/webhooks/mocks/matchers/slack_postmessageparameters.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + slack "github.com/nlopes/slack" ) diff --git a/server/events/webhooks/mocks/matchers/slice_of_slack_channel.go b/server/events/webhooks/mocks/matchers/slice_of_slack_channel.go index 0c26ce66e..37ab8bf1e 100644 --- a/server/events/webhooks/mocks/matchers/slice_of_slack_channel.go +++ b/server/events/webhooks/mocks/matchers/slice_of_slack_channel.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + slack "github.com/nlopes/slack" ) diff --git a/server/events/webhooks/mocks/matchers/webhooks_applyresult.go b/server/events/webhooks/mocks/matchers/webhooks_applyresult.go index adbcf9817..6b1878e32 100644 --- a/server/events/webhooks/mocks/matchers/webhooks_applyresult.go +++ b/server/events/webhooks/mocks/matchers/webhooks_applyresult.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + webhooks "github.com/runatlantis/atlantis/server/events/webhooks" ) diff --git a/server/events/webhooks/mocks/mock_sender.go b/server/events/webhooks/mocks/mock_sender.go index 680ab6dce..42ba6f59c 100644 --- a/server/events/webhooks/mocks/mock_sender.go +++ b/server/events/webhooks/mocks/mock_sender.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" webhooks "github.com/runatlantis/atlantis/server/events/webhooks" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockSender struct { diff --git a/server/events/webhooks/mocks/mock_slack_client.go b/server/events/webhooks/mocks/mock_slack_client.go index ef842b8cd..a1fe65a26 100644 --- a/server/events/webhooks/mocks/mock_slack_client.go +++ b/server/events/webhooks/mocks/mock_slack_client.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - webhooks "github.com/runatlantis/atlantis/server/events/webhooks" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + webhooks "github.com/runatlantis/atlantis/server/events/webhooks" ) type MockSlackClient struct { diff --git a/server/events/webhooks/mocks/mock_underlying_slack_client.go b/server/events/webhooks/mocks/mock_underlying_slack_client.go index b13b0bdb7..db558eae8 100644 --- a/server/events/webhooks/mocks/mock_underlying_slack_client.go +++ b/server/events/webhooks/mocks/mock_underlying_slack_client.go @@ -4,10 +4,11 @@ package mocks import ( - slack "github.com/nlopes/slack" - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + slack "github.com/nlopes/slack" + pegomock "github.com/petergtz/pegomock" ) type MockUnderlyingSlackClient struct { From 2949d659db3da05d56298695547c03b458bb133a Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Thu, 24 Feb 2022 16:16:36 -0800 Subject: [PATCH 3/7] moved command related helpers into command package --- .../events/events_controller_e2e_test.go | 12 +- .../events/events_controller_test.go | 15 +- .../mocks/matchers/http_responsewriter.go | 3 +- .../mocks/matchers/ptr_to_http_request.go | 3 +- .../events/mocks/matchers/slice_of_byte.go | 3 +- .../mock_azuredevops_request_validator.go | 3 +- .../mocks/mock_github_request_validator.go | 3 +- .../mock_gitlab_request_parser_validator.go | 3 +- .../events/mocks/mock_vcs_post_handler.go | 3 +- server/controllers/locks_controller_test.go | 3 +- .../templates/mocks/matchers/io_writer.go | 3 +- .../templates/mocks/mock_template_writer.go | 3 +- server/core/db/boltdb.go | 9 +- server/core/db/boltdb_test.go | 37 ++--- server/core/locking/apply_locking.go | 8 +- server/core/locking/locking.go | 7 +- server/core/locking/locking_test.go | 3 +- .../matchers/locking_applycommandlock.go | 3 +- .../locking_applycommandlockresponse.go | 3 +- .../mocks/matchers/locking_trylockresponse.go | 3 +- .../map_of_string_to_models_projectlock.go | 3 +- .../mocks/matchers/models_commandlock.go | 1 + .../mocks/matchers/models_commandname.go | 22 +-- .../locking/mocks/matchers/models_project.go | 3 +- .../mocks/matchers/models_projectlock.go | 3 +- .../mocks/matchers/models_pullrequest.go | 3 +- .../locking/mocks/matchers/models_user.go | 3 +- .../matchers/ptr_to_models_commandlock.go | 3 +- .../matchers/ptr_to_models_projectlock.go | 3 +- .../matchers/slice_of_models_projectlock.go | 3 +- .../core/locking/mocks/matchers/time_time.go | 3 +- .../locking/mocks/mock_apply_lock_checker.go | 5 +- .../core/locking/mocks/mock_apply_locker.go | 5 +- server/core/locking/mocks/mock_backend.go | 42 +++--- server/core/locking/mocks/mock_locker.go | 5 +- server/core/runtime/apply_step_runner.go | 3 +- server/core/runtime/apply_step_runner_test.go | 5 +- server/core/runtime/cache/local.go | 3 +- .../matchers/ptr_to_go_version_version.go | 3 +- .../cache/mocks/mock_key_serializer.go | 5 +- .../runtime/cache/mocks/mock_version_path.go | 5 +- .../mocks/matchers/logging_simplelogging.go | 3 +- .../mocks/matchers/map_of_string_to_string.go | 3 +- .../models_preworkflowhookcommandcontext.go | 3 +- .../matchers/models_projectcommandcontext.go | 3 +- .../mocks/matchers/models_pullrequest.go | 3 +- .../runtime/mocks/matchers/models_repo.go | 3 +- .../matchers/ptr_to_go_version_version.go | 3 +- .../matchers/ptr_to_logging_simplelogger.go | 3 +- .../runtime/mocks/matchers/slice_of_string.go | 3 +- .../mocks/mock_pre_workflows_hook_runner.go | 5 +- .../mocks/mock_pull_approved_checker.go | 5 +- .../runtime/mocks/mock_pull_status_checker.go | 5 +- server/core/runtime/mocks/mock_runner.go | 5 +- .../mocks/mock_versionedexecutorworkflow.go | 5 +- .../mocks/matchers/map_of_string_to_string.go | 3 +- .../models/mocks/matchers/models_filepath.go | 3 +- .../models/mocks/matchers/slice_of_string.go | 3 +- server/core/runtime/models/mocks/mock_exec.go | 3 +- .../runtime/models/mocks/mock_filepath.go | 5 +- server/core/runtime/plan_step_runner.go | 3 +- server/core/runtime/plan_step_runner_test.go | 5 +- .../policy/mocks/matchers/valid_policyset.go | 3 +- .../policy/mocks/mock_conftest_client.go | 5 +- server/core/runtime/runtime.go | 3 +- .../mocks/matchers/go_getter_clientoption.go | 3 +- .../mocks/matchers/logging_simplelogging.go | 3 +- .../mocks/matchers/map_of_string_to_string.go | 3 +- .../matchers/models_projectcommandcontext.go | 3 +- .../mocks/matchers/ptr_to_exec_cmd.go | 3 +- .../matchers/ptr_to_go_version_version.go | 3 +- .../matchers/ptr_to_logging_simplelogger.go | 3 +- .../mocks/matchers/slice_of_string.go | 3 +- .../terraform/mocks/mock_command_builder.go | 5 +- .../core/terraform/mocks/mock_downloader.go | 5 +- .../terraform/mocks/mock_terraform_client.go | 5 +- server/events/apply_command_runner.go | 8 +- server/events/apply_command_runner_test.go | 2 +- .../events/approve_policies_command_runner.go | 8 +- server/events/automerger.go | 4 +- server/events/command/name.go | 49 +++++++ server/events/command/result_test.go | 1 + server/events/command_runner.go | 10 +- server/events/command_runner_internal_test.go | 22 +-- server/events/command_runner_test.go | 79 +++++----- server/events/comment_parser.go | 43 +++--- server/events/comment_parser_test.go | 45 +++--- server/events/commit_status_updater.go | 19 +-- server/events/commit_status_updater_test.go | 47 +++--- server/events/event_parser.go | 17 +-- server/events/event_parser_test.go | 23 +-- server/events/markdown_renderer.go | 13 +- server/events/markdown_renderer_test.go | 135 +++++++++--------- .../mocks/matchers/models_commandname.go | 21 ++- .../mocks/mock_commit_status_updater.go | 33 ++--- server/events/mocks/mock_job_url_setter.go | 13 +- server/events/models/models.go | 50 +------ server/events/models/models_test.go | 28 ++-- server/events/plan_command_runner.go | 22 +-- server/events/policy_check_command_runner.go | 6 +- server/events/project_command_builder.go | 12 +- .../project_command_builder_internal_test.go | 16 +-- server/events/project_command_builder_test.go | 42 +++--- .../events/project_command_context_builder.go | 22 +-- .../project_command_context_builder_test.go | 6 +- .../events/project_command_pool_executor.go | 1 + server/events/project_command_runner.go | 19 +-- server/events/project_command_runner_test.go | 23 +-- server/events/pull_updater.go | 1 - .../size_limited_project_command_builder.go | 2 +- ...ze_limited_project_command_builder_test.go | 10 +- server/events/unlock_command_runner.go | 3 +- server/events/vcs/github_client_test.go | 9 +- server/events/vcs/gitlab_client.go | 3 +- server/jobs/job_url_setter.go | 9 +- server/jobs/job_url_setter_test.go | 9 +- server/jobs/mocks/matchers/chan_of_string.go | 3 +- server/jobs/mocks/matchers/io_readcloser.go | 3 +- server/jobs/mocks/matchers/jobs_job.go | 3 +- server/jobs/mocks/matchers/jobs_jobstatus.go | 3 +- server/jobs/mocks/matchers/jobs_pullinfo.go | 3 +- .../jobs/mocks/matchers/models_commandname.go | 22 +-- .../mocks/matchers/models_commitstatus.go | 3 +- .../matchers/models_projectcommandcontext.go | 3 +- server/jobs/mocks/matchers/slice_of_string.go | 3 +- server/jobs/mocks/mock_job_store.go | 5 +- .../mock_project_command_output_handler.go | 5 +- .../mocks/mock_project_job_url_generator.go | 5 +- .../jobs/mocks/mock_project_status_updater.go | 18 +-- server/jobs/mocks/mock_storage_backend.go | 3 +- .../mocks/matchers/logging_loglevel.go | 3 +- .../mocks/matchers/logging_simplelogging.go | 3 +- .../mocks/matchers/ptr_to_log_logger.go | 3 +- .../matchers/ptr_to_logging_simplelogger.go | 3 +- server/logging/mocks/mock_simple_logging.go | 5 +- .../aws/sns/mocks/matchers/slice_of_byte.go | 2 +- server/lyft/aws/sns/mocks/mock_writer.go | 3 +- server/lyft/aws/sqs/message.go | 3 +- server/lyft/aws/sqs/message_test.go | 5 +- .../aws/sqs/mocks/matchers/types_message.go | 3 +- .../aws/sqs/mocks/mock_sqs_message_handler.go | 5 +- server/lyft/aws/sqs/queue.go | 1 + server/lyft/aws/sqs/worker.go | 3 +- .../audit_project_commands_wrapper_test.go | 2 +- .../destroy_plan_step_runner_wrapper_test.go | 7 +- .../feature/mocks/matchers/feature_name.go | 3 +- server/lyft/feature/mocks/mock_allocator.go | 5 +- server/lyft/scheduled/executor_service.go | 13 +- server/server.go | 12 +- server/static/bindata_assetfs.go | 3 +- 150 files changed, 784 insertions(+), 658 deletions(-) create mode 100644 server/events/command/name.go diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index fa7059251..5c5d544c4 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -1050,12 +1050,12 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl silenceNoProjects, ) - commentCommandRunnerByCmd := map[models.CommandName]events.CommentCommandRunner{ - models.PlanCommand: planCommandRunner, - models.ApplyCommand: applyCommandRunner, - models.ApprovePoliciesCommand: approvePoliciesCommandRunner, - models.UnlockCommand: unlockCommandRunner, - models.VersionCommand: versionCommandRunner, + commentCommandRunnerByCmd := map[command.Name]events.CommentCommandRunner{ + command.Plan: planCommandRunner, + command.Apply: applyCommandRunner, + command.ApprovePolicies: approvePoliciesCommandRunner, + command.UnlockCommand: unlockCommandRunner, + command.Version: versionCommandRunner, } staleCommandChecker := mocks.NewMockStaleCommandChecker() commandRunner := &events.DefaultCommandRunner{ diff --git a/server/controllers/events/events_controller_test.go b/server/controllers/events/events_controller_test.go index 217a486a5..64703a969 100644 --- a/server/controllers/events/events_controller_test.go +++ b/server/controllers/events/events_controller_test.go @@ -17,6 +17,14 @@ import ( "bytes" "errors" "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "path/filepath" + "reflect" + "strings" + "testing" + "github.com/google/go-github/v31/github" . "github.com/petergtz/pegomock" events_controllers "github.com/runatlantis/atlantis/server/controllers/events" @@ -30,13 +38,6 @@ import ( "github.com/runatlantis/atlantis/server/metrics" . "github.com/runatlantis/atlantis/testing" gitlab "github.com/xanzy/go-gitlab" - "io/ioutil" - "net/http" - "net/http/httptest" - "path/filepath" - "reflect" - "strings" - "testing" ) const githubHeader = "X-Github-Event" diff --git a/server/controllers/events/mocks/matchers/http_responsewriter.go b/server/controllers/events/mocks/matchers/http_responsewriter.go index 1927eca53..6b5eb4dcb 100644 --- a/server/controllers/events/mocks/matchers/http_responsewriter.go +++ b/server/controllers/events/mocks/matchers/http_responsewriter.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + http "net/http" ) diff --git a/server/controllers/events/mocks/matchers/ptr_to_http_request.go b/server/controllers/events/mocks/matchers/ptr_to_http_request.go index dfbfc1867..14f45554d 100644 --- a/server/controllers/events/mocks/matchers/ptr_to_http_request.go +++ b/server/controllers/events/mocks/matchers/ptr_to_http_request.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + http "net/http" ) diff --git a/server/controllers/events/mocks/matchers/slice_of_byte.go b/server/controllers/events/mocks/matchers/slice_of_byte.go index 951531345..7ff2e45ca 100644 --- a/server/controllers/events/mocks/matchers/slice_of_byte.go +++ b/server/controllers/events/mocks/matchers/slice_of_byte.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfByte() []byte { diff --git a/server/controllers/events/mocks/mock_azuredevops_request_validator.go b/server/controllers/events/mocks/mock_azuredevops_request_validator.go index 8d100d544..cf26922fa 100644 --- a/server/controllers/events/mocks/mock_azuredevops_request_validator.go +++ b/server/controllers/events/mocks/mock_azuredevops_request_validator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" http "net/http" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockAzureDevopsRequestValidator struct { diff --git a/server/controllers/events/mocks/mock_github_request_validator.go b/server/controllers/events/mocks/mock_github_request_validator.go index e36b79d74..7b8c3e2ae 100644 --- a/server/controllers/events/mocks/mock_github_request_validator.go +++ b/server/controllers/events/mocks/mock_github_request_validator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" http "net/http" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockGithubRequestValidator struct { diff --git a/server/controllers/events/mocks/mock_gitlab_request_parser_validator.go b/server/controllers/events/mocks/mock_gitlab_request_parser_validator.go index 5abefba54..4744d2647 100644 --- a/server/controllers/events/mocks/mock_gitlab_request_parser_validator.go +++ b/server/controllers/events/mocks/mock_gitlab_request_parser_validator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" http "net/http" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockGitlabRequestParserValidator struct { diff --git a/server/controllers/events/mocks/mock_vcs_post_handler.go b/server/controllers/events/mocks/mock_vcs_post_handler.go index 9ea91b976..ca161bdb2 100644 --- a/server/controllers/events/mocks/mock_vcs_post_handler.go +++ b/server/controllers/events/mocks/mock_vcs_post_handler.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" http "net/http" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockVCSPostHandler struct { diff --git a/server/controllers/locks_controller_test.go b/server/controllers/locks_controller_test.go index f6ebd5500..3a9f1b3f9 100644 --- a/server/controllers/locks_controller_test.go +++ b/server/controllers/locks_controller_test.go @@ -22,6 +22,7 @@ import ( "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/core/locking/mocks" + "github.com/runatlantis/atlantis/server/events/command" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -304,7 +305,7 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) { // Seed the DB with a successful plan for that project (that is later discarded). _, err = db.UpdatePullWithResults(pull, []models.ProjectResult{ { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: projectPath, Workspace: workspaceName, PlanSuccess: &models.PlanSuccess{ diff --git a/server/controllers/templates/mocks/matchers/io_writer.go b/server/controllers/templates/mocks/matchers/io_writer.go index 856053322..e39a22155 100644 --- a/server/controllers/templates/mocks/matchers/io_writer.go +++ b/server/controllers/templates/mocks/matchers/io_writer.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + io "io" ) diff --git a/server/controllers/templates/mocks/mock_template_writer.go b/server/controllers/templates/mocks/mock_template_writer.go index 14a3daff5..c26626d3a 100644 --- a/server/controllers/templates/mocks/mock_template_writer.go +++ b/server/controllers/templates/mocks/mock_template_writer.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" io "io" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockTemplateWriter struct { diff --git a/server/core/db/boltdb.go b/server/core/db/boltdb.go index 51cb857d8..06d264719 100644 --- a/server/core/db/boltdb.go +++ b/server/core/db/boltdb.go @@ -11,6 +11,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" bolt "go.etcd.io/bbolt" ) @@ -173,7 +174,7 @@ func (b *BoltDB) List() ([]models.ProjectLock, error) { // LockCommand attempts to create a new lock for a CommandName. // If the lock doesn't exists, it will create a lock and return a pointer to it. // If the lock already exists, it will return an "lock already exists" error -func (b *BoltDB) LockCommand(cmdName models.CommandName, lockTime time.Time) (*models.CommandLock, error) { +func (b *BoltDB) LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) { lock := models.CommandLock{ CommandName: cmdName, LockMetadata: models.LockMetadata{ @@ -204,7 +205,7 @@ func (b *BoltDB) LockCommand(cmdName models.CommandName, lockTime time.Time) (*m // UnlockCommand removes CommandName lock if present. // If there are no lock it returns an error. -func (b *BoltDB) UnlockCommand(cmdName models.CommandName) error { +func (b *BoltDB) UnlockCommand(cmdName command.Name) error { transactionErr := b.db.Update(func(tx *bolt.Tx) error { bucket := tx.Bucket(b.globalLocksBucketName) @@ -224,7 +225,7 @@ func (b *BoltDB) UnlockCommand(cmdName models.CommandName) error { // CheckCommandLock checks if CommandName lock was set. // If the lock exists return the pointer to the lock object, otherwise return nil -func (b *BoltDB) CheckCommandLock(cmdName models.CommandName) (*models.CommandLock, error) { +func (b *BoltDB) CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) { cmdLock := models.CommandLock{} found := false @@ -453,7 +454,7 @@ func (b *BoltDB) pullKey(pull models.PullRequest) ([]byte, error) { nil } -func (b *BoltDB) commandLockKey(cmdName models.CommandName) string { +func (b *BoltDB) commandLockKey(cmdName command.Name) string { return fmt.Sprintf("%s/lock", cmdName) } diff --git a/server/core/db/boltdb_test.go b/server/core/db/boltdb_test.go index 516af6294..1038f72ed 100644 --- a/server/core/db/boltdb_test.go +++ b/server/core/db/boltdb_test.go @@ -22,6 +22,7 @@ import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/pkg/errors" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" bolt "go.etcd.io/bbolt" @@ -48,7 +49,7 @@ func TestLockCommandNotSet(t *testing.T) { t.Log("retrieving apply lock when there are none should return empty LockCommand") db, b := newTestDB() defer cleanupDB(db) - exists, err := b.CheckCommandLock(models.ApplyCommand) + exists, err := b.CheckCommandLock(command.Apply) Ok(t, err) Assert(t, exists == nil, "exp nil") } @@ -58,10 +59,10 @@ func TestLockCommandEnabled(t *testing.T) { db, b := newTestDB() defer cleanupDB(db) timeNow := time.Now() - _, err := b.LockCommand(models.ApplyCommand, timeNow) + _, err := b.LockCommand(command.Apply, timeNow) Ok(t, err) - config, err := b.CheckCommandLock(models.ApplyCommand) + config, err := b.CheckCommandLock(command.Apply) Ok(t, err) Equals(t, true, config.IsLocked()) } @@ -71,10 +72,10 @@ func TestLockCommandFail(t *testing.T) { db, b := newTestDB() defer cleanupDB(db) timeNow := time.Now() - _, err := b.LockCommand(models.ApplyCommand, timeNow) + _, err := b.LockCommand(command.Apply, timeNow) Ok(t, err) - _, err = b.LockCommand(models.ApplyCommand, timeNow) + _, err = b.LockCommand(command.Apply, timeNow) ErrEquals(t, "db transaction failed: lock already exists", err) } @@ -83,17 +84,17 @@ func TestUnlockCommandDisabled(t *testing.T) { db, b := newTestDB() defer cleanupDB(db) timeNow := time.Now() - _, err := b.LockCommand(models.ApplyCommand, timeNow) + _, err := b.LockCommand(command.Apply, timeNow) Ok(t, err) - config, err := b.CheckCommandLock(models.ApplyCommand) + config, err := b.CheckCommandLock(command.Apply) Ok(t, err) Equals(t, true, config.IsLocked()) - err = b.UnlockCommand(models.ApplyCommand) + err = b.UnlockCommand(command.Apply) Ok(t, err) - config, err = b.CheckCommandLock(models.ApplyCommand) + config, err = b.CheckCommandLock(command.Apply) Ok(t, err) Assert(t, config == nil, "exp nil object") } @@ -102,7 +103,7 @@ func TestUnlockCommandFail(t *testing.T) { t.Log("setting the apply lock") db, b := newTestDB() defer cleanupDB(db) - err := b.UnlockCommand(models.ApplyCommand) + err := b.UnlockCommand(command.Apply) ErrEquals(t, "db transaction failed: no lock exists", err) } @@ -110,7 +111,7 @@ func TestMixedLocksPresent(t *testing.T) { db, b := newTestDB() defer cleanupDB(db) timeNow := time.Now() - _, err := b.LockCommand(models.ApplyCommand, timeNow) + _, err := b.LockCommand(command.Apply, timeNow) Ok(t, err) _, _, err = b.TryLock(lock) @@ -459,7 +460,7 @@ func TestPullStatus_UpdateGet(t *testing.T) { pull, []models.ProjectResult{ { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: ".", Workspace: "default", Failure: "failure", @@ -689,20 +690,20 @@ func TestPullStatus_UpdateMerge(t *testing.T) { pull, []models.ProjectResult{ { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: "mergeme", Workspace: "default", Failure: "failure", }, { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", Failure: "failure", }, { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: "staythesame", Workspace: "default", PlanSuccess: &models.PlanSuccess{ @@ -721,20 +722,20 @@ func TestPullStatus_UpdateMerge(t *testing.T) { updateStatus, err := b.UpdatePullWithResults(pull, []models.ProjectResult{ { - Command: models.ApplyCommand, + Command: command.Apply, RepoRelDir: "mergeme", Workspace: "default", ApplySuccess: "applied!", }, { - Command: models.ApplyCommand, + Command: command.Apply, RepoRelDir: "projectname", Workspace: "default", ProjectName: "projectname", Error: errors.New("apply error"), }, { - Command: models.ApplyCommand, + Command: command.Apply, RepoRelDir: "newresult", Workspace: "default", ApplySuccess: "success!", diff --git a/server/core/locking/apply_locking.go b/server/core/locking/apply_locking.go index bb1310443..3ffc295cc 100644 --- a/server/core/locking/apply_locking.go +++ b/server/core/locking/apply_locking.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command" ) //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_apply_lock_checker.go ApplyLockChecker @@ -60,7 +60,7 @@ func (c *ApplyClient) LockApply() (ApplyCommandLock, error) { return response, errors.New("DisableApplyFlag is set; Apply commands are locked globally until flag is unset") } - applyCmdLock, err := c.backend.LockCommand(models.ApplyCommand, time.Now()) + applyCmdLock, err := c.backend.LockCommand(command.Apply, time.Now()) if err != nil { return response, err } @@ -80,7 +80,7 @@ func (c *ApplyClient) UnlockApply() error { return errors.New("apply commands are disabled until DisableApply flag is unset") } - err := c.backend.UnlockCommand(models.ApplyCommand) + err := c.backend.UnlockCommand(command.Apply) if err != nil { return err } @@ -99,7 +99,7 @@ func (c *ApplyClient) CheckApplyLock() (ApplyCommandLock, error) { }, nil } - applyCmdLock, err := c.backend.CheckCommandLock(models.ApplyCommand) + applyCmdLock, err := c.backend.CheckCommandLock(command.Apply) if err != nil { return response, err } diff --git a/server/core/locking/locking.go b/server/core/locking/locking.go index 17f6b8aad..7b92bcef7 100644 --- a/server/core/locking/locking.go +++ b/server/core/locking/locking.go @@ -20,6 +20,7 @@ import ( "regexp" "time" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -33,9 +34,9 @@ type Backend interface { GetLock(project models.Project, workspace string) (*models.ProjectLock, error) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error) - LockCommand(cmdName models.CommandName, lockTime time.Time) (*models.CommandLock, error) - UnlockCommand(cmdName models.CommandName) error - CheckCommandLock(cmdName models.CommandName) (*models.CommandLock, error) + LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) + UnlockCommand(cmdName command.Name) error + CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) } // TryLockResponse results from an attempted lock. diff --git a/server/core/locking/locking_test.go b/server/core/locking/locking_test.go index fd8ce1e32..1d2f7303c 100644 --- a/server/core/locking/locking_test.go +++ b/server/core/locking/locking_test.go @@ -24,6 +24,7 @@ import ( "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/core/locking/mocks/matchers" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -185,7 +186,7 @@ func TestGetLock_NoOpLocker(t *testing.T) { func TestApplyLocker(t *testing.T) { RegisterMockTestingT(t) applyLock := &models.CommandLock{ - CommandName: models.ApplyCommand, + CommandName: command.Apply, LockMetadata: models.LockMetadata{ UnixTime: time.Now().Unix(), }, diff --git a/server/core/locking/mocks/matchers/locking_applycommandlock.go b/server/core/locking/mocks/matchers/locking_applycommandlock.go index 4e5627062..07bbd23e2 100644 --- a/server/core/locking/mocks/matchers/locking_applycommandlock.go +++ b/server/core/locking/mocks/matchers/locking_applycommandlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + locking "github.com/runatlantis/atlantis/server/core/locking" ) diff --git a/server/core/locking/mocks/matchers/locking_applycommandlockresponse.go b/server/core/locking/mocks/matchers/locking_applycommandlockresponse.go index f54209e43..5b9faf936 100644 --- a/server/core/locking/mocks/matchers/locking_applycommandlockresponse.go +++ b/server/core/locking/mocks/matchers/locking_applycommandlockresponse.go @@ -2,9 +2,10 @@ package matchers import ( + "reflect" + "github.com/petergtz/pegomock" locking "github.com/runatlantis/atlantis/server/core/locking" - "reflect" ) func AnyLockingApplyCommandLockResponse() locking.ApplyCommandLock { diff --git a/server/core/locking/mocks/matchers/locking_trylockresponse.go b/server/core/locking/mocks/matchers/locking_trylockresponse.go index 53e9bb19d..02aaa0098 100644 --- a/server/core/locking/mocks/matchers/locking_trylockresponse.go +++ b/server/core/locking/mocks/matchers/locking_trylockresponse.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + locking "github.com/runatlantis/atlantis/server/core/locking" ) diff --git a/server/core/locking/mocks/matchers/map_of_string_to_models_projectlock.go b/server/core/locking/mocks/matchers/map_of_string_to_models_projectlock.go index eb1b54416..e541f2b22 100644 --- a/server/core/locking/mocks/matchers/map_of_string_to_models_projectlock.go +++ b/server/core/locking/mocks/matchers/map_of_string_to_models_projectlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/models_commandlock.go b/server/core/locking/mocks/matchers/models_commandlock.go index 87669404b..212dcafb1 100644 --- a/server/core/locking/mocks/matchers/models_commandlock.go +++ b/server/core/locking/mocks/matchers/models_commandlock.go @@ -3,6 +3,7 @@ package matchers import ( "reflect" + "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/models_commandname.go b/server/core/locking/mocks/matchers/models_commandname.go index f586b4d21..aec79b126 100644 --- a/server/core/locking/mocks/matchers/models_commandname.go +++ b/server/core/locking/mocks/matchers/models_commandname.go @@ -2,32 +2,32 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsCommandName() models.CommandName { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.CommandName))(nil)).Elem())) - var nullValue models.CommandName +func AnyModelsCommandName() command.Name { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.Name))(nil)).Elem())) + var nullValue command.Name return nullValue } -func EqModelsCommandName(value models.CommandName) models.CommandName { +func EqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func NotEqModelsCommandName(value models.CommandName) models.CommandName { +func NotEqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) models.CommandName { +func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) command.Name { pegomock.RegisterMatcher(matcher) - var nullValue models.CommandName + var nullValue command.Name return nullValue } diff --git a/server/core/locking/mocks/matchers/models_project.go b/server/core/locking/mocks/matchers/models_project.go index a5a87e6f0..0cc4104e5 100644 --- a/server/core/locking/mocks/matchers/models_project.go +++ b/server/core/locking/mocks/matchers/models_project.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/models_projectlock.go b/server/core/locking/mocks/matchers/models_projectlock.go index 182266c5e..64127a924 100644 --- a/server/core/locking/mocks/matchers/models_projectlock.go +++ b/server/core/locking/mocks/matchers/models_projectlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/models_pullrequest.go b/server/core/locking/mocks/matchers/models_pullrequest.go index 9ae2a7e92..db2666f02 100644 --- a/server/core/locking/mocks/matchers/models_pullrequest.go +++ b/server/core/locking/mocks/matchers/models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/models_user.go b/server/core/locking/mocks/matchers/models_user.go index 0aa92b5d8..e9bf1384b 100644 --- a/server/core/locking/mocks/matchers/models_user.go +++ b/server/core/locking/mocks/matchers/models_user.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go b/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go index fbd210aad..962a3b7df 100644 --- a/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go +++ b/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/ptr_to_models_projectlock.go b/server/core/locking/mocks/matchers/ptr_to_models_projectlock.go index 7b0b6f108..c33537f97 100644 --- a/server/core/locking/mocks/matchers/ptr_to_models_projectlock.go +++ b/server/core/locking/mocks/matchers/ptr_to_models_projectlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/slice_of_models_projectlock.go b/server/core/locking/mocks/matchers/slice_of_models_projectlock.go index f510db6e8..16932f9a1 100644 --- a/server/core/locking/mocks/matchers/slice_of_models_projectlock.go +++ b/server/core/locking/mocks/matchers/slice_of_models_projectlock.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/locking/mocks/matchers/time_time.go b/server/core/locking/mocks/matchers/time_time.go index 461e1dd6d..755cf1bf8 100644 --- a/server/core/locking/mocks/matchers/time_time.go +++ b/server/core/locking/mocks/matchers/time_time.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + time "time" ) diff --git a/server/core/locking/mocks/mock_apply_lock_checker.go b/server/core/locking/mocks/mock_apply_lock_checker.go index e133e9994..9234c4d32 100644 --- a/server/core/locking/mocks/mock_apply_lock_checker.go +++ b/server/core/locking/mocks/mock_apply_lock_checker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - locking "github.com/runatlantis/atlantis/server/core/locking" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + locking "github.com/runatlantis/atlantis/server/core/locking" ) type MockApplyLockChecker struct { diff --git a/server/core/locking/mocks/mock_apply_locker.go b/server/core/locking/mocks/mock_apply_locker.go index d8608ec1f..88e3c3897 100644 --- a/server/core/locking/mocks/mock_apply_locker.go +++ b/server/core/locking/mocks/mock_apply_locker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - locking "github.com/runatlantis/atlantis/server/core/locking" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + locking "github.com/runatlantis/atlantis/server/core/locking" ) type MockApplyLocker struct { diff --git a/server/core/locking/mocks/mock_backend.go b/server/core/locking/mocks/mock_backend.go index c2876a9cb..b86550ec8 100644 --- a/server/core/locking/mocks/mock_backend.go +++ b/server/core/locking/mocks/mock_backend.go @@ -4,10 +4,12 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockBackend struct { @@ -124,7 +126,7 @@ func (mock *MockBackend) UnlockByPull(repoFullName string, pullNum int) ([]model return ret0, ret1 } -func (mock *MockBackend) LockCommand(cmdName models.CommandName, lockTime time.Time) (*models.CommandLock, error) { +func (mock *MockBackend) LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockBackend().") } @@ -143,7 +145,7 @@ func (mock *MockBackend) LockCommand(cmdName models.CommandName, lockTime time.T return ret0, ret1 } -func (mock *MockBackend) UnlockCommand(cmdName models.CommandName) error { +func (mock *MockBackend) UnlockCommand(cmdName command.Name) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockBackend().") } @@ -158,7 +160,7 @@ func (mock *MockBackend) UnlockCommand(cmdName models.CommandName) error { return ret0 } -func (mock *MockBackend) CheckCommandLock(cmdName models.CommandName) (*models.CommandLock, error) { +func (mock *MockBackend) CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockBackend().") } @@ -351,7 +353,7 @@ func (c *MockBackend_UnlockByPull_OngoingVerification) GetAllCapturedArguments() return } -func (verifier *VerifierMockBackend) LockCommand(cmdName models.CommandName, lockTime time.Time) *MockBackend_LockCommand_OngoingVerification { +func (verifier *VerifierMockBackend) LockCommand(cmdName command.Name, lockTime time.Time) *MockBackend_LockCommand_OngoingVerification { params := []pegomock.Param{cmdName, lockTime} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "LockCommand", params, verifier.timeout) return &MockBackend_LockCommand_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -362,17 +364,17 @@ type MockBackend_LockCommand_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockBackend_LockCommand_OngoingVerification) GetCapturedArguments() (models.CommandName, time.Time) { +func (c *MockBackend_LockCommand_OngoingVerification) GetCapturedArguments() (command.Name, time.Time) { cmdName, lockTime := c.GetAllCapturedArguments() return cmdName[len(cmdName)-1], lockTime[len(lockTime)-1] } -func (c *MockBackend_LockCommand_OngoingVerification) GetAllCapturedArguments() (_param0 []models.CommandName, _param1 []time.Time) { +func (c *MockBackend_LockCommand_OngoingVerification) GetAllCapturedArguments() (_param0 []command.Name, _param1 []time.Time) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.CommandName, len(c.methodInvocations)) + _param0 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.CommandName) + _param0[u] = param.(command.Name) } _param1 = make([]time.Time, len(c.methodInvocations)) for u, param := range params[1] { @@ -382,7 +384,7 @@ func (c *MockBackend_LockCommand_OngoingVerification) GetAllCapturedArguments() return } -func (verifier *VerifierMockBackend) UnlockCommand(cmdName models.CommandName) *MockBackend_UnlockCommand_OngoingVerification { +func (verifier *VerifierMockBackend) UnlockCommand(cmdName command.Name) *MockBackend_UnlockCommand_OngoingVerification { params := []pegomock.Param{cmdName} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UnlockCommand", params, verifier.timeout) return &MockBackend_UnlockCommand_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -393,23 +395,23 @@ type MockBackend_UnlockCommand_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockBackend_UnlockCommand_OngoingVerification) GetCapturedArguments() models.CommandName { +func (c *MockBackend_UnlockCommand_OngoingVerification) GetCapturedArguments() command.Name { cmdName := c.GetAllCapturedArguments() return cmdName[len(cmdName)-1] } -func (c *MockBackend_UnlockCommand_OngoingVerification) GetAllCapturedArguments() (_param0 []models.CommandName) { +func (c *MockBackend_UnlockCommand_OngoingVerification) GetAllCapturedArguments() (_param0 []command.Name) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.CommandName, len(c.methodInvocations)) + _param0 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.CommandName) + _param0[u] = param.(command.Name) } } return } -func (verifier *VerifierMockBackend) CheckCommandLock(cmdName models.CommandName) *MockBackend_CheckCommandLock_OngoingVerification { +func (verifier *VerifierMockBackend) CheckCommandLock(cmdName command.Name) *MockBackend_CheckCommandLock_OngoingVerification { params := []pegomock.Param{cmdName} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckCommandLock", params, verifier.timeout) return &MockBackend_CheckCommandLock_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -420,17 +422,17 @@ type MockBackend_CheckCommandLock_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockBackend_CheckCommandLock_OngoingVerification) GetCapturedArguments() models.CommandName { +func (c *MockBackend_CheckCommandLock_OngoingVerification) GetCapturedArguments() command.Name { cmdName := c.GetAllCapturedArguments() return cmdName[len(cmdName)-1] } -func (c *MockBackend_CheckCommandLock_OngoingVerification) GetAllCapturedArguments() (_param0 []models.CommandName) { +func (c *MockBackend_CheckCommandLock_OngoingVerification) GetAllCapturedArguments() (_param0 []command.Name) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.CommandName, len(c.methodInvocations)) + _param0 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.CommandName) + _param0[u] = param.(command.Name) } } return diff --git a/server/core/locking/mocks/mock_locker.go b/server/core/locking/mocks/mock_locker.go index 645ca4552..2346124d3 100644 --- a/server/core/locking/mocks/mock_locker.go +++ b/server/core/locking/mocks/mock_locker.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" locking "github.com/runatlantis/atlantis/server/core/locking" models "github.com/runatlantis/atlantis/server/events/models" - "reflect" - "time" ) type MockLocker struct { diff --git a/server/core/runtime/apply_step_runner.go b/server/core/runtime/apply_step_runner.go index ed41f104f..e226632ca 100644 --- a/server/core/runtime/apply_step_runner.go +++ b/server/core/runtime/apply_step_runner.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" version "github.com/hashicorp/go-version" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -125,7 +126,7 @@ func (a *ApplyStepRunner) runRemoteApply( // updateStatusF will update the commit status and log any error. updateStatusF := func(status models.CommitStatus, url string) { - if err := a.CommitStatusUpdater.UpdateProject(ctx, models.ApplyCommand, status, url); err != nil { + if err := a.CommitStatusUpdater.UpdateProject(ctx, command.Apply, status, url); err != nil { ctx.Log.Err("unable to update status: %s", err) } } diff --git a/server/core/runtime/apply_step_runner_test.go b/server/core/runtime/apply_step_runner_test.go index f0f1e45cc..e757e42e5 100644 --- a/server/core/runtime/apply_step_runner_test.go +++ b/server/core/runtime/apply_step_runner_test.go @@ -16,6 +16,7 @@ import ( "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" + "github.com/runatlantis/atlantis/server/events/command" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -279,8 +280,8 @@ Apply complete! Resources: 0 added, 0 changed, 1 destroyed. // Check that the status was updated with the run url. runURL := "https://app.terraform.io/app/lkysow-enterprises/atlantis-tfe-test-dir2/runs/run-PiDsRYKGcerTttV2" - updater.VerifyWasCalledOnce().UpdateProject(ctx, models.ApplyCommand, models.PendingCommitStatus, runURL) - updater.VerifyWasCalledOnce().UpdateProject(ctx, models.ApplyCommand, models.SuccessCommitStatus, runURL) + updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.PendingCommitStatus, runURL) + updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Apply, models.SuccessCommitStatus, runURL) } // Test that if the plan is different, we error out. diff --git a/server/core/runtime/cache/local.go b/server/core/runtime/cache/local.go index 36efef6ce..c4ea653e4 100644 --- a/server/core/runtime/cache/local.go +++ b/server/core/runtime/cache/local.go @@ -1,8 +1,9 @@ package cache import ( - "github.com/hashicorp/go-version" "os/exec" + + "github.com/hashicorp/go-version" ) func NewLocalBinaryCache(binaryName string) ExecutionVersionCache { diff --git a/server/core/runtime/cache/mocks/matchers/ptr_to_go_version_version.go b/server/core/runtime/cache/mocks/matchers/ptr_to_go_version_version.go index bb596fe3d..038c5f8f1 100644 --- a/server/core/runtime/cache/mocks/matchers/ptr_to_go_version_version.go +++ b/server/core/runtime/cache/mocks/matchers/ptr_to_go_version_version.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_version "github.com/hashicorp/go-version" ) diff --git a/server/core/runtime/cache/mocks/mock_key_serializer.go b/server/core/runtime/cache/mocks/mock_key_serializer.go index e82f10140..89006d23f 100644 --- a/server/core/runtime/cache/mocks/mock_key_serializer.go +++ b/server/core/runtime/cache/mocks/mock_key_serializer.go @@ -4,10 +4,11 @@ package mocks import ( - go_version "github.com/hashicorp/go-version" - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + go_version "github.com/hashicorp/go-version" + pegomock "github.com/petergtz/pegomock" ) type MockKeySerializer struct { diff --git a/server/core/runtime/cache/mocks/mock_version_path.go b/server/core/runtime/cache/mocks/mock_version_path.go index 8db080d2e..22a83d33a 100644 --- a/server/core/runtime/cache/mocks/mock_version_path.go +++ b/server/core/runtime/cache/mocks/mock_version_path.go @@ -4,10 +4,11 @@ package mocks import ( - go_version "github.com/hashicorp/go-version" - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + go_version "github.com/hashicorp/go-version" + pegomock "github.com/petergtz/pegomock" ) type MockExecutionVersionCache struct { diff --git a/server/core/runtime/mocks/matchers/logging_simplelogging.go b/server/core/runtime/mocks/matchers/logging_simplelogging.go index 502456e7c..c3b96f61f 100644 --- a/server/core/runtime/mocks/matchers/logging_simplelogging.go +++ b/server/core/runtime/mocks/matchers/logging_simplelogging.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/core/runtime/mocks/matchers/map_of_string_to_string.go b/server/core/runtime/mocks/matchers/map_of_string_to_string.go index 65175de1a..e1683b5df 100644 --- a/server/core/runtime/mocks/matchers/map_of_string_to_string.go +++ b/server/core/runtime/mocks/matchers/map_of_string_to_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnyMapOfStringToString() map[string]string { diff --git a/server/core/runtime/mocks/matchers/models_preworkflowhookcommandcontext.go b/server/core/runtime/mocks/matchers/models_preworkflowhookcommandcontext.go index 8a57120c7..0b9768e67 100644 --- a/server/core/runtime/mocks/matchers/models_preworkflowhookcommandcontext.go +++ b/server/core/runtime/mocks/matchers/models_preworkflowhookcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go index 535f8b967..8972dd412 100644 --- a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/runtime/mocks/matchers/models_pullrequest.go b/server/core/runtime/mocks/matchers/models_pullrequest.go index 9ae2a7e92..db2666f02 100644 --- a/server/core/runtime/mocks/matchers/models_pullrequest.go +++ b/server/core/runtime/mocks/matchers/models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/runtime/mocks/matchers/models_repo.go b/server/core/runtime/mocks/matchers/models_repo.go index fd44665f8..2ca60819c 100644 --- a/server/core/runtime/mocks/matchers/models_repo.go +++ b/server/core/runtime/mocks/matchers/models_repo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/runtime/mocks/matchers/ptr_to_go_version_version.go b/server/core/runtime/mocks/matchers/ptr_to_go_version_version.go index bb596fe3d..038c5f8f1 100644 --- a/server/core/runtime/mocks/matchers/ptr_to_go_version_version.go +++ b/server/core/runtime/mocks/matchers/ptr_to_go_version_version.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_version "github.com/hashicorp/go-version" ) diff --git a/server/core/runtime/mocks/matchers/ptr_to_logging_simplelogger.go b/server/core/runtime/mocks/matchers/ptr_to_logging_simplelogger.go index cf9bb5453..e7c8b942f 100644 --- a/server/core/runtime/mocks/matchers/ptr_to_logging_simplelogger.go +++ b/server/core/runtime/mocks/matchers/ptr_to_logging_simplelogger.go @@ -2,9 +2,10 @@ package matchers import ( + "reflect" + "github.com/petergtz/pegomock" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" ) func AnyPtrToLoggingSimpleLogger() logging.SimpleLogging { diff --git a/server/core/runtime/mocks/matchers/slice_of_string.go b/server/core/runtime/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/core/runtime/mocks/matchers/slice_of_string.go +++ b/server/core/runtime/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/core/runtime/mocks/mock_pre_workflows_hook_runner.go b/server/core/runtime/mocks/mock_pre_workflows_hook_runner.go index ddc883491..3c13af19f 100644 --- a/server/core/runtime/mocks/mock_pre_workflows_hook_runner.go +++ b/server/core/runtime/mocks/mock_pre_workflows_hook_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPreWorkflowHookRunner struct { diff --git a/server/core/runtime/mocks/mock_pull_approved_checker.go b/server/core/runtime/mocks/mock_pull_approved_checker.go index 9c0790100..7e72f47d5 100644 --- a/server/core/runtime/mocks/mock_pull_approved_checker.go +++ b/server/core/runtime/mocks/mock_pull_approved_checker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPullApprovedChecker struct { diff --git a/server/core/runtime/mocks/mock_pull_status_checker.go b/server/core/runtime/mocks/mock_pull_status_checker.go index 2e4c91a79..319b9e2a3 100644 --- a/server/core/runtime/mocks/mock_pull_status_checker.go +++ b/server/core/runtime/mocks/mock_pull_status_checker.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockPullStatusChecker struct { diff --git a/server/core/runtime/mocks/mock_runner.go b/server/core/runtime/mocks/mock_runner.go index f3d6534a4..373cfa7f3 100644 --- a/server/core/runtime/mocks/mock_runner.go +++ b/server/core/runtime/mocks/mock_runner.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockRunner struct { diff --git a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go index a2c7939da..37e8a7a77 100644 --- a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go +++ b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go @@ -4,12 +4,13 @@ package mocks import ( + "reflect" + "time" + go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockVersionedExecutorWorkflow struct { diff --git a/server/core/runtime/models/mocks/matchers/map_of_string_to_string.go b/server/core/runtime/models/mocks/matchers/map_of_string_to_string.go index 65175de1a..e1683b5df 100644 --- a/server/core/runtime/models/mocks/matchers/map_of_string_to_string.go +++ b/server/core/runtime/models/mocks/matchers/map_of_string_to_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnyMapOfStringToString() map[string]string { diff --git a/server/core/runtime/models/mocks/matchers/models_filepath.go b/server/core/runtime/models/mocks/matchers/models_filepath.go index 3d484539a..edcd2770a 100644 --- a/server/core/runtime/models/mocks/matchers/models_filepath.go +++ b/server/core/runtime/models/mocks/matchers/models_filepath.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/core/runtime/models" ) diff --git a/server/core/runtime/models/mocks/matchers/slice_of_string.go b/server/core/runtime/models/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/core/runtime/models/mocks/matchers/slice_of_string.go +++ b/server/core/runtime/models/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/core/runtime/models/mocks/mock_exec.go b/server/core/runtime/models/mocks/mock_exec.go index 83da167ae..5b7816d4b 100644 --- a/server/core/runtime/models/mocks/mock_exec.go +++ b/server/core/runtime/models/mocks/mock_exec.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockExec struct { diff --git a/server/core/runtime/models/mocks/mock_filepath.go b/server/core/runtime/models/mocks/mock_filepath.go index 8bbc61632..a54e1f8a2 100644 --- a/server/core/runtime/models/mocks/mock_filepath.go +++ b/server/core/runtime/models/mocks/mock_filepath.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/core/runtime/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/core/runtime/models" ) type MockFilePath struct { diff --git a/server/core/runtime/plan_step_runner.go b/server/core/runtime/plan_step_runner.go index 661975642..755826136 100644 --- a/server/core/runtime/plan_step_runner.go +++ b/server/core/runtime/plan_step_runner.go @@ -10,6 +10,7 @@ import ( version "github.com/hashicorp/go-version" "github.com/pkg/errors" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) @@ -246,7 +247,7 @@ func (p *PlanStepRunner) runRemotePlan( // updateStatusF will update the commit status and log any error. updateStatusF := func(status models.CommitStatus, url string) { - if err := p.CommitStatusUpdater.UpdateProject(ctx, models.PlanCommand, status, url); err != nil { + if err := p.CommitStatusUpdater.UpdateProject(ctx, command.Plan, status, url); err != nil { ctx.Log.Err("unable to update status: %s", err) } } diff --git a/server/core/runtime/plan_step_runner_test.go b/server/core/runtime/plan_step_runner_test.go index c862a836b..7a23d0a6c 100644 --- a/server/core/runtime/plan_step_runner_test.go +++ b/server/core/runtime/plan_step_runner_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/terraform" + "github.com/runatlantis/atlantis/server/events/command" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" . "github.com/petergtz/pegomock" @@ -807,8 +808,8 @@ Plan: 0 to add, 0 to change, 1 to destroy.`, string(bytes)) // Ensure that the status was updated with the runURL. runURL := "https://app.terraform.io/app/lkysow-enterprises/atlantis-tfe-test/runs/run-is4oVvJfrkud1KvE" - updater.VerifyWasCalledOnce().UpdateProject(ctx, models.PlanCommand, models.PendingCommitStatus, runURL) - updater.VerifyWasCalledOnce().UpdateProject(ctx, models.PlanCommand, models.SuccessCommitStatus, runURL) + updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.PendingCommitStatus, runURL) + updater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.SuccessCommitStatus, runURL) }) } } diff --git a/server/core/runtime/policy/mocks/matchers/valid_policyset.go b/server/core/runtime/policy/mocks/matchers/valid_policyset.go index 4b2d633e0..6a45c052d 100644 --- a/server/core/runtime/policy/mocks/matchers/valid_policyset.go +++ b/server/core/runtime/policy/mocks/matchers/valid_policyset.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + valid "github.com/runatlantis/atlantis/server/core/config/valid" ) diff --git a/server/core/runtime/policy/mocks/mock_conftest_client.go b/server/core/runtime/policy/mocks/mock_conftest_client.go index 7b461634c..08cf94cd4 100644 --- a/server/core/runtime/policy/mocks/mock_conftest_client.go +++ b/server/core/runtime/policy/mocks/mock_conftest_client.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - valid "github.com/runatlantis/atlantis/server/core/config/valid" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + valid "github.com/runatlantis/atlantis/server/core/config/valid" ) type MockSourceResolver struct { diff --git a/server/core/runtime/runtime.go b/server/core/runtime/runtime.go index 7846104b9..b4ec991fe 100644 --- a/server/core/runtime/runtime.go +++ b/server/core/runtime/runtime.go @@ -11,6 +11,7 @@ import ( version "github.com/hashicorp/go-version" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/terraform" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" ) @@ -47,7 +48,7 @@ type AsyncTFExec interface { // StatusUpdater brings the interface from CommitStatusUpdater into this package // without causing circular imports. type StatusUpdater interface { - UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error + UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_runner.go Runner diff --git a/server/core/terraform/mocks/matchers/go_getter_clientoption.go b/server/core/terraform/mocks/matchers/go_getter_clientoption.go index c6a41e3bd..7cf1a3365 100644 --- a/server/core/terraform/mocks/matchers/go_getter_clientoption.go +++ b/server/core/terraform/mocks/matchers/go_getter_clientoption.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_getter "github.com/hashicorp/go-getter" ) diff --git a/server/core/terraform/mocks/matchers/logging_simplelogging.go b/server/core/terraform/mocks/matchers/logging_simplelogging.go index 502456e7c..c3b96f61f 100644 --- a/server/core/terraform/mocks/matchers/logging_simplelogging.go +++ b/server/core/terraform/mocks/matchers/logging_simplelogging.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/core/terraform/mocks/matchers/map_of_string_to_string.go b/server/core/terraform/mocks/matchers/map_of_string_to_string.go index 65175de1a..e1683b5df 100644 --- a/server/core/terraform/mocks/matchers/map_of_string_to_string.go +++ b/server/core/terraform/mocks/matchers/map_of_string_to_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnyMapOfStringToString() map[string]string { diff --git a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go index 535f8b967..8972dd412 100644 --- a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/core/terraform/mocks/matchers/ptr_to_exec_cmd.go b/server/core/terraform/mocks/matchers/ptr_to_exec_cmd.go index f2580a269..9d4299673 100644 --- a/server/core/terraform/mocks/matchers/ptr_to_exec_cmd.go +++ b/server/core/terraform/mocks/matchers/ptr_to_exec_cmd.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + exec "os/exec" ) diff --git a/server/core/terraform/mocks/matchers/ptr_to_go_version_version.go b/server/core/terraform/mocks/matchers/ptr_to_go_version_version.go index bb596fe3d..038c5f8f1 100644 --- a/server/core/terraform/mocks/matchers/ptr_to_go_version_version.go +++ b/server/core/terraform/mocks/matchers/ptr_to_go_version_version.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + go_version "github.com/hashicorp/go-version" ) diff --git a/server/core/terraform/mocks/matchers/ptr_to_logging_simplelogger.go b/server/core/terraform/mocks/matchers/ptr_to_logging_simplelogger.go index cf9bb5453..e7c8b942f 100644 --- a/server/core/terraform/mocks/matchers/ptr_to_logging_simplelogger.go +++ b/server/core/terraform/mocks/matchers/ptr_to_logging_simplelogger.go @@ -2,9 +2,10 @@ package matchers import ( + "reflect" + "github.com/petergtz/pegomock" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" ) func AnyPtrToLoggingSimpleLogger() logging.SimpleLogging { diff --git a/server/core/terraform/mocks/matchers/slice_of_string.go b/server/core/terraform/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/core/terraform/mocks/matchers/slice_of_string.go +++ b/server/core/terraform/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/core/terraform/mocks/mock_command_builder.go b/server/core/terraform/mocks/mock_command_builder.go index 8bc2cc39f..e8fd64784 100644 --- a/server/core/terraform/mocks/mock_command_builder.go +++ b/server/core/terraform/mocks/mock_command_builder.go @@ -4,11 +4,12 @@ package mocks import ( - go_version "github.com/hashicorp/go-version" - pegomock "github.com/petergtz/pegomock" exec "os/exec" "reflect" "time" + + go_version "github.com/hashicorp/go-version" + pegomock "github.com/petergtz/pegomock" ) type MockcommandBuilder struct { diff --git a/server/core/terraform/mocks/mock_downloader.go b/server/core/terraform/mocks/mock_downloader.go index 7d5719ccd..e18a7f046 100644 --- a/server/core/terraform/mocks/mock_downloader.go +++ b/server/core/terraform/mocks/mock_downloader.go @@ -4,10 +4,11 @@ package mocks import ( - go_getter "github.com/hashicorp/go-getter" - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + go_getter "github.com/hashicorp/go-getter" + pegomock "github.com/petergtz/pegomock" ) type MockDownloader struct { diff --git a/server/core/terraform/mocks/mock_terraform_client.go b/server/core/terraform/mocks/mock_terraform_client.go index 633844676..99109b89b 100644 --- a/server/core/terraform/mocks/mock_terraform_client.go +++ b/server/core/terraform/mocks/mock_terraform_client.go @@ -4,12 +4,13 @@ package mocks import ( + "reflect" + "time" + go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" - "time" ) type MockClient struct { diff --git a/server/events/apply_command_runner.go b/server/events/apply_command_runner.go index 5ffef5369..d616b4cec 100644 --- a/server/events/apply_command_runner.go +++ b/server/events/apply_command_runner.go @@ -78,7 +78,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { if locked { ctx.Log.Info("ignoring apply command since apply disabled globally") - if err := a.vcsClient.CreateComment(baseRepo, pull.Num, applyDisabledComment, models.ApplyCommand.String()); err != nil { + if err := a.vcsClient.CreateComment(baseRepo, pull.Num, applyDisabledComment, command.Apply.String()); err != nil { ctx.Log.Err("unable to comment on pull request: %s", err) } @@ -87,7 +87,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { if a.DisableApplyAll && !cmd.IsForSpecificProject() { ctx.Log.Info("ignoring apply command without flags since apply all is disabled") - if err := a.vcsClient.CreateComment(baseRepo, pull.Num, applyAllDisabledComment, models.ApplyCommand.String()); err != nil { + if err := a.vcsClient.CreateComment(baseRepo, pull.Num, applyAllDisabledComment, command.Apply.String()); err != nil { ctx.Log.Err("unable to comment on pull request: %s", err) } @@ -131,7 +131,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { // with 0/0 projects applied successfully because some users require // the Atlantis status to be passing for all pull requests. ctx.Log.Debug("setting VCS status to success with no projects found") - if err := a.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, models.ApplyCommand, 0, 0); err != nil { + if err := a.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Apply, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } @@ -195,7 +195,7 @@ func (a *ApplyCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus ctx.Pull.BaseRepo, ctx.Pull, status, - models.ApplyCommand, + command.Apply, numSuccess, len(pullStatus.Projects), ); err != nil { diff --git a/server/events/apply_command_runner_test.go b/server/events/apply_command_runner_test.go index e9240e859..336dca672 100644 --- a/server/events/apply_command_runner_test.go +++ b/server/events/apply_command_runner_test.go @@ -68,7 +68,7 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) { } When(applyLockChecker.CheckApplyLock()).ThenReturn(locking.ApplyCommandLock{Locked: c.ApplyLocked}, c.ApplyLockError) - applyCommandRunner.Run(ctx, &events.CommentCommand{Name: models.ApplyCommand}) + applyCommandRunner.Run(ctx, &events.CommentCommand{Name: command.Apply}) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, c.ExpComment, "apply") }) diff --git a/server/events/approve_policies_command_runner.go b/server/events/approve_policies_command_runner.go index be4f2049e..4f52905bd 100644 --- a/server/events/approve_policies_command_runner.go +++ b/server/events/approve_policies_command_runner.go @@ -43,13 +43,13 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *command.Context, cmd *CommentCom baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull - if err := a.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.PendingCommitStatus, models.PolicyCheckCommand); err != nil { + if err := a.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.PendingCommitStatus, command.PolicyCheck); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } projectCmds, err := a.prjCmdBuilder.BuildApprovePoliciesCommands(ctx, cmd) if err != nil { - if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PolicyCheckCommand); statusErr != nil { + if statusErr := a.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, command.PolicyCheck); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } a.pullUpdater.updatePull(ctx, cmd, command.Result{Error: err}) @@ -63,7 +63,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *command.Context, cmd *CommentCom // with 0/0 projects approve_policies successfully because some users require // the Atlantis status to be passing for all pull requests. ctx.Log.Debug("setting VCS status to success with no projects found") - if err := a.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, models.SuccessCommitStatus, models.PolicyCheckCommand, 0, 0); err != nil { + if err := a.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, models.SuccessCommitStatus, command.PolicyCheck, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } @@ -118,7 +118,7 @@ func (a *ApprovePoliciesCommandRunner) updateCommitStatus(ctx *command.Context, status = models.FailedCommitStatus } - if err := a.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, status, models.PolicyCheckCommand, numSuccess, len(pullStatus.Projects)); err != nil { + if err := a.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, status, command.PolicyCheck, numSuccess, len(pullStatus.Projects)); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } diff --git a/server/events/automerger.go b/server/events/automerger.go index e5012581f..fb052d3e5 100644 --- a/server/events/automerger.go +++ b/server/events/automerger.go @@ -23,7 +23,7 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu } // Comment that we're automerging the pull request. - if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, automergeComment, models.ApplyCommand.String()); err != nil { + if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, automergeComment, command.Apply.String()); err != nil { ctx.Log.Err("failed to comment about automerge: %s", err) // Commenting isn't required so continue. } @@ -38,7 +38,7 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu ctx.Log.Err("automerging failed: %s", err) failureComment := fmt.Sprintf("Automerging failed:\n```\n%s\n```", err) - if commentErr := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, failureComment, models.ApplyCommand.String()); commentErr != nil { + if commentErr := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, failureComment, command.Apply.String()); commentErr != nil { ctx.Log.Err("failed to comment about automerge failing: %s", err) } } diff --git a/server/events/command/name.go b/server/events/command/name.go new file mode 100644 index 000000000..cd31e66a2 --- /dev/null +++ b/server/events/command/name.go @@ -0,0 +1,49 @@ +package command + +import "strings" + +// Name is which command to run. +type Name int + +const ( + // Apply is a command to run terraform apply. + Apply Name = iota + // Plan is a command to run terraform plan. + Plan + // Unlock is a command to discard previous plans as well as the atlantis locks. + Unlock + // PolicyCheck is a command to run conftest test. + PolicyCheck + // ApprovePolicies is a command to approve policies with owner check + ApprovePolicies + // Autoplan is a command to run terrafor plan on PR open/update if autoplan is enabled + Autoplan + // Version is a command to run terraform version. + Version + // Adding more? Don't forget to update String() below +) + +// TitleString returns the string representation in title form. +// ie. policy_check becomes Policy Check +func (c Name) TitleString() string { + return strings.Title(strings.ReplaceAll(strings.ToLower(c.String()), "_", " ")) +} + +// String returns the string representation of c. +func (c Name) String() string { + switch c { + case Apply: + return "apply" + case Plan, Autoplan: + return "plan" + case Unlock: + return "unlock" + case PolicyCheck: + return "policy_check" + case ApprovePolicies: + return "approve_policies" + case Version: + return "version" + } + return "" +} diff --git a/server/events/command/result_test.go b/server/events/command/result_test.go index a238ba977..4bdd41e88 100644 --- a/server/events/command/result_test.go +++ b/server/events/command/result_test.go @@ -4,6 +4,7 @@ import ( "errors" "testing" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) diff --git a/server/events/command_runner.go b/server/events/command_runner.go index aa01f50d5..650b019f2 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -86,7 +86,7 @@ type CommentCommandRunner interface { func buildCommentCommandRunner( cmdRunner *DefaultCommandRunner, - cmdName models.CommandName, + cmdName command.Name, ) CommentCommandRunner { // panic here, we want to fail fast and hard since // this would be an internal service configuration error. @@ -125,7 +125,7 @@ type DefaultCommandRunner struct { // this in our error message back to the user on a forked PR so they know // how to disable error comment SilenceForkPRErrorsFlag string - CommentCommandRunnerByCmd map[models.CommandName]CommentCommandRunner + CommentCommandRunnerByCmd map[command.Name]CommentCommandRunner Drainer *Drainer PreWorkflowHooksCommandRunner PreWorkflowHooksCommandRunner PullStatusFetcher PullStatusFetcher @@ -135,7 +135,7 @@ type DefaultCommandRunner struct { // RunAutoplanCommand runs plan and policy_checks when a pull request is opened or updated. func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo models.Repo, pull models.PullRequest, user models.User, timestamp time.Time) { if opStarted := c.Drainer.StartOp(); !opStarted { - if commentErr := c.VCSClient.CreateComment(baseRepo, pull.Num, ShutdownComment, models.PlanCommand.String()); commentErr != nil { + if commentErr := c.VCSClient.CreateComment(baseRepo, pull.Num, ShutdownComment, command.Plan.String()); commentErr != nil { c.Logger.Log(logging.Error, "unable to comment that Atlantis is shutting down: %s", commentErr) } return @@ -178,10 +178,10 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo err = c.PreWorkflowHooksCommandRunner.RunPreHooks(ctx) if err != nil { - ctx.Log.Err("Error running pre-workflow hooks %s. Proceeding with %s command.", err, models.PlanCommand) + ctx.Log.Err("Error running pre-workflow hooks %s. Proceeding with %s command.", err, command.Plan) } - autoPlanRunner := buildCommentCommandRunner(c, models.PlanCommand) + autoPlanRunner := buildCommentCommandRunner(c, command.Plan) autoPlanRunner.Run(ctx, nil) } diff --git a/server/events/command_runner_internal_test.go b/server/events/command_runner_internal_test.go index c99ce221b..03e367022 100644 --- a/server/events/command_runner_internal_test.go +++ b/server/events/command_runner_internal_test.go @@ -10,14 +10,14 @@ import ( func TestApplyUpdateCommitStatus(t *testing.T) { cases := map[string]struct { - cmd models.CommandName + cmd command.Name pullStatus models.PullStatus expStatus models.CommitStatus expNumSuccess int expNumTotal int }{ "apply, one pending": { - cmd: models.ApplyCommand, + cmd: command.Apply, pullStatus: models.PullStatus{ Projects: []models.ProjectStatus{ { @@ -33,7 +33,7 @@ func TestApplyUpdateCommitStatus(t *testing.T) { expNumTotal: 2, }, "apply, all successful": { - cmd: models.ApplyCommand, + cmd: command.Apply, pullStatus: models.PullStatus{ Projects: []models.ProjectStatus{ { @@ -49,7 +49,7 @@ func TestApplyUpdateCommitStatus(t *testing.T) { expNumTotal: 2, }, "apply, one errored, one pending": { - cmd: models.ApplyCommand, + cmd: command.Apply, pullStatus: models.PullStatus{ Projects: []models.ProjectStatus{ { @@ -88,14 +88,14 @@ func TestApplyUpdateCommitStatus(t *testing.T) { func TestPlanUpdateCommitStatus(t *testing.T) { cases := map[string]struct { - cmd models.CommandName + cmd command.Name pullStatus models.PullStatus expStatus models.CommitStatus expNumSuccess int expNumTotal int }{ "single plan success": { - cmd: models.PlanCommand, + cmd: command.Plan, pullStatus: models.PullStatus{ Projects: []models.ProjectStatus{ { @@ -108,7 +108,7 @@ func TestPlanUpdateCommitStatus(t *testing.T) { expNumTotal: 1, }, "one plan error, other errors": { - cmd: models.PlanCommand, + cmd: command.Plan, pullStatus: models.PullStatus{ Projects: []models.ProjectStatus{ { @@ -152,12 +152,12 @@ type MockCSU struct { CalledRepo models.Repo CalledPull models.PullRequest CalledStatus models.CommitStatus - CalledCommand models.CommandName + CalledCommand command.Name CalledNumSuccess int CalledNumTotal int } -func (m *MockCSU) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) error { +func (m *MockCSU) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name, numSuccess int, numTotal int) error { m.CalledRepo = repo m.CalledPull = pull m.CalledStatus = status @@ -166,9 +166,9 @@ func (m *MockCSU) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, m.CalledNumTotal = numTotal return nil } -func (m *MockCSU) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) error { +func (m *MockCSU) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name) error { return nil } -func (m *MockCSU) UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error { +func (m *MockCSU) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { return nil } diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index a8195caec..de6e802b1 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -23,6 +23,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/db" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/vcs" lyft_vcs "github.com/runatlantis/atlantis/server/events/vcs/lyft" "github.com/runatlantis/atlantis/server/logging" @@ -182,12 +183,12 @@ func setup(t *testing.T) *vcsmocks.MockClient { SilenceNoProjects, ) - commentCommandRunnerByCmd := map[models.CommandName]events.CommentCommandRunner{ - models.PlanCommand: planCommandRunner, - models.ApplyCommand: applyCommandRunner, - models.ApprovePoliciesCommand: approvePoliciesCommandRunner, - models.UnlockCommand: unlockCommandRunner, - models.VersionCommand: versionCommandRunner, + commentCommandRunnerByCmd := map[command.Name]events.CommentCommandRunner{ + command.Plan: planCommandRunner, + command.Apply: applyCommandRunner, + command.ApprovePolicies: approvePoliciesCommandRunner, + command.UnlockCommand: unlockCommandRunner, + command.Version: versionCommandRunner, } preWorkflowHooksCommandRunner = mocks.NewMockPreWorkflowHooksCommandRunner() @@ -223,7 +224,7 @@ func TestRunCommentCommand_LogPanics(t *testing.T) { t.Log("if there is a panic it is commented back on the pull request") vcsClient := setup(t) When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenPanic("panic test - if you're seeing this in a test failure this isn't the failing test") - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, 1, &events.CommentCommand{Name: models.PlanCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, 1, &events.CommentCommand{Name: command.Plan}, time.Now()) _, _, comment, _ := vcsClient.VerifyWasCalledOnce().CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()).GetCapturedArguments() Assert(t, strings.Contains(comment, "Error: goroutine panic"), fmt.Sprintf("comment should be about a goroutine panic but was %q", comment)) } @@ -307,13 +308,13 @@ func TestRunCommentCommandPlan_NoProjects_SilenceEnabled(t *testing.T) { When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.PlanCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount( matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), matchers.EqModelsCommitStatus(models.SuccessCommitStatus), - matchers.EqModelsCommandName(models.PlanCommand), + matchers.EqModelsCommandName(command.Plan), EqInt(0), EqInt(0), ) @@ -329,13 +330,13 @@ func TestRunCommentCommandApply_NoProjects_SilenceEnabled(t *testing.T) { When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount( matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), matchers.EqModelsCommitStatus(models.SuccessCommitStatus), - matchers.EqModelsCommandName(models.ApplyCommand), + matchers.EqModelsCommandName(command.Apply), EqInt(0), EqInt(0), ) @@ -351,13 +352,13 @@ func TestRunCommentCommandApprovePolicy_NoProjects_SilenceEnabled(t *testing.T) When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApprovePoliciesCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.ApprovePolicies}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount( matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), matchers.EqModelsCommitStatus(models.SuccessCommitStatus), - matchers.EqModelsCommandName(models.PolicyCheckCommand), + matchers.EqModelsCommandName(command.PolicyCheck), EqInt(0), EqInt(0), ) @@ -372,7 +373,7 @@ func TestRunCommentCommandUnlock_NoProjects_SilenceEnabled(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(&pull, nil) When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) } @@ -389,7 +390,7 @@ func TestRunCommentCommand_DisableApplyAllDisabled(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, "**Error:** Running `atlantis apply` without flags is disabled. You must specify which project to apply via the `-d `, `-w ` or `-p ` flags.", "apply") } @@ -409,7 +410,7 @@ func TestFeatureAwareRunCommentCommandRunner_CommentWhenEnabled(t *testing.T) { modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} When(allocator.ShouldAllocate(feature.ForceApply, "runatlantis/atlantis")).ThenReturn(true, nil) - fa.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: models.ApplyCommand, ForceApply: true}, time.Now()) + fa.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: command.Apply, ForceApply: true}, time.Now()) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, "⚠️ WARNING ⚠️\n\n You have bypassed all apply requirements for this PR 🚀 . This can have unpredictable consequences 🙏🏽 and should only be used in an emergency 🆘 .\n\n 𝐓𝐡𝐢𝐬 𝐚𝐜𝐭𝐢𝐨𝐧 𝐰𝐢𝐥𝐥 𝐛𝐞 𝐚𝐮𝐝𝐢𝐭𝐞𝐝.\n", "") } @@ -422,10 +423,10 @@ func TestRunCommentCommand_DisableDisableAutoplan(t *testing.T) { When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). ThenReturn([]models.ProjectCommandContext{ { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, }, nil) @@ -462,7 +463,7 @@ func TestRunCommentCommand_MatchedBranch(t *testing.T) { When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.PlanCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan}, time.Now()) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, modelPull.Num, "Ran Plan for 0 projects:\n\n\n\n", "plan") } @@ -479,7 +480,7 @@ func TestRunCommentCommand_UnmatchedBranch(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(&pull, nil) When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.PlanCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) } @@ -496,7 +497,7 @@ func TestRunUnlockCommand_VCSComment(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) deleteLockCommand.VerifyWasCalledOnce().DeleteLocksByPull(fixtures.GithubRepo.FullName, fixtures.Pull.Num) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, fixtures.Pull.Num, "All Atlantis locks for this PR have been unlocked and plans discarded", "unlock") @@ -516,7 +517,7 @@ func TestRunUnlockCommandFail_VCSComment(t *testing.T) { When(deleteLockCommand.DeleteLocksByPull(fixtures.GithubRepo.FullName, fixtures.Pull.Num)).ThenReturn(0, errors.New("err")) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, fixtures.Pull.Num, "Failed to delete PR locks", "unlock") } @@ -538,10 +539,10 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). ThenReturn([]models.ProjectCommandContext{ { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { - CommandName: models.PlanCommand, + CommandName: command.Plan, }, }, nil) callCount := 0 @@ -597,21 +598,21 @@ func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) { When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]models.ProjectCommandContext{ { - CommandName: models.ApprovePoliciesCommand, + CommandName: command.ApprovePolicies, }, { - CommandName: models.ApprovePoliciesCommand, + CommandName: command.ApprovePolicies, }, }, nil) When(workingDir.GetPullDir(fixtures.GithubRepo, fixtures.Pull)).ThenReturn(tmp, nil) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &fixtures.Pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApprovePoliciesCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &fixtures.Pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.ApprovePolicies}, time.Now()) commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount( matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), matchers.EqModelsCommitStatus(models.SuccessCommitStatus), - matchers.EqModelsCommandName(models.PolicyCheckCommand), + matchers.EqModelsCommandName(command.PolicyCheck), EqInt(0), EqInt(0), ) @@ -644,7 +645,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]models.ProjectCommandContext{ { - CommandName: models.ApprovePoliciesCommand, + CommandName: command.ApprovePolicies, PolicySets: valid.PolicySets{ Owners: valid.PolicyOwners{ Users: []string{fixtures.User.Username}, @@ -657,18 +658,18 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(projectCommandRunner.ApprovePolicies(matchers.AnyModelsProjectCommandContext())).Then(func(_ []Param) ReturnValues { return ReturnValues{ models.ProjectResult{ - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, } }) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &fixtures.Pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApprovePoliciesCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &fixtures.Pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.ApprovePolicies}, time.Now()) commitUpdater.VerifyWasCalledOnce().UpdateCombinedCount( matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest(), matchers.EqModelsCommitStatus(models.SuccessCommitStatus), - matchers.EqModelsCommandName(models.PolicyCheckCommand), + matchers.EqModelsCommandName(command.PolicyCheck), EqInt(1), EqInt(1), ) @@ -700,7 +701,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { _, _ = boltDB.UpdatePullWithResults(modelPull, []models.ProjectResult{ { - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, Error: fmt.Errorf("failing policy"), ProjectName: "default", Workspace: "default", @@ -714,7 +715,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { return ReturnValues{ []models.ProjectCommandContext{ { - CommandName: models.ApplyCommand, + CommandName: command.Apply, ProjectName: "default", Workspace: "default", RepoRelDir: ".", @@ -726,7 +727,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { }) When(workingDir.GetPullDir(fixtures.GithubRepo, modelPull)).ThenReturn(tmp, nil) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &modelPull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &modelPull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) } func TestApplyWithAutoMerge_VSCMerge(t *testing.T) { @@ -747,7 +748,7 @@ func TestApplyWithAutoMerge_VSCMerge(t *testing.T) { DeleteSourceBranchOnMerge: false, } - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) vcsClient.VerifyWasCalledOnce().MergePull(modelPull, pullOptions) } @@ -767,7 +768,7 @@ func TestRunApply_DiscardedProjects(t *testing.T) { pull.BaseRepo = fixtures.GithubRepo _, err = boltDB.UpdatePullWithResults(pull, []models.ProjectResult{ { - Command: models.PlanCommand, + Command: command.Plan, RepoRelDir: ".", Workspace: "default", PlanSuccess: &models.PlanSuccess{ @@ -785,7 +786,7 @@ func TestRunApply_DiscardedProjects(t *testing.T) { When(eventParsing.ParseGithubPull(ghPull)).ThenReturn(pull, pull.BaseRepo, fixtures.GithubRepo, nil) When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())). ThenReturn(tmp, nil) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, &pull, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) vcsClient.VerifyWasCalled(Never()).MergePull(matchers.AnyModelsPullRequest(), matchers.AnyModelsPullRequestOptions()) } @@ -837,7 +838,7 @@ func TestRunCommentCommand_DropStaleRequest(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(true) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: models.ApplyCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, modelPull.Num, &events.CommentCommand{Name: command.Apply}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) } diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index 95cbab7e2..dbd75fcd4 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -25,6 +25,7 @@ import ( "github.com/flynn-archive/go-shlex" "github.com/runatlantis/atlantis/server/core/config" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/spf13/pflag" ) @@ -169,7 +170,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen } // Need to have a plan, apply, approve_policy or unlock at this point. - if !e.stringInSlice(command, []string{models.PlanCommand.String(), models.ApplyCommand.String(), models.UnlockCommand.String(), models.ApprovePoliciesCommand.String(), models.VersionCommand.String()}) { + if !e.stringInSlice(command, []string{command.Plan.String(), command.Apply.String(), command.UnlockCommand.String(), command.ApprovePolicies.String(), command.Version.String()}) { return CommentParseResult{CommentResponse: fmt.Sprintf("```\nError: unknown command %q.\nRun 'atlantis --help' for usage.\n```", command)} } @@ -178,21 +179,21 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen var project string var verbose, autoMergeDisabled, force bool var flagSet *pflag.FlagSet - var name models.CommandName + var name command.Name // Set up the flag parsing depending on the command. switch command { - case models.PlanCommand.String(): - name = models.PlanCommand - flagSet = pflag.NewFlagSet(models.PlanCommand.String(), pflag.ContinueOnError) + case command.Plan.String(): + name = command.Plan + flagSet = pflag.NewFlagSet(command.Plan.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.", config.AtlantisYAMLFilename)) flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.") - case models.ApplyCommand.String(): - name = models.ApplyCommand - flagSet = pflag.NewFlagSet(models.ApplyCommand.String(), pflag.ContinueOnError) + case command.Apply.String(): + name = command.Apply + flagSet = pflag.NewFlagSet(command.Apply.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'.") @@ -200,18 +201,18 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen flagSet.BoolVarP(&autoMergeDisabled, autoMergeDisabledFlagLong, autoMergeDisabledFlagShort, false, "Disable automerge after apply.") flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.") flagSet.BoolVarP(&force, forceFlagLong, forceFlagShort, false, "Force Atlantis to ignore apply requirements.") - case models.ApprovePoliciesCommand.String(): - name = models.ApprovePoliciesCommand - flagSet = pflag.NewFlagSet(models.ApprovePoliciesCommand.String(), pflag.ContinueOnError) + case command.ApprovePolicies.String(): + name = command.ApprovePolicies + flagSet = pflag.NewFlagSet(command.ApprovePolicies.String(), pflag.ContinueOnError) flagSet.SetOutput(ioutil.Discard) flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.") - case models.UnlockCommand.String(): - name = models.UnlockCommand - flagSet = pflag.NewFlagSet(models.UnlockCommand.String(), pflag.ContinueOnError) + case command.UnlockCommand.String(): + name = command.UnlockCommand + flagSet = pflag.NewFlagSet(command.UnlockCommand.String(), pflag.ContinueOnError) flagSet.SetOutput(ioutil.Discard) - case models.VersionCommand.String(): - name = models.VersionCommand - flagSet = pflag.NewFlagSet(models.VersionCommand.String(), pflag.ContinueOnError) + case command.Version.String(): + name = command.Version + flagSet = pflag.NewFlagSet(command.Version.String(), pflag.ContinueOnError) flagSet.StringVarP(&workspace, workspaceFlagLong, workspaceFlagShort, "", "Switch to this Terraform workspace before running version.") flagSet.StringVarP(&dir, dirFlagLong, dirFlagShort, "", "Which directory to run version in relative to root of repo, ex. 'child/dir'.") flagSet.StringVarP(&project, projectFlagLong, projectFlagShort, "", fmt.Sprintf("Print the version for this project. Refers to the name of the project configured in %s.", config.AtlantisYAMLFilename)) @@ -227,7 +228,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen return CommentParseResult{CommentResponse: fmt.Sprintf("```\nUsage of %s:\n%s\n```", command, flagSet.FlagUsagesWrapped(usagesCols))} } if err != nil { - if command == models.UnlockCommand.String() { + if command == command.UnlockCommand.String() { return CommentParseResult{CommentResponse: UnlockUsage} } return CommentParseResult{CommentResponse: e.errMarkdown(err.Error(), command, flagSet)} @@ -288,19 +289,19 @@ func (e *CommentParser) BuildPlanComment(repoRelDir string, workspace string, pr } commentFlags = fmt.Sprintf(" -- %s", strings.Join(flagsWithoutQuotes, " ")) } - return fmt.Sprintf("%s %s%s%s", atlantisExecutable, models.PlanCommand.String(), flags, commentFlags) + return fmt.Sprintf("%s %s%s%s", atlantisExecutable, command.Plan.String(), flags, commentFlags) } // BuildApplyComment builds an apply comment for the specified args. func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, project string, autoMergeDisabled bool) string { flags := e.buildFlags(repoRelDir, workspace, project, autoMergeDisabled) - return fmt.Sprintf("%s %s%s", atlantisExecutable, models.ApplyCommand.String(), flags) + return fmt.Sprintf("%s %s%s", atlantisExecutable, command.Apply.String(), flags) } // BuildVersionComment builds a version comment for the specified args. func (e *CommentParser) BuildVersionComment(repoRelDir string, workspace string, project string) string { flags := e.buildFlags(repoRelDir, workspace, project, false) - return fmt.Sprintf("%s %s%s", atlantisExecutable, models.VersionCommand.String(), flags) + return fmt.Sprintf("%s %s%s", atlantisExecutable, command.Version.String(), flags) } func (e *CommentParser) buildFlags(repoRelDir string, workspace string, project string, autoMergeDisabled bool) string { diff --git a/server/events/comment_parser_test.go b/server/events/comment_parser_test.go index 612927262..d87e5c41a 100644 --- a/server/events/comment_parser_test.go +++ b/server/events/comment_parser_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -81,57 +82,57 @@ func TestParse_HelpResponseWithApplyDisabled(t *testing.T) { func TestParse_UnusedArguments(t *testing.T) { t.Log("if there are unused flags we return an error") cases := []struct { - Command models.CommandName + Command command.Name Args string Unused string }{ { - models.PlanCommand, + command.Plan, "-d . arg", "arg", }, { - models.PlanCommand, + command.Plan, "arg -d .", "arg", }, { - models.PlanCommand, + command.Plan, "arg", "arg", }, { - models.PlanCommand, + command.Plan, "arg arg2", "arg arg2", }, { - models.PlanCommand, + command.Plan, "-d . arg -w kjj arg2", "arg arg2", }, { - models.ApplyCommand, + command.Apply, "-d . arg", "arg", }, { - models.ApplyCommand, + command.Apply, "arg arg2", "arg arg2", }, { - models.ApplyCommand, + command.Apply, "arg arg2 -- useful", "arg arg2", }, { - models.ApplyCommand, + command.Apply, "arg arg2 --", "arg arg2", }, { - models.ApprovePoliciesCommand, + command.ApprovePolicies, "arg arg2 --", "arg arg2", }, @@ -142,11 +143,11 @@ func TestParse_UnusedArguments(t *testing.T) { r := commentParser.Parse(comment, models.Github) var usage string switch c.Command { - case models.PlanCommand: + case command.Plan: usage = PlanUsage - case models.ApplyCommand: + case command.Apply: usage = ApplyUsage - case models.ApprovePoliciesCommand: + case command.ApprovePolicies: usage = ApprovePolicyUsage } Equals(t, fmt.Sprintf("```\nError: unknown argument(s) – %s.\n%s```", c.Unused, usage), r.CommentResponse) @@ -287,7 +288,7 @@ func TestParse_Multiline(t *testing.T) { Equals(t, &events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, Workspace: "", ProjectName: "", @@ -563,13 +564,13 @@ func TestParse_Parsing(t *testing.T) { actExtraArgs := strings.Join(r.Command.Flags, " ") Assert(t, test.expExtraArgs == actExtraArgs, "exp extra args to equal %v but got %v for comment %q", test.expExtraArgs, actExtraArgs, comment) if cmdName == "plan" { - Assert(t, r.Command.Name == models.PlanCommand, "did not parse comment %q as plan command", comment) + Assert(t, r.Command.Name == command.Plan, "did not parse comment %q as plan command", comment) } if cmdName == "apply" { - Assert(t, r.Command.Name == models.ApplyCommand, "did not parse comment %q as apply command", comment) + Assert(t, r.Command.Name == command.Apply, "did not parse comment %q as apply command", comment) } if cmdName == "approve_policies" { - Assert(t, r.Command.Name == models.ApprovePoliciesCommand, "did not parse comment %q as approve_policies command", comment) + Assert(t, r.Command.Name == command.ApprovePolicies, "did not parse comment %q as approve_policies command", comment) } }) } @@ -681,15 +682,15 @@ func TestBuildPlanApplyVersionComment(t *testing.T) { for _, c := range cases { t.Run(c.expPlanFlags, func(t *testing.T) { - for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand, models.VersionCommand} { + for _, cmd := range []command.Name{command.Plan, command.Apply, command.Version} { switch cmd { - case models.PlanCommand: + case command.Plan: actComment := commentParser.BuildPlanComment(c.repoRelDir, c.workspace, c.project, c.commentArgs) Equals(t, fmt.Sprintf("atlantis plan %s", c.expPlanFlags), actComment) - case models.ApplyCommand: + case command.Apply: actComment := commentParser.BuildApplyComment(c.repoRelDir, c.workspace, c.project, c.autoMergeDisabled) Equals(t, fmt.Sprintf("atlantis apply %s", c.expApplyFlags), actComment) - case models.VersionCommand: + case command.Version: actComment := commentParser.BuildVersionComment(c.repoRelDir, c.workspace, c.project) Equals(t, fmt.Sprintf("atlantis version %s", c.expVersionFlags), actComment) } diff --git a/server/events/commit_status_updater.go b/server/events/commit_status_updater.go index 312211a2f..6009e0901 100644 --- a/server/events/commit_status_updater.go +++ b/server/events/commit_status_updater.go @@ -17,6 +17,7 @@ import ( "fmt" "strings" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -28,13 +29,13 @@ import ( type CommitStatusUpdater interface { // UpdateCombined updates the combined status of the head commit of pull. // A combined status represents all the projects modified in the pull. - UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName models.CommandName) error + UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name) error // UpdateCombinedCount updates the combined status to reflect the // numSuccess out of numTotal. - UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName models.CommandName, numSuccess int, numTotal int) error + UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error + UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error } // DefaultCommitStatusUpdater implements CommitStatusUpdater. @@ -43,29 +44,29 @@ type DefaultCommitStatusUpdater struct { TitleBuilder vcs.StatusTitleBuilder } -func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName models.CommandName) error { +func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name) error { src := d.TitleBuilder.Build(cmdName.String()) descrip := fmt.Sprintf("%s %s", strings.Title(cmdName.String()), d.statusDescription(status)) return d.Client.UpdateStatus(repo, pull, status, src, descrip, "") } -func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName models.CommandName, numSuccess int, numTotal int) error { +func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error { src := d.TitleBuilder.Build(cmdName.String()) cmdVerb := "unknown" switch cmdName { - case models.PlanCommand: + case command.Plan: cmdVerb = "planned" - case models.PolicyCheckCommand: + case command.PolicyCheck: cmdVerb = "policies checked" - case models.ApplyCommand: + case command.Apply: cmdVerb = "applied" } return d.Client.UpdateStatus(repo, pull, status, src, fmt.Sprintf("%d/%d projects %s successfully.", numSuccess, numTotal, cmdVerb), "") } -func (d *DefaultCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error { +func (d *DefaultCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { projectID := ctx.ProjectName if projectID == "" { projectID = fmt.Sprintf("%s/%s", ctx.RepoRelDir, ctx.Workspace) diff --git a/server/events/commit_status_updater_test.go b/server/events/commit_status_updater_test.go index aa2c658c0..17a576983 100644 --- a/server/events/commit_status_updater_test.go +++ b/server/events/commit_status_updater_test.go @@ -19,6 +19,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -28,37 +29,37 @@ import ( func TestUpdateCombined(t *testing.T) { cases := []struct { status models.CommitStatus - command models.CommandName + command command.Name expDescrip string }{ { status: models.PendingCommitStatus, - command: models.PlanCommand, + command: command.Plan, expDescrip: "Plan in progress...", }, { status: models.FailedCommitStatus, - command: models.PlanCommand, + command: command.Plan, expDescrip: "Plan failed.", }, { status: models.SuccessCommitStatus, - command: models.PlanCommand, + command: command.Plan, expDescrip: "Plan succeeded.", }, { status: models.PendingCommitStatus, - command: models.ApplyCommand, + command: command.Apply, expDescrip: "Apply in progress...", }, { status: models.FailedCommitStatus, - command: models.ApplyCommand, + command: command.Apply, expDescrip: "Apply failed.", }, { status: models.SuccessCommitStatus, - command: models.ApplyCommand, + command: command.Apply, expDescrip: "Apply succeeded.", }, } @@ -82,49 +83,49 @@ func TestUpdateCombined(t *testing.T) { func TestUpdateCombinedCount(t *testing.T) { cases := []struct { status models.CommitStatus - command models.CommandName + command command.Name numSuccess int numTotal int expDescrip string }{ { status: models.PendingCommitStatus, - command: models.PlanCommand, + command: command.Plan, numSuccess: 0, numTotal: 2, expDescrip: "0/2 projects planned successfully.", }, { status: models.FailedCommitStatus, - command: models.PlanCommand, + command: command.Plan, numSuccess: 1, numTotal: 2, expDescrip: "1/2 projects planned successfully.", }, { status: models.SuccessCommitStatus, - command: models.PlanCommand, + command: command.Plan, numSuccess: 2, numTotal: 2, expDescrip: "2/2 projects planned successfully.", }, { status: models.FailedCommitStatus, - command: models.ApplyCommand, + command: command.Apply, numSuccess: 0, numTotal: 2, expDescrip: "0/2 projects applied successfully.", }, { status: models.PendingCommitStatus, - command: models.ApplyCommand, + command: command.Apply, numSuccess: 1, numTotal: 2, expDescrip: "1/2 projects applied successfully.", }, { status: models.SuccessCommitStatus, - command: models.ApplyCommand, + command: command.Apply, numSuccess: 2, numTotal: 2, expDescrip: "2/2 projects applied successfully.", @@ -180,7 +181,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectSrc(t *testing.T) { RepoRelDir: c.repoRelDir, Workspace: c.workspace, }, - models.PlanCommand, + command.Plan, models.PendingCommitStatus, "url") Ok(t, err) @@ -194,37 +195,37 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { RegisterMockTestingT(t) cases := []struct { status models.CommitStatus - cmd models.CommandName + cmd command.Name expDescrip string }{ { models.PendingCommitStatus, - models.PlanCommand, + command.Plan, "Plan in progress...", }, { models.FailedCommitStatus, - models.PlanCommand, + command.Plan, "Plan failed.", }, { models.SuccessCommitStatus, - models.PlanCommand, + command.Plan, "Plan succeeded.", }, { models.PendingCommitStatus, - models.ApplyCommand, + command.Apply, "Apply in progress...", }, { models.FailedCommitStatus, - models.ApplyCommand, + command.Apply, "Apply failed.", }, { models.SuccessCommitStatus, - models.ApplyCommand, + command.Apply, "Apply succeeded.", }, } @@ -257,7 +258,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectCustomStatusName(t *testing.T) RepoRelDir: ".", Workspace: "default", }, - models.ApplyCommand, + command.Apply, models.SuccessCommitStatus, "url") Ok(t, err) diff --git a/server/events/event_parser.go b/server/events/event_parser.go index 1f3a90d50..5694c4c6e 100644 --- a/server/events/event_parser.go +++ b/server/events/event_parser.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-github/v31/github" "github.com/mcdafydd/go-azuredevops/azuredevops" "github.com/pkg/errors" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs/bitbucketcloud" "github.com/runatlantis/atlantis/server/events/vcs/bitbucketserver" @@ -36,7 +37,7 @@ const usagesCols = 90 // PullCommand is a command to run on a pull request. type PullCommand interface { // CommandName is the name of the command we're running. - CommandName() models.CommandName + CommandName() command.Name // 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. @@ -48,8 +49,8 @@ type PullCommand interface { type PolicyCheckCommand struct{} // CommandName is policy_check. -func (c PolicyCheckCommand) CommandName() models.CommandName { - return models.PolicyCheckCommand +func (c PolicyCheckCommand) CommandName() command.Name { + return command.PolicyCheck } // IsVerbose is false for policy_check commands. @@ -67,8 +68,8 @@ func (c PolicyCheckCommand) IsAutoplan() bool { type AutoplanCommand struct{} // CommandName is plan. -func (c AutoplanCommand) CommandName() models.CommandName { - return models.PlanCommand +func (c AutoplanCommand) CommandName() command.Name { + return command.Plan } // IsVerbose is false for autoplan commands. @@ -90,7 +91,7 @@ type CommentCommand struct { // ex. atlantis plan -- -target=resource Flags []string // Name is the name of the command the comment specified. - Name models.CommandName + Name command.Name // AutoMergeDisabled is true if the command should not automerge after apply. AutoMergeDisabled bool // Verbose is true if the command should output verbosely. @@ -114,7 +115,7 @@ func (c CommentCommand) IsForSpecificProject() bool { } // CommandName returns the name of this command. -func (c CommentCommand) CommandName() models.CommandName { +func (c CommentCommand) CommandName() command.Name { return c.Name } @@ -134,7 +135,7 @@ func (c CommentCommand) String() string { } // NewCommentCommand constructs a CommentCommand, setting all missing fields to defaults. -func NewCommentCommand(repoRelDir string, flags []string, name models.CommandName, verbose, forceApply, autoMergeDisabled bool, workspace string, project string) *CommentCommand { +func NewCommentCommand(repoRelDir string, flags []string, name command.Name, verbose, forceApply, autoMergeDisabled bool, workspace string, project string) *CommentCommand { // If repoRelDir was empty we want to keep it that way to indicate that it // wasn't specified in the comment. if repoRelDir != "" { diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index 656f8b369..6b2f980df 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -25,6 +25,7 @@ import ( "github.com/mcdafydd/go-azuredevops/azuredevops" "github.com/mohae/deepcopy" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/server/events/vcs/fixtures" . "github.com/runatlantis/atlantis/testing" @@ -650,18 +651,18 @@ func TestNewCommand_CleansDir(t *testing.T) { for _, c := range cases { t.Run(c.RepoRelDir, func(t *testing.T) { - cmd := events.NewCommentCommand(c.RepoRelDir, nil, models.PlanCommand, false, false, false, "workspace", "") + cmd := events.NewCommentCommand(c.RepoRelDir, nil, command.Plan, false, false, false, "workspace", "") Equals(t, c.ExpDir, cmd.RepoRelDir) }) } } func TestNewCommand_EmptyDirWorkspaceProject(t *testing.T) { - cmd := events.NewCommentCommand("", nil, models.PlanCommand, false, false, false, "", "") + cmd := events.NewCommentCommand("", nil, command.Plan, false, false, false, "", "") Equals(t, events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, Workspace: "", ProjectName: "", @@ -669,19 +670,19 @@ func TestNewCommand_EmptyDirWorkspaceProject(t *testing.T) { } func TestNewCommand_AllFieldsSet(t *testing.T) { - cmd := events.NewCommentCommand("dir", []string{"a", "b"}, models.PlanCommand, true, false, false, "workspace", "project") + cmd := events.NewCommentCommand("dir", []string{"a", "b"}, command.Plan, true, false, false, "workspace", "project") Equals(t, events.CommentCommand{ Workspace: "workspace", RepoRelDir: "dir", Verbose: true, Flags: []string{"a", "b"}, - Name: models.PlanCommand, + Name: command.Plan, ProjectName: "project", }, *cmd) } func TestAutoplanCommand_CommandName(t *testing.T) { - Equals(t, models.PlanCommand, (events.AutoplanCommand{}).CommandName()) + Equals(t, command.Plan, (events.AutoplanCommand{}).CommandName()) } func TestAutoplanCommand_IsVerbose(t *testing.T) { @@ -693,11 +694,11 @@ func TestAutoplanCommand_IsAutoplan(t *testing.T) { } func TestCommentCommand_CommandName(t *testing.T) { - Equals(t, models.PlanCommand, (events.CommentCommand{ - Name: models.PlanCommand, + Equals(t, command.Plan, (events.CommentCommand{ + Name: command.Plan, }).CommandName()) - Equals(t, models.ApplyCommand, (events.CommentCommand{ - Name: models.ApplyCommand, + Equals(t, command.Apply, (events.CommentCommand{ + Name: command.Apply, }).CommandName()) } @@ -719,7 +720,7 @@ func TestCommentCommand_String(t *testing.T) { Equals(t, exp, (events.CommentCommand{ RepoRelDir: "mydir", Flags: []string{"flag1", "flag2"}, - Name: models.PlanCommand, + Name: command.Plan, Verbose: true, Workspace: "myworkspace", ProjectName: "myproject", diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index fb796797c..e14710009 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -23,15 +23,16 @@ import ( _ "embed" "github.com/Masterminds/sprig/v3" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) var ( - planCommandTitle = models.PlanCommand.TitleString() - applyCommandTitle = models.ApplyCommand.TitleString() - policyCheckCommandTitle = models.PolicyCheckCommand.TitleString() - approvePoliciesCommandTitle = models.ApprovePoliciesCommand.TitleString() - versionCommandTitle = models.VersionCommand.TitleString() + planCommandTitle = command.Plan.TitleString() + applyCommandTitle = command.Apply.TitleString() + policyCheckCommandTitle = command.PolicyCheck.TitleString() + approvePoliciesCommandTitle = command.ApprovePolicies.TitleString() + versionCommandTitle = command.Version.TitleString() // maxUnwrappedLines is the maximum number of lines the Terraform output // can be before we wrap it in an expandable template. maxUnwrappedLines = 12 @@ -102,7 +103,7 @@ type projectResultTmplData struct { // Render formats the data into a markdown string. // nolint: interfacer -func (m *MarkdownRenderer) Render(res command.Result, cmdName models.CommandName, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { +func (m *MarkdownRenderer) Render(res command.Result, cmdName command.Name, log string, verbose bool, vcsHost models.VCSHostType, templateOverrides map[string]string) string { commandStr := strings.Title(strings.Replace(cmdName.String(), "_", " ", -1)) common := commonData{ Command: commandStr, diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 844a766fa..835cda0ed 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -27,7 +28,7 @@ import ( func TestCustomTemplates(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string @@ -35,7 +36,7 @@ func TestCustomTemplates(t *testing.T) { }{ { "Plan Override", - models.PlanCommand, + command.Plan, []models.ProjectResult{}, models.Github, "Custom Template", @@ -43,7 +44,7 @@ func TestCustomTemplates(t *testing.T) { }, { "Default Plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", @@ -51,7 +52,7 @@ func TestCustomTemplates(t *testing.T) { }, { "Apply Override", - models.ApplyCommand, + command.Apply, []models.ProjectResult{}, models.Github, "Custom Template", @@ -59,7 +60,7 @@ func TestCustomTemplates(t *testing.T) { }, { "Project Plan Successful Custom Template", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -107,7 +108,7 @@ Custom Template }, { "Only Use Plan Success Override with failed, and errored plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -179,25 +180,25 @@ func TestRenderErr(t *testing.T) { err := errors.New("err") cases := []struct { Description string - Command models.CommandName + Command command.Name Error error Expected string }{ { "apply error", - models.ApplyCommand, + command.Apply, err, "**Apply Error**\n```\nerr\n```\n", }, { "plan error", - models.PlanCommand, + command.Plan, err, "**Plan Error**\n```\nerr\n```\n", }, { "policy check error", - models.PolicyCheckCommand, + command.PolicyCheck, err, "**Policy Check Error**\n```\nerr\n```" + "\n* :heavy_check_mark: To **approve** failing policies either request an approval from approvers or address the failure by modifying the codebase.\n\n", @@ -225,25 +226,25 @@ func TestRenderErr(t *testing.T) { func TestRenderFailure(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name Failure string Expected string }{ { "apply failure", - models.ApplyCommand, + command.Apply, "failure", "**Apply Failed**: failure\n", }, { "plan failure", - models.PlanCommand, + command.Plan, "failure", "**Plan Failed**: failure\n", }, { "policy check failure", - models.PolicyCheckCommand, + command.PolicyCheck, "failure", "**Policy Check Failed**: failure\n", }, @@ -273,35 +274,35 @@ func TestRenderErrAndFailure(t *testing.T) { Error: errors.New("error"), Failure: "failure", } - s := r.Render(res, models.PlanCommand, "", false, models.Github, make(map[string]string)) + s := r.Render(res, command.Plan, "", false, models.Github, make(map[string]string)) Equals(t, "**Plan Error**\n```\nerror\n```\n", s) } func TestRenderProjectResults(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string }{ { "no projects", - models.PlanCommand, + command.Plan, []models.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "approve policies", - models.ApprovePoliciesCommand, + command.ApprovePolicies, []models.ProjectResult{}, models.Github, "Approved Policies for 0 projects:\n\n\n\n", }, { "single successful plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -336,7 +337,7 @@ $$$ }, { "single successful plan with master ahead", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -374,7 +375,7 @@ $$$ }, { "single successful plan with project name", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -410,7 +411,7 @@ $$$ }, { "single successful policy check with project name", - models.PolicyCheckCommand, + command.PolicyCheck, []models.ProjectResult{ { PolicyCheckSuccess: &models.PolicyCheckSuccess{ @@ -446,7 +447,7 @@ $$$ }, { "single successful apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { ApplySuccess: "success", @@ -465,7 +466,7 @@ $$$ }, { "single successful apply with project name", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { ApplySuccess: "success", @@ -485,7 +486,7 @@ $$$ }, { "multiple successful plans", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -547,7 +548,7 @@ $$$ }, { "multiple successful policy checks", - models.PolicyCheckCommand, + command.PolicyCheck, []models.ProjectResult{ { Workspace: "workspace", @@ -609,7 +610,7 @@ $$$ }, { "multiple successful applies", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { RepoRelDir: "path", @@ -646,7 +647,7 @@ $$$ }, { "single errored plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Error: errors.New("error"), @@ -666,7 +667,7 @@ $$$ }, { "single failed plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { RepoRelDir: "path", @@ -683,7 +684,7 @@ $$$ }, { "successful, failed, and errored plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -745,7 +746,7 @@ $$$ }, { "successful, failed, and errored policy check", - models.PolicyCheckCommand, + command.PolicyCheck, []models.ProjectResult{ { Workspace: "workspace", @@ -809,7 +810,7 @@ $$$ }, { "successful, failed, and errored apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { Workspace: "workspace", @@ -856,7 +857,7 @@ $$$ }, { "successful, failed, and errored apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { Workspace: "workspace", @@ -928,14 +929,14 @@ $$$ func TestRenderProjectResultsDisableApplyAll(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply all set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -966,7 +967,7 @@ $$$ }, { "single successful plan with project name with disable apply all set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -998,7 +999,7 @@ $$$ }, { "multiple successful plans, disable apply all set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -1081,14 +1082,14 @@ $$$ func TestRenderProjectResultsDisableApply(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -1117,7 +1118,7 @@ $$$ }, { "single successful plan with project name with disable apply set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -1147,7 +1148,7 @@ $$$ }, { "multiple successful plans, disable apply set", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -1237,7 +1238,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { Error: errors.New(strings.Repeat("line\n", 13)), }, }, - }, models.PlanCommand, "log", false, models.Github, make(map[string]string)) + }, command.Plan, "log", false, models.Github, make(map[string]string)) Equals(t, false, strings.Contains(rendered, "
")) } @@ -1321,7 +1322,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { Error: errors.New(c.Output), }, }, - }, models.PlanCommand, "log", false, c.VCSHost, make(map[string]string)) + }, command.Plan, "log", false, c.VCSHost, make(map[string]string)) var exp string if c.ShouldWrap { exp = `Ran Plan for dir: $.$ workspace: $default$ @@ -1418,7 +1419,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { } for _, c := range cases { - for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { + for _, cmd := range []command.Name{command.Plan, command.Apply} { t.Run(fmt.Sprintf("%s_%s_%v", c.VCSHost.String(), cmd.String(), c.ShouldWrap), func(t *testing.T) { mr := events.MarkdownRenderer{ @@ -1426,7 +1427,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { } var pr models.ProjectResult switch cmd { - case models.PlanCommand: + case command.Plan: pr = models.ProjectResult{ RepoRelDir: ".", Workspace: "default", @@ -1437,7 +1438,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { ApplyCmd: "applycmd", }, } - case models.ApplyCommand: + case command.Apply: pr = models.ProjectResult{ RepoRelDir: ".", Workspace: "default", @@ -1451,7 +1452,7 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { // Check result. var exp string switch cmd { - case models.PlanCommand: + case command.Plan: if c.ShouldWrap { exp = `Ran Plan for dir: $.$ workspace: $default$ @@ -1495,7 +1496,7 @@ $$$ * $atlantis unlock$ ` } - case models.ApplyCommand: + case command.Apply: if c.ShouldWrap { exp = `Ran Apply for dir: $.$ workspace: $default$ @@ -1541,7 +1542,7 @@ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { ApplySuccess: tfOut, }, }, - }, models.ApplyCommand, "log", false, models.Github, make(map[string]string)) + }, command.Apply, "log", false, models.Github, make(map[string]string)) exp := `Ran Apply for 2 projects: 1. dir: $.$ workspace: $staging$ @@ -1597,7 +1598,7 @@ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { }, }, }, - }, models.PlanCommand, "log", false, models.Github, make(map[string]string)) + }, command.Plan, "log", false, models.Github, make(map[string]string)) exp := `Ran Plan for 2 projects: 1. dir: $.$ workspace: $staging$ @@ -1746,7 +1747,7 @@ This plan was not saved because one or more projects failed and automerge requir for name, c := range cases { t.Run(name, func(t *testing.T) { mr := events.MarkdownRenderer{} - rendered := mr.Render(c.cr, models.PlanCommand, "log", false, models.Github, make(map[string]string)) + rendered := mr.Render(c.cr, command.Plan, "log", false, models.Github, make(map[string]string)) expWithBackticks := strings.Replace(c.exp, "$", "`", -1) Equals(t, expWithBackticks, rendered) }) @@ -1757,21 +1758,21 @@ This plan was not saved because one or more projects failed and automerge requir func TestRenderProjectResultsWithRepoLockingDisabled(t *testing.T) { cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string }{ { "no projects", - models.PlanCommand, + command.Plan, []models.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "single successful plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -1805,7 +1806,7 @@ $$$ }, { "single successful plan with master ahead", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -1842,7 +1843,7 @@ $$$ }, { "single successful plan with project name", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ @@ -1877,7 +1878,7 @@ $$$ }, { "single successful apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { ApplySuccess: "success", @@ -1896,7 +1897,7 @@ $$$ }, { "single successful apply with project name", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { ApplySuccess: "success", @@ -1916,7 +1917,7 @@ $$$ }, { "multiple successful plans", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -1976,7 +1977,7 @@ $$$ }, { "multiple successful applies", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { RepoRelDir: "path", @@ -2013,7 +2014,7 @@ $$$ }, { "single errored plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Error: errors.New("error"), @@ -2033,7 +2034,7 @@ $$$ }, { "single failed plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { RepoRelDir: "path", @@ -2050,7 +2051,7 @@ $$$ }, { "successful, failed, and errored plan", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { Workspace: "workspace", @@ -2111,7 +2112,7 @@ $$$ }, { "successful, failed, and errored apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { Workspace: "workspace", @@ -2158,7 +2159,7 @@ $$$ }, { "successful, failed, and errored apply", - models.ApplyCommand, + command.Apply, []models.ProjectResult{ { Workspace: "workspace", @@ -2337,14 +2338,14 @@ Plan: 1 to add, 1 to change, 1 to destroy. ` cases := []struct { Description string - Command models.CommandName + Command command.Name ProjectResults []models.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with diff markdown formatted", - models.PlanCommand, + command.Plan, []models.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ diff --git a/server/events/mocks/matchers/models_commandname.go b/server/events/mocks/matchers/models_commandname.go index a40ed59a8..aec79b126 100644 --- a/server/events/mocks/matchers/models_commandname.go +++ b/server/events/mocks/matchers/models_commandname.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsCommandName() models.CommandName { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.CommandName))(nil)).Elem())) - var nullValue models.CommandName +func AnyModelsCommandName() command.Name { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.Name))(nil)).Elem())) + var nullValue command.Name return nullValue } -func EqModelsCommandName(value models.CommandName) models.CommandName { +func EqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func NotEqModelsCommandName(value models.CommandName) models.CommandName { +func NotEqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) models.CommandName { +func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) command.Name { pegomock.RegisterMatcher(matcher) - var nullValue models.CommandName + var nullValue command.Name return nullValue } diff --git a/server/events/mocks/mock_commit_status_updater.go b/server/events/mocks/mock_commit_status_updater.go index 0e560f534..00bf6032f 100644 --- a/server/events/mocks/mock_commit_status_updater.go +++ b/server/events/mocks/mock_commit_status_updater.go @@ -8,6 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -26,7 +27,7 @@ func NewMockCommitStatusUpdater(options ...pegomock.Option) *MockCommitStatusUpd func (mock *MockCommitStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockCommitStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) error { +func (mock *MockCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCommitStatusUpdater().") } @@ -41,7 +42,7 @@ func (mock *MockCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model return ret0 } -func (mock *MockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) error { +func (mock *MockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name, numSuccess int, numTotal int) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCommitStatusUpdater().") } @@ -56,7 +57,7 @@ func (mock *MockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull return ret0 } -func (mock *MockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error { +func (mock *MockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCommitStatusUpdater().") } @@ -108,7 +109,7 @@ type VerifierMockCommitStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName) *MockCommitStatusUpdater_UpdateCombined_OngoingVerification { +func (verifier *VerifierMockCommitStatusUpdater) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name) *MockCommitStatusUpdater_UpdateCombined_OngoingVerification { params := []pegomock.Param{repo, pull, status, command} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateCombined", params, verifier.timeout) return &MockCommitStatusUpdater_UpdateCombined_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -119,12 +120,12 @@ type MockCommitStatusUpdater_UpdateCombined_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest, models.CommitStatus, models.CommandName) { +func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest, models.CommitStatus, command.Name) { repo, pull, status, command := c.GetAllCapturedArguments() return repo[len(repo)-1], pull[len(pull)-1], status[len(status)-1], command[len(command)-1] } -func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest, _param2 []models.CommitStatus, _param3 []models.CommandName) { +func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest, _param2 []models.CommitStatus, _param3 []command.Name) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.Repo, len(c.methodInvocations)) @@ -139,9 +140,9 @@ func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetAllCaptu for u, param := range params[2] { _param2[u] = param.(models.CommitStatus) } - _param3 = make([]models.CommandName, len(c.methodInvocations)) + _param3 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[3] { - _param3[u] = param.(models.CommandName) + _param3[u] = param.(command.Name) } } return @@ -158,7 +159,7 @@ type MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest, models.CommitStatus, models.CommandName, int, int) { +func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetCapturedArguments() (models.Repo, models.PullRequest, models.CommitStatus, command.Name, int, int) { repo, pull, status, command, numSuccess, numTotal := c.GetAllCapturedArguments() return repo[len(repo)-1], pull[len(pull)-1], status[len(status)-1], command[len(command)-1], numSuccess[len(numSuccess)-1], numTotal[len(numTotal)-1] } @@ -178,9 +179,9 @@ func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAll for u, param := range params[2] { _param2[u] = param.(models.CommitStatus) } - _param3 = make([]models.CommandName, len(c.methodInvocations)) + _param3 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[3] { - _param3[u] = param.(models.CommandName) + _param3[u] = param.(command.Name) } _param4 = make([]int, len(c.methodInvocations)) for u, param := range params[4] { @@ -194,7 +195,7 @@ func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAll return } -func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{ctx, cmdName, status, url} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockCommitStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -205,21 +206,21 @@ type MockCommitStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, models.CommandName, models.CommitStatus, string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus, string) { ctx, cmdName, status, url := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], url[len(url)-1] } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []models.CommandName, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(models.ProjectCommandContext) } - _param1 = make([]models.CommandName, len(c.methodInvocations)) + _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(models.CommandName) + _param1[u] = param.(command.Name) } _param2 = make([]models.CommitStatus, len(c.methodInvocations)) for u, param := range params[2] { diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index ad7fc6c5e..e9b95b0bb 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -8,6 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -26,7 +27,7 @@ func NewMockJobURLSetter(options ...pegomock.Option) *MockJobURLSetter { func (mock *MockJobURLSetter) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobURLSetter) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 models.CommandName, _param2 models.CommitStatus) error { +func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobURLSetter().") } @@ -78,7 +79,7 @@ type VerifierMockJobURLSetter struct { timeout time.Duration } -func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 models.CommandName, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { +func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", params, verifier.timeout) return &MockJobURLSetter_SetJobURLWithStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -89,21 +90,21 @@ type MockJobURLSetter_SetJobURLWithStatus_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, models.CommandName, models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus) { _param0, _param1, _param2 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []models.CommandName, _param2 []models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(models.ProjectCommandContext) } - _param1 = make([]models.CommandName, len(c.methodInvocations)) + _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(models.CommandName) + _param1[u] = param.(command.Name) } _param2 = make([]models.CommitStatus, len(c.methodInvocations)) for u, param := range params[2] { diff --git a/server/events/models/models.go b/server/events/models/models.go index 2c41e5676..aad976fe0 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -242,7 +242,7 @@ type LockMetadata struct { type CommandLock struct { // Time is the time at which the lock was first created. LockMetadata LockMetadata - CommandName CommandName + CommandName command.CommandName } func (l *CommandLock) LockTime() time.Time { @@ -351,7 +351,7 @@ func (h VCSHostType) String() string { // ProjectCommandContext defines the context for a plan or apply stage that will // be executed for a project. type ProjectCommandContext struct { - CommandName CommandName + CommandName command.CommandName // ApplyCmd is the command that users should run to apply this plan. If // this is an apply then this will be empty. ApplyCmd string @@ -688,52 +688,6 @@ func (p ProjectPlanStatus) String() string { } } -// 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 - // UnlockCommand is a command to discard previous plans as well as the atlantis locks. - UnlockCommand - // PolicyCheckCommand is a command to run conftest test. - PolicyCheckCommand - // ApprovePoliciesCommand is a command to approve policies with owner check - ApprovePoliciesCommand - // AutoplanCommand is a command to run terrafor plan on PR open/update if autoplan is enabled - AutoplanCommand - // VersionCommand is a command to run terraform version. - VersionCommand - // Adding more? Don't forget to update String() below -) - -// TitleString returns the string representation in title form. -// ie. policy_check becomes Policy Check -func (c CommandName) TitleString() string { - return strings.Title(strings.ReplaceAll(strings.ToLower(c.String()), "_", " ")) -} - -// String returns the string representation of c. -func (c CommandName) String() string { - switch c { - case ApplyCommand: - return "apply" - case PlanCommand, AutoplanCommand: - return "plan" - case UnlockCommand: - return "unlock" - case PolicyCheckCommand: - return "policy_check" - case ApprovePoliciesCommand: - return "approve_policies" - case VersionCommand: - return "version" - } - return "" -} - // PreWorkflowHookCommandContext defines the context for a pre_worklfow_hooks that will // be executed before workflows. type PreWorkflowHookCommandContext struct { diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index 7692205bd..242b437a3 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -407,70 +407,70 @@ func TestProjectResult_PlanStatus(t *testing.T) { }{ { p: models.ProjectResult{ - Command: models.PlanCommand, + Command: command.Plan, Error: errors.New("err"), }, expStatus: models.ErroredPlanStatus, }, { p: models.ProjectResult{ - Command: models.PlanCommand, + Command: command.Plan, Failure: "failure", }, expStatus: models.ErroredPlanStatus, }, { p: models.ProjectResult{ - Command: models.PlanCommand, + Command: command.Plan, PlanSuccess: &models.PlanSuccess{}, }, expStatus: models.PlannedPlanStatus, }, { p: models.ProjectResult{ - Command: models.ApplyCommand, + Command: command.Apply, Error: errors.New("err"), }, expStatus: models.ErroredApplyStatus, }, { p: models.ProjectResult{ - Command: models.ApplyCommand, + Command: command.Apply, Failure: "failure", }, expStatus: models.ErroredApplyStatus, }, { p: models.ProjectResult{ - Command: models.ApplyCommand, + Command: command.Apply, ApplySuccess: "success", }, expStatus: models.AppliedPlanStatus, }, { p: models.ProjectResult{ - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { p: models.ProjectResult{ - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, Failure: "failure", }, expStatus: models.ErroredPolicyCheckStatus, }, { p: models.ProjectResult{ - Command: models.ApprovePoliciesCommand, + Command: command.ApprovePolicies, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { p: models.ProjectResult{ - Command: models.ApprovePoliciesCommand, + Command: command.ApprovePolicies, Failure: "failure", }, expStatus: models.ErroredPolicyCheckStatus, @@ -610,25 +610,25 @@ func TestPullStatus_StatusCount(t *testing.T) { } func TestApplyCommand_String(t *testing.T) { - uc := models.ApplyCommand + uc := command.Apply Equals(t, "apply", uc.String()) } func TestPlanCommand_String(t *testing.T) { - uc := models.PlanCommand + uc := command.Plan Equals(t, "plan", uc.String()) } func TestPolicyCheckCommand_String(t *testing.T) { - uc := models.PolicyCheckCommand + uc := command.PolicyCheck Equals(t, "policy_check", uc.String()) } func TestUnlockCommand_String(t *testing.T) { - uc := models.UnlockCommand + uc := command.UnlockCommand Equals(t, "unlock", uc.String()) } diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 333637319..9a25131b0 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -72,7 +72,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) { projectCmds, err := p.prjCmdBuilder.BuildAutoplanCommands(ctx) if err != nil { - if statusErr := p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { + if statusErr := p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.FailedCommitStatus, command.Plan); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } p.pullUpdater.updatePull(ctx, AutoplanCommand{}, command.Result{Error: err}) @@ -88,13 +88,13 @@ func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) { // with 0/0 projects planned/policy_checked/applied successfully because some users require // the Atlantis status to be passing for all pull requests. ctx.Log.Debug("setting VCS status to success with no projects found") - if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, models.PlanCommand, 0, 0); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Plan, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } - if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, models.PolicyCheckCommand, 0, 0); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.PolicyCheck, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } - if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, models.ApplyCommand, 0, 0); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Apply, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } @@ -102,7 +102,7 @@ func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) { } // At this point we are sure Atlantis has work to do, so set commit status to pending - if err := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.PendingCommitStatus, models.PlanCommand); err != nil { + if err := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.PendingCommitStatus, command.Plan); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } @@ -151,13 +151,13 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { baseRepo := ctx.Pull.BaseRepo pull := ctx.Pull - if err = p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.PendingCommitStatus, models.PlanCommand); err != nil { + if err = p.commitStatusUpdater.UpdateCombined(baseRepo, pull, models.PendingCommitStatus, command.Plan); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } projectCmds, err := p.prjCmdBuilder.BuildPlanCommands(ctx, cmd) if err != nil { - if statusErr := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, models.PlanCommand); statusErr != nil { + if statusErr := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.FailedCommitStatus, command.Plan); statusErr != nil { ctx.Log.Warn("unable to update commit status: %s", statusErr) } p.pullUpdater.updatePull(ctx, cmd, command.Result{Error: err}) @@ -171,7 +171,7 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { // with 0/0 projects planned successfully because some users require // the Atlantis status to be passing for all pull requests. ctx.Log.Debug("setting VCS status to success with no projects found") - if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, models.PlanCommand, 0, 0); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(baseRepo, pull, models.SuccessCommitStatus, command.Plan, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } @@ -244,7 +244,7 @@ func (p *PlanCommandRunner) updateCommitStatus(ctx *command.Context, pullStatus ctx.Pull.BaseRepo, ctx.Pull, status, - models.PlanCommand, + command.Plan, numSuccess, len(pullStatus.Projects), ); err != nil { @@ -272,9 +272,9 @@ func (p *PlanCommandRunner) partitionProjectCmds( ) { for _, cmd := range cmds { switch cmd.CommandName { - case models.PlanCommand: + case command.Plan: projectCmds = append(projectCmds, cmd) - case models.PolicyCheckCommand: + case command.PolicyCheck: policyCheckCmds = append(policyCheckCmds, cmd) default: ctx.Log.Err("%s is not supported", cmd.CommandName) diff --git a/server/events/policy_check_command_runner.go b/server/events/policy_check_command_runner.go index 2a0162b5c..830c8380c 100644 --- a/server/events/policy_check_command_runner.go +++ b/server/events/policy_check_command_runner.go @@ -42,7 +42,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []models.Proje // with 0/0 projects policy_checked successfully because some users require // the Atlantis status to be passing for all pull requests. ctx.Log.Debug("setting VCS status to success with no projects found") - if err := p.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, models.SuccessCommitStatus, models.PolicyCheckCommand, 0, 0); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, models.SuccessCommitStatus, command.PolicyCheck, 0, 0); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } @@ -50,7 +50,7 @@ func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []models.Proje } // So set policy_check commit status to pending - if err := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.PendingCommitStatus, models.PolicyCheckCommand); err != nil { + if err := p.commitStatusUpdater.UpdateCombined(ctx.Pull.BaseRepo, ctx.Pull, models.PendingCommitStatus, command.PolicyCheck); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } @@ -84,7 +84,7 @@ func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *command.Context, pull status = models.FailedCommitStatus } - if err := p.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, status, models.PolicyCheckCommand, numSuccess, len(pullStatus.Projects)); err != nil { + if err := p.commitStatusUpdater.UpdateCombinedCount(ctx.Pull.BaseRepo, ctx.Pull, status, command.PolicyCheck, numSuccess, len(pullStatus.Projects)); err != nil { ctx.Log.Warn("unable to update commit status: %s", err) } } diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 96c3b48e3..07fb21b85 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -309,7 +309,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context projCtxs = append(projCtxs, p.ProjectCommandContextBuilder.BuildProjectContext( ctx, - models.PlanCommand, + command.Plan, mergedCfg, commentFlags, repoDir, @@ -340,7 +340,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context projCtxs = append(projCtxs, p.ProjectCommandContextBuilder.BuildProjectContext( ctx, - models.PlanCommand, + command.Plan, pCfg, commentFlags, repoDir, @@ -388,7 +388,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Cont return p.buildProjectCommandCtx( ctx, - models.PlanCommand, + command.Plan, cmd.ProjectName, cmd.Flags, defaultRepoDir, @@ -521,7 +521,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Con return p.buildProjectCommandCtx( ctx, - models.ApplyCommand, + command.Apply, cmd.ProjectName, cmd.Flags, repoDir, @@ -563,7 +563,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.C return p.buildProjectCommandCtx( ctx, - models.VersionCommand, + command.Version, cmd.ProjectName, cmd.Flags, repoDir, @@ -577,7 +577,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.C // buildProjectCommandCtx builds a context for a single or several projects identified // by the parameters. func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Context, - cmd models.CommandName, + cmd command.Name, projectName string, commentFlags []string, repoDir string, diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index 0530d9bf7..5d2dc7aff 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -621,7 +621,7 @@ projects: } // We run a test for each type of command. - for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { + for _, cmd := range []command.Name{command.Plan, command.Apply} { t.Run(cmd.String(), func(t *testing.T) { ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Log: logger, @@ -644,9 +644,9 @@ projects: // Construct expected steps. var stepNames []string switch cmd { - case models.PlanCommand: + case command.Plan: stepNames = c.expPlanSteps - case models.ApplyCommand: + case command.Apply: stepNames = c.expApplySteps } var expSteps []valid.Step @@ -816,7 +816,7 @@ projects: } // We run a test for each type of command, again specific projects - for _, cmd := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { + for _, cmd := range []command.Name{command.Plan, command.Apply} { t.Run(cmd.String(), func(t *testing.T) { ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Pull: models.PullRequest{ @@ -840,9 +840,9 @@ projects: // Construct expected steps. var stepNames []string switch cmd { - case models.PlanCommand: + case command.Plan: stepNames = c.expPlanSteps - case models.ApplyCommand: + case command.Apply: stepNames = c.expApplySteps } var expSteps []valid.Step @@ -1041,7 +1041,7 @@ workflows: AutoplanFileList: "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl", } - cmd := models.PolicyCheckCommand + cmd := command.PolicyCheck t.Run(cmd.String(), func(t *testing.T) { ctxs, err := builder.buildProjectCommandCtx(&command.Context{ Log: logger, @@ -1051,7 +1051,7 @@ workflows: PullRequestStatus: models.PullReqStatus{ Mergeable: true, }, - }, models.PlanCommand, "", []string{"flag"}, tmp, "project1", "myworkspace", true, false) + }, command.Plan, "", []string{"flag"}, tmp, "project1", "myworkspace", true, false) if c.expErr != "" { ErrEquals(t, c.expErr, err) diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index fe61ffc4b..a754cb15b 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -202,7 +202,7 @@ func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T) Cmd: events.CommentCommand{ RepoRelDir: ".", Flags: []string{"commentarg"}, - Name: models.PlanCommand, + Name: command.Plan, Workspace: "myworkspace", }, AtlantisYAML: "", @@ -215,7 +215,7 @@ func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T) Description: "no atlantis.yaml with project flag", Cmd: events.CommentCommand{ RepoRelDir: ".", - Name: models.PlanCommand, + Name: command.Plan, ProjectName: "myproject", }, AtlantisYAML: "", @@ -225,7 +225,7 @@ func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T) Description: "simple atlantis.yaml", Cmd: events.CommentCommand{ RepoRelDir: ".", - Name: models.PlanCommand, + Name: command.Plan, Workspace: "myworkspace", }, AtlantisYAML: ` @@ -242,7 +242,7 @@ projects: Description: "atlantis.yaml wrong dir", Cmd: events.CommentCommand{ RepoRelDir: ".", - Name: models.PlanCommand, + Name: command.Plan, Workspace: "myworkspace", }, AtlantisYAML: ` @@ -259,7 +259,7 @@ projects: Description: "atlantis.yaml wrong workspace", Cmd: events.CommentCommand{ RepoRelDir: ".", - Name: models.PlanCommand, + Name: command.Plan, Workspace: "myworkspace", }, AtlantisYAML: ` @@ -273,7 +273,7 @@ projects: { Description: "atlantis.yaml with projectname", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, ProjectName: "myproject", }, AtlantisYAML: ` @@ -291,7 +291,7 @@ projects: { Description: "atlantis.yaml with mergeable apply requirement", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, ProjectName: "myproject", }, AtlantisYAML: ` @@ -309,7 +309,7 @@ projects: { Description: "atlantis.yaml with mergeable and approved apply requirements", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, ProjectName: "myproject", }, AtlantisYAML: ` @@ -327,7 +327,7 @@ projects: { Description: "atlantis.yaml with multiple dir/workspaces matching", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, RepoRelDir: ".", Workspace: "myworkspace", }, @@ -347,7 +347,7 @@ projects: { Description: "atlantis.yaml with project flag not matching", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, RepoRelDir: ".", Workspace: "default", ProjectName: "notconfigured", @@ -362,7 +362,7 @@ projects: { Description: "atlantis.yaml with ParallelPlan Set to true", Cmd: events.CommentCommand{ - Name: models.PlanCommand, + Name: command.Plan, RepoRelDir: ".", Workspace: "default", ProjectName: "myproject", @@ -389,7 +389,7 @@ projects: for _, c := range cases { // NOTE: we're testing both plan and apply here. - for _, cmdName := range []models.CommandName{models.PlanCommand, models.ApplyCommand} { + for _, cmdName := range []command.Name{command.Plan, command.Apply} { t.Run(c.Description+"_"+cmdName.String(), func(t *testing.T) { RegisterMockTestingT(t) tmpDir, cleanup := DirStructure(t, map[string]interface{}{ @@ -433,7 +433,7 @@ projects: var actCtxs []models.ProjectCommandContext var err error - if cmdName == models.PlanCommand { + if cmdName == command.Plan { actCtxs, err = builder.BuildPlanCommands(&command.Context{ Log: logger, Scope: scope, @@ -594,7 +594,7 @@ projects: &events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, Workspace: "", ProjectName: "", @@ -685,7 +685,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiApply(t *testing.T) { &events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.ApplyCommand, + Name: command.Apply, Verbose: false, Workspace: "", ProjectName: "", @@ -772,7 +772,7 @@ projects: _, err = builder.BuildPlanCommands(ctx, &events.CommentCommand{ RepoRelDir: ".", Flags: nil, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, Workspace: "notconfigured", ProjectName: "", @@ -849,7 +849,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { }, &events.CommentCommand{ RepoRelDir: ".", Flags: c.ExtraArgs, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, Workspace: "default", }) @@ -1032,7 +1032,7 @@ projects: &events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.PlanCommand, + Name: command.Plan, Verbose: false, }) @@ -1161,9 +1161,9 @@ func TestDefaultProjectCommandBuilder_WithPolicyCheckEnabled_BuildAutoplanComman Equals(t, 2, len(ctxs)) planCtx := ctxs[0] policyCheckCtx := ctxs[1] - Equals(t, models.PlanCommand, planCtx.CommandName) + Equals(t, command.Plan, planCtx.CommandName) Equals(t, globalCfg.Workflows["default"].Plan.Steps, planCtx.Steps) - Equals(t, models.PolicyCheckCommand, policyCheckCtx.CommandName) + Equals(t, command.PolicyCheck, policyCheckCtx.CommandName) Equals(t, globalCfg.Workflows["default"].PolicyCheck.Steps, policyCheckCtx.Steps) } @@ -1238,7 +1238,7 @@ func TestDefaultProjectCommandBuilder_BuildVersionCommand(t *testing.T) { &events.CommentCommand{ RepoRelDir: "", Flags: nil, - Name: models.VersionCommand, + Name: command.Version, Verbose: false, Workspace: "", ProjectName: "", diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index 240879a29..ea0b21563 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -46,7 +46,7 @@ type ProjectCommandContextBuilder interface { // BuildProjectContext builds project command contexts for atlantis commands BuildProjectContext( ctx *command.Context, - cmdName models.CommandName, + cmdName command.Name, prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, @@ -65,7 +65,7 @@ type CommandScopedStatsProjectCommandContextBuilder struct { // BuildProjectContext builds the context and injects the appropriate command level scope after the fact. func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( ctx *command.Context, - cmdName models.CommandName, + cmdName command.Name, prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, @@ -97,7 +97,7 @@ type DefaultProjectCommandContextBuilder struct { func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( ctx *command.Context, - cmdName models.CommandName, + cmdName command.Name, prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, @@ -107,11 +107,11 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( var steps []valid.Step switch cmdName { - case models.PlanCommand: + case command.Plan: steps = prjCfg.Workflow.Plan.Steps - case models.ApplyCommand: + case command.Apply: steps = prjCfg.Workflow.Apply.Steps - case models.VersionCommand: + case command.Version: // Setting statically since there will only be one step steps = []valid.Step{{ StepName: "version", @@ -151,7 +151,7 @@ type PolicyCheckProjectCommandContextBuilder struct { func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( ctx *command.Context, - cmdName models.CommandName, + cmdName command.Name, prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, @@ -174,13 +174,13 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( contextFlags, ) - if cmdName == models.PlanCommand { - ctx.Log.Debug("Building project command context for %s", models.PolicyCheckCommand) + if cmdName == command.Plan { + ctx.Log.Debug("Building project command context for %s", command.PolicyCheck) steps := prjCfg.Workflow.PolicyCheck.Steps projectCmds = append(projectCmds, newProjectCommandContext( ctx, - models.PolicyCheckCommand, + command.PolicyCheck, cb.CommentBuilder.BuildApplyComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, prjCfg.AutoMergeDisabled), cb.CommentBuilder.BuildPlanComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name, commentFlags), cb.CommentBuilder.BuildVersionComment(prjCfg.RepoRelDir, prjCfg.Workspace, prjCfg.Name), @@ -200,7 +200,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( // newProjectCommandContext is a initializer method that handles constructing the // ProjectCommandContext. func newProjectCommandContext(ctx *command.Context, - cmd models.CommandName, + cmd command.Name, applyCmd string, planCmd string, versionCmd string, diff --git a/server/events/project_command_context_builder_test.go b/server/events/project_command_context_builder_test.go index 5275bd252..36ce95dee 100644 --- a/server/events/project_command_context_builder_test.go +++ b/server/events/project_command_context_builder_test.go @@ -65,7 +65,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { Verbose: false, ForceApply: false, } - result := subject.BuildProjectContext(commandCtx, models.PlanCommand, projCfg, []string{}, "some/dir", contextFlags) + result := subject.BuildProjectContext(commandCtx, command.Plan, projCfg, []string{}, "some/dir", contextFlags) assert.Equal(t, models.ErroredPolicyCheckStatus, result[0].ProjectPlanStatus) }) @@ -93,7 +93,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { ForceApply: false, } - result := subject.BuildProjectContext(commandCtx, models.PlanCommand, projCfg, []string{}, "some/dir", contextFlags) + result := subject.BuildProjectContext(commandCtx, command.Plan, projCfg, []string{}, "some/dir", contextFlags) assert.Equal(t, models.ErroredPolicyCheckStatus, result[0].ProjectPlanStatus) }) @@ -120,7 +120,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { Verbose: false, ForceApply: false, } - result := subject.BuildProjectContext(commandCtx, models.PlanCommand, projCfg, []string{}, "some/dir", contextFlags) + result := subject.BuildProjectContext(commandCtx, command.Plan, projCfg, []string{}, "some/dir", contextFlags) assert.True(t, result[0].ParallelApplyEnabled) assert.False(t, result[0].ParallelPlanEnabled) diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index 05b71fd63..56f51e9c7 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/remeh/sizedwaitgroup" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index f8a6b9bf6..ec6b04798 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -22,6 +22,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/webhooks" "github.com/runatlantis/atlantis/server/logging" @@ -122,7 +123,7 @@ type ProjectCommandRunner interface { type JobURLSetter interface { // SetJobURLWithStatus sets the commit status for the project represented by // ctx and updates the status with and url to a job. - SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus) error + SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_job_closer.go JobCloser @@ -141,18 +142,18 @@ type ProjectOutputWrapper struct { } func (p *ProjectOutputWrapper) Plan(ctx models.ProjectCommandContext) models.ProjectResult { - result := p.updateProjectPRStatus(models.PlanCommand, ctx, p.ProjectCommandRunner.Plan) + result := p.updateProjectPRStatus(command.Plan, ctx, p.ProjectCommandRunner.Plan) p.JobCloser.CloseJob(ctx.JobID) return result } func (p *ProjectOutputWrapper) Apply(ctx models.ProjectCommandContext) models.ProjectResult { - result := p.updateProjectPRStatus(models.ApplyCommand, ctx, p.ProjectCommandRunner.Apply) + result := p.updateProjectPRStatus(command.Apply, ctx, p.ProjectCommandRunner.Apply) p.JobCloser.CloseJob(ctx.JobID) return result } -func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName models.CommandName, ctx models.ProjectCommandContext, execute func(ctx models.ProjectCommandContext) models.ProjectResult) models.ProjectResult { +func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx models.ProjectCommandContext, execute func(ctx models.ProjectCommandContext) models.ProjectResult) models.ProjectResult { // Create a PR status to track project's plan status. The status will // include a link to view the progress of atlantis plan command in real // time @@ -210,7 +211,7 @@ type DefaultProjectCommandRunner struct { //create object and test func (p *DefaultProjectCommandRunner) Plan(ctx models.ProjectCommandContext) models.ProjectResult { planSuccess, failure, err := p.doPlan(ctx) return models.ProjectResult{ - Command: models.PlanCommand, + Command: command.Plan, PlanSuccess: planSuccess, Error: err, Failure: failure, @@ -224,7 +225,7 @@ func (p *DefaultProjectCommandRunner) Plan(ctx models.ProjectCommandContext) mod func (p *DefaultProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult { policySuccess, failure, err := p.doPolicyCheck(ctx) return models.ProjectResult{ - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, PolicyCheckSuccess: policySuccess, Error: err, Failure: failure, @@ -238,7 +239,7 @@ func (p *DefaultProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandConte func (p *DefaultProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { applyOut, failure, err := p.doApply(ctx) return models.ProjectResult{ - Command: models.ApplyCommand, + Command: command.Apply, Failure: failure, Error: err, ApplySuccess: applyOut, @@ -251,7 +252,7 @@ func (p *DefaultProjectCommandRunner) Apply(ctx models.ProjectCommandContext) mo func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandContext) models.ProjectResult { approvedOut, failure, err := p.doApprovePolicies(ctx) return models.ProjectResult{ - Command: models.PolicyCheckCommand, + Command: command.PolicyCheck, Failure: failure, Error: err, PolicyCheckSuccess: approvedOut, @@ -264,7 +265,7 @@ func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandC func (p *DefaultProjectCommandRunner) Version(ctx models.ProjectCommandContext) models.ProjectResult { versionOut, failure, err := p.doVersion(ctx) return models.ProjectResult{ - Command: models.VersionCommand, + Command: command.Version, Failure: failure, Error: err, VersionSuccess: versionOut, diff --git a/server/events/project_command_runner_test.go b/server/events/project_command_runner_test.go index 63461e96b..c53da626e 100644 --- a/server/events/project_command_runner_test.go +++ b/server/events/project_command_runner_test.go @@ -25,6 +25,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" tmocks "github.com/runatlantis/atlantis/server/core/terraform/mocks" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" eventmocks "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" @@ -149,37 +150,37 @@ func TestProjectOutputWrapper(t *testing.T) { Failure bool Error bool Success bool - CommandName models.CommandName + CommandName command.Name }{ { Description: "plan success", Success: true, - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { Description: "plan failure", Failure: true, - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { Description: "plan error", Error: true, - CommandName: models.PlanCommand, + CommandName: command.Plan, }, { Description: "apply success", Success: true, - CommandName: models.ApplyCommand, + CommandName: command.Apply, }, { Description: "apply failure", Failure: true, - CommandName: models.ApplyCommand, + CommandName: command.Apply, }, { Description: "apply error", Error: true, - CommandName: models.ApplyCommand, + CommandName: command.Apply, }, } @@ -220,9 +221,9 @@ func TestProjectOutputWrapper(t *testing.T) { When(mockProjectCommandRunner.Apply(matchers.AnyModelsProjectCommandContext())).ThenReturn(prjResult) switch c.CommandName { - case models.PlanCommand: + case command.Plan: runner.Plan(ctx) - case models.ApplyCommand: + case command.Apply: runner.Apply(ctx) } @@ -230,9 +231,9 @@ func TestProjectOutputWrapper(t *testing.T) { mockJobURLSetter.VerifyWasCalled(Once()).SetJobURLWithStatus(ctx, c.CommandName, expCommitStatus) switch c.CommandName { - case models.PlanCommand: + case command.Plan: mockProjectCommandRunner.VerifyWasCalledOnce().Plan(ctx) - case models.ApplyCommand: + case command.Apply: mockProjectCommandRunner.VerifyWasCalledOnce().Apply(ctx) } }) diff --git a/server/events/pull_updater.go b/server/events/pull_updater.go index 04b6a9a2b..c91d2c7c2 100644 --- a/server/events/pull_updater.go +++ b/server/events/pull_updater.go @@ -3,7 +3,6 @@ package events import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) diff --git a/server/events/size_limited_project_command_builder.go b/server/events/size_limited_project_command_builder.go index 10323cc13..c8d336723 100644 --- a/server/events/size_limited_project_command_builder.go +++ b/server/events/size_limited_project_command_builder.go @@ -39,7 +39,7 @@ func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []models.P for _, project := range projects { - if project.CommandName == models.PlanCommand { + if project.CommandName == command.Plan { planCommands = append(planCommands, project) } } diff --git a/server/events/size_limited_project_command_builder_test.go b/server/events/size_limited_project_command_builder_test.go index 18ad209b0..31765d5f7 100644 --- a/server/events/size_limited_project_command_builder_test.go +++ b/server/events/size_limited_project_command_builder_test.go @@ -20,17 +20,17 @@ func TestSizeLimitedProjectCommandBuilder_autoplan(t *testing.T) { project1 := models.ProjectCommandContext{ ProjectName: "test1", - CommandName: models.PlanCommand, + CommandName: command.Plan, } project2 := models.ProjectCommandContext{ ProjectName: "test2", - CommandName: models.PlanCommand, + CommandName: command.Plan, } project3 := models.ProjectCommandContext{ ProjectName: "test1", - CommandName: models.PolicyCheckCommand, + CommandName: command.PolicyCheck, } expectedResult := []models.ProjectCommandContext{project1, project2} @@ -111,12 +111,12 @@ func TestSizeLimitedProjectCommandBuilder_planComment(t *testing.T) { project1 := models.ProjectCommandContext{ ProjectName: "test1", - CommandName: models.PlanCommand, + CommandName: command.Plan, } project2 := models.ProjectCommandContext{ ProjectName: "test2", - CommandName: models.PlanCommand, + CommandName: command.Plan, } expectedResult := []models.ProjectCommandContext{project1, project2} diff --git a/server/events/unlock_command_runner.go b/server/events/unlock_command_runner.go index d6711a4f9..bf8e6aca7 100644 --- a/server/events/unlock_command_runner.go +++ b/server/events/unlock_command_runner.go @@ -2,7 +2,6 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -45,7 +44,7 @@ func (u *UnlockCommandRunner) Run( return } - if commentErr := u.vcsClient.CreateComment(baseRepo, pullNum, vcsMessage, models.UnlockCommand.String()); commentErr != nil { + if commentErr := u.vcsClient.CreateComment(baseRepo, pullNum, vcsMessage, command.UnlockCommand.String()); commentErr != nil { ctx.Log.Err("unable to comment: %s", commentErr) } } diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index bb2d28375..016ba332e 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/logging" @@ -231,7 +232,7 @@ func TestGithubClient_PaginatesComments(t *testing.T) { }, }, 123, - models.PlanCommand.TitleString(), + command.Plan.TitleString(), ) Ok(t, err) Equals(t, 2, len(gotMinimizeCalls)) @@ -321,7 +322,7 @@ func TestGithubClient_HideOldComments(t *testing.T) { }, }, 123, - models.PlanCommand.TitleString(), + command.Plan.TitleString(), ) Ok(t, err) Equals(t, 3, len(gotMinimizeCalls)) @@ -1056,7 +1057,7 @@ func TestGithubClient_SplitComments(t *testing.T) { } // create an extra long string comment := strings.Repeat("a", 65537) - err = client.CreateComment(repo, pull.Num, comment, models.PlanCommand.String()) + err = client.CreateComment(repo, pull.Num, comment, command.Plan.String()) Ok(t, err) err = client.CreateComment(repo, pull.Num, comment, "") Ok(t, err) @@ -1067,7 +1068,7 @@ func TestGithubClient_SplitComments(t *testing.T) { secondSplit := strings.ToLower(body[0]) Equals(t, 4, len(githubComments)) - Assert(t, strings.Contains(firstSplit, models.PlanCommand.String()), fmt.Sprintf("comment should contain the command name but was %q", firstSplit)) + Assert(t, strings.Contains(firstSplit, command.Plan.String()), fmt.Sprintf("comment should contain the command name but was %q", firstSplit)) Assert(t, strings.Contains(secondSplit, "continued from previous comment"), fmt.Sprintf("comment should contain no reference to the command name but was %q", secondSplit)) } diff --git a/server/events/vcs/gitlab_client.go b/server/events/vcs/gitlab_client.go index 582d62af9..c03ebdaf1 100644 --- a/server/events/vcs/gitlab_client.go +++ b/server/events/vcs/gitlab_client.go @@ -24,6 +24,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/vcs/common" version "github.com/hashicorp/go-version" @@ -211,7 +212,7 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest } for _, status := range statuses { - if !strings.HasSuffix(status.Name, fmt.Sprintf("/%s", models.ApplyCommand.String())) { + if !strings.HasSuffix(status.Name, fmt.Sprintf("/%s", command.Apply.String())) { if !status.AllowFailure && project.OnlyAllowMergeIfPipelineSucceeds && status.Status != "success" { return false, nil } diff --git a/server/jobs/job_url_setter.go b/server/jobs/job_url_setter.go index d681935c5..1ae6eba2a 100644 --- a/server/jobs/job_url_setter.go +++ b/server/jobs/job_url_setter.go @@ -1,6 +1,9 @@ package jobs -import "github.com/runatlantis/atlantis/server/events/models" +import ( + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" +) //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_job_url_generator.go ProjectJobURLGenerator @@ -14,7 +17,7 @@ type ProjectJobURLGenerator interface { type ProjectStatusUpdater interface { // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus, url string) error + UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error } type JobURLSetter struct { @@ -29,7 +32,7 @@ func NewJobURLSetter(projectJobURLGenerator ProjectJobURLGenerator, projectStatu } } -func (j *JobURLSetter) SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName models.CommandName, status models.CommitStatus) error { +func (j *JobURLSetter) SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus) error { url, err := j.projectJobURLGenerator.GenerateProjectJobURL(ctx) if err != nil { diff --git a/server/jobs/job_url_setter_test.go b/server/jobs/job_url_setter_test.go index 5ae8073c6..4b19edcbc 100644 --- a/server/jobs/job_url_setter_test.go +++ b/server/jobs/job_url_setter_test.go @@ -5,6 +5,7 @@ import ( "testing" . "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/jobs" "github.com/runatlantis/atlantis/server/jobs/mocks" @@ -24,11 +25,11 @@ func TestJobURLSetter(t *testing.T) { jobURLSetter := jobs.NewJobURLSetter(projectJobURLGenerator, projectStatusUpdater) When(projectJobURLGenerator.GenerateProjectJobURL(matchers.EqModelsProjectCommandContext(ctx))).ThenReturn(url, nil) - When(projectStatusUpdater.UpdateProject(ctx, models.PlanCommand, models.PendingCommitStatus, url)).ThenReturn(nil) - err := jobURLSetter.SetJobURLWithStatus(ctx, models.PlanCommand, models.PendingCommitStatus) + When(projectStatusUpdater.UpdateProject(ctx, command.Plan, models.PendingCommitStatus, url)).ThenReturn(nil) + err := jobURLSetter.SetJobURLWithStatus(ctx, command.Plan, models.PendingCommitStatus) Ok(t, err) - projectStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, models.PlanCommand, models.PendingCommitStatus, "url-to-project-jobs") + projectStatusUpdater.VerifyWasCalledOnce().UpdateProject(ctx, command.Plan, models.PendingCommitStatus, "url-to-project-jobs") }) t.Run("update project status with project jobs url error", func(t *testing.T) { @@ -38,7 +39,7 @@ func TestJobURLSetter(t *testing.T) { jobURLSetter := jobs.NewJobURLSetter(projectJobURLGenerator, projectStatusUpdater) When(projectJobURLGenerator.GenerateProjectJobURL(matchers.EqModelsProjectCommandContext(ctx))).ThenReturn("url-to-project-jobs", errors.New("some error")) - err := jobURLSetter.SetJobURLWithStatus(ctx, models.PlanCommand, models.PendingCommitStatus) + err := jobURLSetter.SetJobURLWithStatus(ctx, command.Plan, models.PendingCommitStatus) assert.Error(t, err) }) } diff --git a/server/jobs/mocks/matchers/chan_of_string.go b/server/jobs/mocks/matchers/chan_of_string.go index e1bfee572..44526eb9b 100644 --- a/server/jobs/mocks/matchers/chan_of_string.go +++ b/server/jobs/mocks/matchers/chan_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnyChanOfString() chan string { diff --git a/server/jobs/mocks/matchers/io_readcloser.go b/server/jobs/mocks/matchers/io_readcloser.go index abba94c9c..3c4060ad3 100644 --- a/server/jobs/mocks/matchers/io_readcloser.go +++ b/server/jobs/mocks/matchers/io_readcloser.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + io "io" ) diff --git a/server/jobs/mocks/matchers/jobs_job.go b/server/jobs/mocks/matchers/jobs_job.go index bc3112a1d..85aacba7a 100644 --- a/server/jobs/mocks/matchers/jobs_job.go +++ b/server/jobs/mocks/matchers/jobs_job.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) diff --git a/server/jobs/mocks/matchers/jobs_jobstatus.go b/server/jobs/mocks/matchers/jobs_jobstatus.go index 2d56719cd..1cbcfdd01 100644 --- a/server/jobs/mocks/matchers/jobs_jobstatus.go +++ b/server/jobs/mocks/matchers/jobs_jobstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) diff --git a/server/jobs/mocks/matchers/jobs_pullinfo.go b/server/jobs/mocks/matchers/jobs_pullinfo.go index 95e16a16f..64141c6b3 100644 --- a/server/jobs/mocks/matchers/jobs_pullinfo.go +++ b/server/jobs/mocks/matchers/jobs_pullinfo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) diff --git a/server/jobs/mocks/matchers/models_commandname.go b/server/jobs/mocks/matchers/models_commandname.go index f586b4d21..aec79b126 100644 --- a/server/jobs/mocks/matchers/models_commandname.go +++ b/server/jobs/mocks/matchers/models_commandname.go @@ -2,32 +2,32 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsCommandName() models.CommandName { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.CommandName))(nil)).Elem())) - var nullValue models.CommandName +func AnyModelsCommandName() command.Name { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.Name))(nil)).Elem())) + var nullValue command.Name return nullValue } -func EqModelsCommandName(value models.CommandName) models.CommandName { +func EqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func NotEqModelsCommandName(value models.CommandName) models.CommandName { +func NotEqModelsCommandName(value command.Name) command.Name { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.CommandName + var nullValue command.Name return nullValue } -func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) models.CommandName { +func ModelsCommandNameThat(matcher pegomock.ArgumentMatcher) command.Name { pegomock.RegisterMatcher(matcher) - var nullValue models.CommandName + var nullValue command.Name return nullValue } diff --git a/server/jobs/mocks/matchers/models_commitstatus.go b/server/jobs/mocks/matchers/models_commitstatus.go index 1e10ed782..5ebf733ee 100644 --- a/server/jobs/mocks/matchers/models_commitstatus.go +++ b/server/jobs/mocks/matchers/models_commitstatus.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/jobs/mocks/matchers/models_projectcommandcontext.go b/server/jobs/mocks/matchers/models_projectcommandcontext.go index 535f8b967..8972dd412 100644 --- a/server/jobs/mocks/matchers/models_projectcommandcontext.go +++ b/server/jobs/mocks/matchers/models_projectcommandcontext.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) diff --git a/server/jobs/mocks/matchers/slice_of_string.go b/server/jobs/mocks/matchers/slice_of_string.go index f9281819d..8bfc2792f 100644 --- a/server/jobs/mocks/matchers/slice_of_string.go +++ b/server/jobs/mocks/matchers/slice_of_string.go @@ -2,8 +2,9 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + + "github.com/petergtz/pegomock" ) func AnySliceOfString() []string { diff --git a/server/jobs/mocks/mock_job_store.go b/server/jobs/mocks/mock_job_store.go index e17b09e4d..f8a53d2fb 100644 --- a/server/jobs/mocks/mock_job_store.go +++ b/server/jobs/mocks/mock_job_store.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - jobs "github.com/runatlantis/atlantis/server/jobs" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + jobs "github.com/runatlantis/atlantis/server/jobs" ) type MockJobStore struct { diff --git a/server/jobs/mocks/mock_project_command_output_handler.go b/server/jobs/mocks/mock_project_command_output_handler.go index a0afc5562..967d159d0 100644 --- a/server/jobs/mocks/mock_project_command_output_handler.go +++ b/server/jobs/mocks/mock_project_command_output_handler.go @@ -4,11 +4,12 @@ package mocks import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" models "github.com/runatlantis/atlantis/server/events/models" jobs "github.com/runatlantis/atlantis/server/jobs" - "reflect" - "time" ) type MockProjectCommandOutputHandler struct { diff --git a/server/jobs/mocks/mock_project_job_url_generator.go b/server/jobs/mocks/mock_project_job_url_generator.go index 385cc6410..6f365d6cf 100644 --- a/server/jobs/mocks/mock_project_job_url_generator.go +++ b/server/jobs/mocks/mock_project_job_url_generator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockProjectJobURLGenerator struct { diff --git a/server/jobs/mocks/mock_project_status_updater.go b/server/jobs/mocks/mock_project_status_updater.go index 4ea237d0f..792126aa0 100644 --- a/server/jobs/mocks/mock_project_status_updater.go +++ b/server/jobs/mocks/mock_project_status_updater.go @@ -4,10 +4,12 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command" + models "github.com/runatlantis/atlantis/server/events/models" ) type MockProjectStatusUpdater struct { @@ -25,7 +27,7 @@ func NewMockProjectStatusUpdater(options ...pegomock.Option) *MockProjectStatusU func (mock *MockProjectStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 models.CommandName, _param2 models.CommitStatus, _param3 string) error { +func (mock *MockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectStatusUpdater().") } @@ -77,7 +79,7 @@ type VerifierMockProjectStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 models.CommandName, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2, _param3} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockProjectStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -88,21 +90,21 @@ type MockProjectStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, models.CommandName, models.CommitStatus, string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus, string) { _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []models.CommandName, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(models.ProjectCommandContext) } - _param1 = make([]models.CommandName, len(c.methodInvocations)) + _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(models.CommandName) + _param1[u] = param.(command.Name) } _param2 = make([]models.CommitStatus, len(c.methodInvocations)) for u, param := range params[2] { diff --git a/server/jobs/mocks/mock_storage_backend.go b/server/jobs/mocks/mock_storage_backend.go index ad66535c4..d1176aa91 100644 --- a/server/jobs/mocks/mock_storage_backend.go +++ b/server/jobs/mocks/mock_storage_backend.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockStorageBackend struct { diff --git a/server/logging/mocks/matchers/logging_loglevel.go b/server/logging/mocks/matchers/logging_loglevel.go index bba8254e7..c1f742113 100644 --- a/server/logging/mocks/matchers/logging_loglevel.go +++ b/server/logging/mocks/matchers/logging_loglevel.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/logging/mocks/matchers/logging_simplelogging.go b/server/logging/mocks/matchers/logging_simplelogging.go index 502456e7c..c3b96f61f 100644 --- a/server/logging/mocks/matchers/logging_simplelogging.go +++ b/server/logging/mocks/matchers/logging_simplelogging.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/logging/mocks/matchers/ptr_to_log_logger.go b/server/logging/mocks/matchers/ptr_to_log_logger.go index a15f6620a..73a8e575a 100644 --- a/server/logging/mocks/matchers/ptr_to_log_logger.go +++ b/server/logging/mocks/matchers/ptr_to_log_logger.go @@ -2,9 +2,10 @@ package matchers import ( + log "log" "reflect" + "github.com/petergtz/pegomock" - log "log" ) func AnyPtrToLogLogger() *log.Logger { diff --git a/server/logging/mocks/matchers/ptr_to_logging_simplelogger.go b/server/logging/mocks/matchers/ptr_to_logging_simplelogger.go index cf9bb5453..e7c8b942f 100644 --- a/server/logging/mocks/matchers/ptr_to_logging_simplelogger.go +++ b/server/logging/mocks/matchers/ptr_to_logging_simplelogger.go @@ -2,9 +2,10 @@ package matchers import ( + "reflect" + "github.com/petergtz/pegomock" logging "github.com/runatlantis/atlantis/server/logging" - "reflect" ) func AnyPtrToLoggingSimpleLogger() logging.SimpleLogging { diff --git a/server/logging/mocks/mock_simple_logging.go b/server/logging/mocks/mock_simple_logging.go index 3efaa7b0c..36e97c84b 100644 --- a/server/logging/mocks/mock_simple_logging.go +++ b/server/logging/mocks/mock_simple_logging.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - logging "github.com/runatlantis/atlantis/server/logging" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) type MockSimpleLogging struct { diff --git a/server/lyft/aws/sns/mocks/matchers/slice_of_byte.go b/server/lyft/aws/sns/mocks/matchers/slice_of_byte.go index 9a9894fa0..4ca934d51 100644 --- a/server/lyft/aws/sns/mocks/matchers/slice_of_byte.go +++ b/server/lyft/aws/sns/mocks/matchers/slice_of_byte.go @@ -3,8 +3,8 @@ package matchers import ( "reflect" + "github.com/petergtz/pegomock" - ) func AnySliceOfByte() []byte { diff --git a/server/lyft/aws/sns/mocks/mock_writer.go b/server/lyft/aws/sns/mocks/mock_writer.go index abccb7aac..db336d19e 100644 --- a/server/lyft/aws/sns/mocks/mock_writer.go +++ b/server/lyft/aws/sns/mocks/mock_writer.go @@ -4,9 +4,10 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" ) type MockWriter struct { diff --git a/server/lyft/aws/sqs/message.go b/server/lyft/aws/sqs/message.go index 0dab7a673..28a09b5ae 100644 --- a/server/lyft/aws/sqs/message.go +++ b/server/lyft/aws/sqs/message.go @@ -3,10 +3,11 @@ package sqs import ( "bufio" "bytes" + "net/http" + "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/pkg/errors" "github.com/uber-go/tally" - "net/http" ) //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_sqs_message_handler.go MessageProcessor diff --git a/server/lyft/aws/sqs/message_test.go b/server/lyft/aws/sqs/message_test.go index 6faf85b96..14b85121c 100644 --- a/server/lyft/aws/sqs/message_test.go +++ b/server/lyft/aws/sqs/message_test.go @@ -2,6 +2,9 @@ package sqs_test import ( "bytes" + "net/http" + "net/url" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/sqs/types" . "github.com/petergtz/pegomock" @@ -11,8 +14,6 @@ import ( . "github.com/runatlantis/atlantis/testing" "github.com/stretchr/testify/assert" "github.com/uber-go/tally" - "net/http" - "net/url" "testing" ) diff --git a/server/lyft/aws/sqs/mocks/matchers/types_message.go b/server/lyft/aws/sqs/mocks/matchers/types_message.go index 500dec5e9..be47cd424 100644 --- a/server/lyft/aws/sqs/mocks/matchers/types_message.go +++ b/server/lyft/aws/sqs/mocks/matchers/types_message.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + types "github.com/aws/aws-sdk-go-v2/service/sqs/types" ) diff --git a/server/lyft/aws/sqs/mocks/mock_sqs_message_handler.go b/server/lyft/aws/sqs/mocks/mock_sqs_message_handler.go index 0b6eaf864..c00061100 100644 --- a/server/lyft/aws/sqs/mocks/mock_sqs_message_handler.go +++ b/server/lyft/aws/sqs/mocks/mock_sqs_message_handler.go @@ -4,10 +4,11 @@ package mocks import ( - types "github.com/aws/aws-sdk-go-v2/service/sqs/types" - pegomock "github.com/petergtz/pegomock" "reflect" "time" + + types "github.com/aws/aws-sdk-go-v2/service/sqs/types" + pegomock "github.com/petergtz/pegomock" ) type MockMessageProcessor struct { diff --git a/server/lyft/aws/sqs/queue.go b/server/lyft/aws/sqs/queue.go index bd3b3da5e..7eeded9b7 100644 --- a/server/lyft/aws/sqs/queue.go +++ b/server/lyft/aws/sqs/queue.go @@ -3,6 +3,7 @@ package sqs import ( "context" "fmt" + "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/uber-go/tally" ) diff --git a/server/lyft/aws/sqs/worker.go b/server/lyft/aws/sqs/worker.go index 387328702..1d22be9a1 100644 --- a/server/lyft/aws/sqs/worker.go +++ b/server/lyft/aws/sqs/worker.go @@ -2,11 +2,12 @@ package sqs import ( "context" + "sync" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/uber-go/tally" - "sync" ) const ( diff --git a/server/lyft/decorators/audit_project_commands_wrapper_test.go b/server/lyft/decorators/audit_project_commands_wrapper_test.go index c7aca1676..cccb76d9b 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper_test.go +++ b/server/lyft/decorators/audit_project_commands_wrapper_test.go @@ -8,10 +8,10 @@ import ( . "github.com/runatlantis/atlantis/testing" . "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" - "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/logging" snsMocks "github.com/runatlantis/atlantis/server/lyft/aws/sns/mocks" "github.com/runatlantis/atlantis/server/lyft/decorators" diff --git a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go index 5fda841fc..76d0ab66b 100644 --- a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go +++ b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go @@ -2,13 +2,14 @@ package decorators_test import ( "fmt" - "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/core/runtime" - "github.com/runatlantis/atlantis/server/core/terraform/mocks" "os" "path/filepath" "testing" + "github.com/hashicorp/go-version" + "github.com/runatlantis/atlantis/server/core/runtime" + "github.com/runatlantis/atlantis/server/core/terraform/mocks" + "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" "github.com/runatlantis/atlantis/server/lyft/decorators" diff --git a/server/lyft/feature/mocks/matchers/feature_name.go b/server/lyft/feature/mocks/matchers/feature_name.go index b09ae7406..3d253d619 100644 --- a/server/lyft/feature/mocks/matchers/feature_name.go +++ b/server/lyft/feature/mocks/matchers/feature_name.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + feature "github.com/runatlantis/atlantis/server/lyft/feature" ) diff --git a/server/lyft/feature/mocks/mock_allocator.go b/server/lyft/feature/mocks/mock_allocator.go index 3c25b162c..8c753f892 100644 --- a/server/lyft/feature/mocks/mock_allocator.go +++ b/server/lyft/feature/mocks/mock_allocator.go @@ -4,10 +4,11 @@ package mocks import ( - pegomock "github.com/petergtz/pegomock" - feature "github.com/runatlantis/atlantis/server/lyft/feature" "reflect" "time" + + pegomock "github.com/petergtz/pegomock" + feature "github.com/runatlantis/atlantis/server/lyft/feature" ) type MockAllocator struct { diff --git a/server/lyft/scheduled/executor_service.go b/server/lyft/scheduled/executor_service.go index f7fa59e1c..072ec355a 100644 --- a/server/lyft/scheduled/executor_service.go +++ b/server/lyft/scheduled/executor_service.go @@ -2,12 +2,6 @@ package scheduled import ( "context" - "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/metrics" - "github.com/runatlantis/atlantis/server/events/models" - "github.com/runatlantis/atlantis/server/events/vcs" - "github.com/runatlantis/atlantis/server/logging" - "github.com/uber-go/tally" "io" "os" "os/signal" @@ -16,6 +10,13 @@ import ( "syscall" "text/template" "time" + + "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/metrics" + "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/vcs" + "github.com/runatlantis/atlantis/server/logging" + "github.com/uber-go/tally" ) type ExecutorService struct { diff --git a/server/server.go b/server/server.go index 04734f43d..e2d147c74 100644 --- a/server/server.go +++ b/server/server.go @@ -708,12 +708,12 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { userConfig.SilenceNoProjects, ) - commentCommandRunnerByCmd := map[models.CommandName]events.CommentCommandRunner{ - models.PlanCommand: planCommandRunner, - models.ApplyCommand: applyCommandRunner, - models.ApprovePoliciesCommand: approvePoliciesCommandRunner, - models.UnlockCommand: unlockCommandRunner, - models.VersionCommand: versionCommandRunner, + commentCommandRunnerByCmd := map[command.Name]events.CommentCommandRunner{ + command.Plan: planCommandRunner, + command.Apply: applyCommandRunner, + command.ApprovePolicies: approvePoliciesCommandRunner, + command.UnlockCommand: unlockCommandRunner, + command.Version: versionCommandRunner, } cmdStatsScope := statsScope.SubScope("cmd") staleCommandChecker := &events.StaleCommandHandler{ diff --git a/server/static/bindata_assetfs.go b/server/static/bindata_assetfs.go index 7c49505b5..9b3691516 100644 --- a/server/static/bindata_assetfs.go +++ b/server/static/bindata_assetfs.go @@ -10,7 +10,6 @@ package static import ( - "github.com/elazarl/go-bindata-assetfs" "bytes" "compress/gzip" "fmt" @@ -20,6 +19,8 @@ import ( "path/filepath" "strings" "time" + + assetfs "github.com/elazarl/go-bindata-assetfs" ) func bindataRead(data []byte, name string) ([]byte, error) { From 1f4464f035390091902df86047f059f9fca46417 Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Thu, 24 Feb 2022 16:36:05 -0800 Subject: [PATCH 4/7] move ProjectCommandContext and ProjectResult to command/project package --- CONTRIBUTING.md | 2 +- server/controllers/locks_controller_test.go | 3 +- server/core/db/boltdb.go | 5 +- server/core/db/boltdb_test.go | 14 +- server/core/runtime/apply_step_runner.go | 7 +- server/core/runtime/apply_step_runner_test.go | 21 +- server/core/runtime/env_step_runner.go | 4 +- server/core/runtime/env_step_runner_test.go | 3 +- server/core/runtime/executor.go | 4 +- server/core/runtime/init_step_runner.go | 4 +- server/core/runtime/init_step_runner_test.go | 18 +- .../minimum_version_step_runner_delegate.go | 4 +- ...nimum_version_step_runner_delegate_test.go | 10 +- .../matchers/models_projectcommandcontext.go | 21 +- server/core/runtime/mocks/mock_runner.go | 14 +- .../mocks/mock_versionedexecutorworkflow.go | 14 +- server/core/runtime/plan_step_runner.go | 13 +- server/core/runtime/plan_step_runner_test.go | 27 +-- .../runtime/plan_type_step_runner_delegate.go | 8 +- .../plan_type_step_runner_delegate_test.go | 10 +- server/core/runtime/policy/conftest_client.go | 4 +- .../runtime/policy/conftest_client_test.go | 4 +- .../core/runtime/policy_check_step_runner.go | 4 +- .../runtime/policy_check_step_runner_test.go | 3 +- server/core/runtime/run_step_runner.go | 4 +- server/core/runtime/run_step_runner_test.go | 3 +- server/core/runtime/runtime.go | 11 +- server/core/runtime/show_step_runner.go | 4 +- server/core/runtime/show_step_runner_test.go | 6 +- server/core/runtime/version_step_runner.go | 4 +- .../core/runtime/version_step_runner_test.go | 3 +- server/core/terraform/async_client.go | 6 +- server/core/terraform/async_client_test.go | 12 +- .../matchers/models_projectcommandcontext.go | 21 +- .../terraform/mocks/mock_terraform_client.go | 9 +- server/core/terraform/terraform_client.go | 6 +- .../terraform_client_internal_test.go | 5 +- .../core/terraform/terraform_client_test.go | 5 +- server/events/apply_command_runner.go | 5 +- server/events/apply_requirement_handler.go | 5 +- .../events/approve_policies_command_runner.go | 5 +- server/events/automerger.go | 5 +- server/events/command/project/context.go | 139 +++++++++++++ server/events/command/project/result.go | 61 ++++++ server/events/command/result.go | 4 +- server/events/command/result_test.go | 15 +- server/events/command_runner_internal_test.go | 3 +- server/events/command_runner_test.go | 21 +- server/events/commit_status_updater.go | 5 +- server/events/commit_status_updater_test.go | 7 +- server/events/db_updater.go | 5 +- .../instrumented_project_command_builder.go | 8 +- .../instrumented_project_command_runner.go | 10 +- server/events/markdown_renderer.go | 3 +- server/events/markdown_renderer_test.go | 119 +++++------ .../matchers/models_projectcommandcontext.go | 21 +- .../mocks/matchers/models_projectresult.go | 21 +- .../slice_of_models_projectcommandcontext.go | 21 +- server/events/mocks/mock_apply_handler.go | 14 +- .../mocks/mock_commit_status_updater.go | 13 +- .../events/mocks/mock_custom_step_runner.go | 14 +- server/events/mocks/mock_env_step_runner.go | 14 +- .../events/mocks/mock_job_message_sender.go | 14 +- server/events/mocks/mock_job_url_setter.go | 13 +- .../mocks/mock_log_stream_url_generator.go | 13 +- .../mocks/mock_project_command_builder.go | 42 ++-- .../mocks/mock_project_command_runner.go | 92 ++++----- server/events/mocks/mock_step_runner.go | 14 +- server/events/models/models.go | 193 +----------------- server/events/models/models_test.go | 47 ++--- server/events/plan_command_runner.go | 9 +- server/events/policy_check_command_runner.go | 5 +- server/events/project_command_builder.go | 54 ++--- .../project_command_builder_internal_test.go | 29 +-- server/events/project_command_builder_test.go | 7 +- .../events/project_command_context_builder.go | 15 +- .../events/project_command_pool_executor.go | 12 +- server/events/project_command_runner.go | 59 +++--- server/events/project_command_runner_test.go | 31 +-- server/events/pull_closed_executor_test.go | 5 +- server/events/pull_updater.go | 6 +- .../size_limited_project_command_builder.go | 10 +- ...ze_limited_project_command_builder_test.go | 18 +- server/events/version_command_runner.go | 6 +- server/jobs/job_url_setter.go | 7 +- .../matchers/models_projectcommandcontext.go | 21 +- .../mock_project_command_output_handler.go | 14 +- .../mocks/mock_project_job_url_generator.go | 14 +- .../jobs/mocks/mock_project_status_updater.go | 13 +- server/jobs/project_command_output_handler.go | 8 +- .../project_command_output_handler_test.go | 5 +- .../audit_project_commands_wrapper.go | 8 +- .../audit_project_commands_wrapper_test.go | 5 +- .../destroy_plan_step_runner_wrapper.go | 4 +- .../destroy_plan_step_runner_wrapper_test.go | 3 +- server/router.go | 4 +- server/router_test.go | 5 +- 97 files changed, 856 insertions(+), 807 deletions(-) create mode 100644 server/events/command/project/context.go create mode 100644 server/events/command/project/result.go diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e31457083..99ab6a993 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,7 +160,7 @@ Each interface that is mocked has a `go:generate` command above it, e.g. //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder type ProjectCommandBuilder interface { - BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) } ``` diff --git a/server/controllers/locks_controller_test.go b/server/controllers/locks_controller_test.go index 3a9f1b3f9..63a1099a5 100644 --- a/server/controllers/locks_controller_test.go +++ b/server/controllers/locks_controller_test.go @@ -23,6 +23,7 @@ import ( "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -303,7 +304,7 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) { db, err := db.New(tmp) Ok(t, err) // Seed the DB with a successful plan for that project (that is later discarded). - _, err = db.UpdatePullWithResults(pull, []models.ProjectResult{ + _, err = db.UpdatePullWithResults(pull, []project.Result{ { Command: command.Plan, RepoRelDir: projectPath, diff --git a/server/core/db/boltdb.go b/server/core/db/boltdb.go index 06d264719..5abff70ae 100644 --- a/server/core/db/boltdb.go +++ b/server/core/db/boltdb.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" bolt "go.etcd.io/bbolt" ) @@ -313,7 +314,7 @@ func (b *BoltDB) GetLock(p models.Project, workspace string) (*models.ProjectLoc // UpdatePullWithResults updates pull's status with the latest project results. // It returns the new PullStatus object. -func (b *BoltDB) UpdatePullWithResults(pull models.PullRequest, newResults []models.ProjectResult) (models.PullStatus, error) { +func (b *BoltDB) UpdatePullWithResults(pull models.PullRequest, newResults []project.Result) (models.PullStatus, error) { key, err := b.pullKey(pull) if err != nil { return models.PullStatus{}, err @@ -483,7 +484,7 @@ func (b *BoltDB) writePullToBucket(bucket *bolt.Bucket, key []byte, pull models. return bucket.Put(key, serialized) } -func (b *BoltDB) projectResultToProject(p models.ProjectResult) models.ProjectStatus { +func (b *BoltDB) projectResultToProject(p project.Result) models.ProjectStatus { return models.ProjectStatus{ Workspace: p.Workspace, RepoRelDir: p.RepoRelDir, diff --git a/server/core/db/boltdb_test.go b/server/core/db/boltdb_test.go index 1038f72ed..c3c98255d 100644 --- a/server/core/db/boltdb_test.go +++ b/server/core/db/boltdb_test.go @@ -458,7 +458,7 @@ func TestPullStatus_UpdateGet(t *testing.T) { } status, err := b.UpdatePullWithResults( pull, - []models.ProjectResult{ + []project.Result{ { Command: command.Plan, RepoRelDir: ".", @@ -510,7 +510,7 @@ func TestPullStatus_UpdateDeleteGet(t *testing.T) { } _, err := b.UpdatePullWithResults( pull, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: ".", Workspace: "default", @@ -556,7 +556,7 @@ func TestPullStatus_UpdateProject(t *testing.T) { } _, err := b.UpdatePullWithResults( pull, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: ".", Workspace: "default", @@ -621,7 +621,7 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { } initialStatus, err := b.UpdatePullWithResults( pull, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: ".", Workspace: "default", @@ -635,7 +635,7 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { pull.HeadCommit = "newsha" status, err := b.UpdatePullWithResults(pull, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -688,7 +688,7 @@ func TestPullStatus_UpdateMerge(t *testing.T) { } initialStatus, err := b.UpdatePullWithResults( pull, - []models.ProjectResult{ + []project.Result{ { Command: command.Plan, RepoRelDir: "mergeme", @@ -720,7 +720,7 @@ func TestPullStatus_UpdateMerge(t *testing.T) { time.Sleep(1 * time.Second) updateStatus, err := b.UpdatePullWithResults(pull, - []models.ProjectResult{ + []project.Result{ { Command: command.Apply, RepoRelDir: "mergeme", diff --git a/server/core/runtime/apply_step_runner.go b/server/core/runtime/apply_step_runner.go index e226632ca..0c0270e6b 100644 --- a/server/core/runtime/apply_step_runner.go +++ b/server/core/runtime/apply_step_runner.go @@ -12,6 +12,7 @@ import ( version "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -22,7 +23,7 @@ type ApplyStepRunner struct { AsyncTFExec AsyncTFExec } -func (a *ApplyStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (a *ApplyStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { if a.hasTargetFlag(ctx, extraArgs) { return "", errors.New("cannot run apply with -target because we are applying an already generated plan. Instead, run -target with atlantis plan") } @@ -63,7 +64,7 @@ func (a *ApplyStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []stri return out, err } -func (a *ApplyStepRunner) hasTargetFlag(ctx models.ProjectCommandContext, extraArgs []string) bool { +func (a *ApplyStepRunner) hasTargetFlag(ctx project.Context, extraArgs []string) bool { isTargetFlag := func(s string) bool { if s == "-target" { return true @@ -110,7 +111,7 @@ func (a *ApplyStepRunner) cleanRemoteApplyOutput(out string) string { // manual diff. // It also writes "yes" or "no" to the process to confirm the apply. func (a *ApplyStepRunner) runRemoteApply( - ctx models.ProjectCommandContext, + ctx project.Context, applyArgs []string, path string, absPlanPath string, diff --git a/server/core/runtime/apply_step_runner_test.go b/server/core/runtime/apply_step_runner_test.go index e757e42e5..c7b1c9a0c 100644 --- a/server/core/runtime/apply_step_runner_test.go +++ b/server/core/runtime/apply_step_runner_test.go @@ -17,6 +17,7 @@ import ( "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -29,7 +30,7 @@ func TestRun_NoDir(t *testing.T) { o := runtime.ApplyStepRunner{ TerraformExecutor: nil, } - _, err := o.Run(models.ProjectCommandContext{ + _, err := o.Run(project.Context{ RepoRelDir: ".", Workspace: "workspace", }, nil, "/nonexistent/path", map[string]string(nil)) @@ -42,7 +43,7 @@ func TestRun_NoPlanFile(t *testing.T) { o := runtime.ApplyStepRunner{ TerraformExecutor: nil, } - _, err := o.Run(models.ProjectCommandContext{ + _, err := o.Run(project.Context{ RepoRelDir: ".", Workspace: "workspace", }, nil, tmpDir, map[string]string(nil)) @@ -55,7 +56,7 @@ func TestRun_Success(t *testing.T) { planPath := filepath.Join(tmpDir, "workspace.tfplan") err := ioutil.WriteFile(planPath, nil, 0600) logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -87,7 +88,7 @@ func TestRun_AppliesCorrectProjectPlan(t *testing.T) { err := ioutil.WriteFile(planPath, nil, 0600) logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -121,7 +122,7 @@ func TestRun_UsesConfiguredTFVersion(t *testing.T) { logger := logging.NewNoopLogger(t) tfVersion, _ := version.NewVersion("0.11.0") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -210,7 +211,7 @@ func TestRun_UsingTarget(t *testing.T) { TerraformExecutor: terraform, } - output, err := step.Run(models.ProjectCommandContext{ + output, err := step.Run(project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -254,7 +255,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.` CommitStatusUpdater: updater, } tfVersion, _ := version.NewVersion("0.11.0") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Workspace: "workspace", RepoRelDir: ".", @@ -316,7 +317,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.` } tfVersion, _ := version.NewVersion("0.11.0") - output, err := o.Run(models.ProjectCommandContext{ + output, err := o.Run(project.Context{ Log: logging.NewNoopLogger(t), Workspace: "workspace", RepoRelDir: ".", @@ -370,7 +371,7 @@ type remoteApplyMock struct { DoneCh chan bool } -func (r *remoteApplyMock) RunCommandAsync(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { +func (r *remoteApplyMock) RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { in := make(chan string) defer close(in) @@ -379,7 +380,7 @@ func (r *remoteApplyMock) RunCommandAsync(ctx models.ProjectCommandContext, path } // RunCommandAsync fakes out running terraform async. -func (r *remoteApplyMock) RunCommandAsyncWithInput(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { +func (r *remoteApplyMock) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { r.CalledArgs = args out := make(chan terraform.Line) diff --git a/server/core/runtime/env_step_runner.go b/server/core/runtime/env_step_runner.go index e8ba3246c..f20c5fe52 100644 --- a/server/core/runtime/env_step_runner.go +++ b/server/core/runtime/env_step_runner.go @@ -3,7 +3,7 @@ package runtime import ( "strings" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // EnvStepRunner set environment variables. @@ -14,7 +14,7 @@ type EnvStepRunner struct { // Run runs the env step command. // value is the value for the environment variable. If set this is returned as // the value. Otherwise command is run and its output is the value returned. -func (r *EnvStepRunner) Run(ctx models.ProjectCommandContext, command string, value string, path string, envs map[string]string) (string, error) { +func (r *EnvStepRunner) Run(ctx project.Context, command string, value string, path string, envs map[string]string) (string, error) { if value != "" { return value, nil } diff --git a/server/core/runtime/env_step_runner_test.go b/server/core/runtime/env_step_runner_test.go index 746840c4c..cb1ebad2d 100644 --- a/server/core/runtime/env_step_runner_test.go +++ b/server/core/runtime/env_step_runner_test.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -50,7 +51,7 @@ func TestEnvStepRunner_Run(t *testing.T) { t.Run(c.Command, func(t *testing.T) { tmpDir, cleanup := TempDir(t) defer cleanup() - ctx := models.ProjectCommandContext{ + ctx := project.Context{ BaseRepo: models.Repo{ Name: "basename", Owner: "baseowner", diff --git a/server/core/runtime/executor.go b/server/core/runtime/executor.go index 1d73112eb..f7c4c9db2 100644 --- a/server/core/runtime/executor.go +++ b/server/core/runtime/executor.go @@ -2,7 +2,7 @@ package runtime import ( version "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/logging" ) @@ -16,7 +16,7 @@ type VersionedExecutorWorkflow interface { // Executor runs an executable with provided environment variables and arguments and returns stdout type Executor interface { - Run(ctx models.ProjectCommandContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) + Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) } // ExecutorVersionEnsurer ensures a given version exists and outputs a path to the executable diff --git a/server/core/runtime/init_step_runner.go b/server/core/runtime/init_step_runner.go index 30264f300..5b088eff7 100644 --- a/server/core/runtime/init_step_runner.go +++ b/server/core/runtime/init_step_runner.go @@ -5,7 +5,7 @@ import ( "path/filepath" version "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/runtime/common" ) @@ -15,7 +15,7 @@ type InitStepRunner struct { DefaultTFVersion *version.Version } -func (i *InitStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (i *InitStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { lockFileName := ".terraform.lock.hcl" terraformLockfilePath := filepath.Join(path, lockFileName) terraformLockFileTracked, err := common.IsFileTracked(path, lockFileName) diff --git a/server/core/runtime/init_step_runner_test.go b/server/core/runtime/init_step_runner_test.go index da1c6a062..d337d30f5 100644 --- a/server/core/runtime/init_step_runner_test.go +++ b/server/core/runtime/init_step_runner_test.go @@ -14,8 +14,8 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks/matchers" - "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) @@ -49,7 +49,7 @@ func TestRun_UsesGetOrInitForRightVersion(t *testing.T) { terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -92,7 +92,7 @@ func TestRun_ShowInitOutputOnError(t *testing.T) { DefaultTFVersion: tfVersion, } - output, err := iso.Run(models.ProjectCommandContext{ + output, err := iso.Run(project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -114,7 +114,7 @@ func TestRun_InitOmitsUpgradeFlagIfLockFileTracked(t *testing.T) { runCmd(t, repoDir, "git", "commit", "-m", "add .terraform.lock.hcl") logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -131,7 +131,7 @@ func TestRun_InitOmitsUpgradeFlagIfLockFileTracked(t *testing.T) { When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())). ThenReturn("output", nil) - output, err := iso.Run(models.ProjectCommandContext{ + output, err := iso.Run(project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -151,7 +151,7 @@ func TestRun_InitKeepsUpgradeFlagIfLockFileNotPresent(t *testing.T) { RegisterMockTestingT(t) terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -185,7 +185,7 @@ func TestRun_InitKeepUpgradeFlagIfLockFilePresentAndTFLessThanPoint14(t *testing terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -252,7 +252,7 @@ func TestRun_InitExtraArgsDeDupe(t *testing.T) { terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -291,7 +291,7 @@ func TestRun_InitDeletesLockFileIfPresentAndNotTracked(t *testing.T) { logger := logging.NewNoopLogger(t) tfVersion, _ := version.NewVersion("0.14.0") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", Log: logger, diff --git a/server/core/runtime/minimum_version_step_runner_delegate.go b/server/core/runtime/minimum_version_step_runner_delegate.go index 0ec8acf15..742c2a958 100644 --- a/server/core/runtime/minimum_version_step_runner_delegate.go +++ b/server/core/runtime/minimum_version_step_runner_delegate.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // MinimumVersionStepRunnerDelegate ensures that a given step runner can't run unless the command version being used @@ -30,7 +30,7 @@ func NewMinimumVersionStepRunnerDelegate(minimumVersionStr string, defaultVersio }, nil } -func (r *MinimumVersionStepRunnerDelegate) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (r *MinimumVersionStepRunnerDelegate) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := r.defaultTfVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/minimum_version_step_runner_delegate_test.go b/server/core/runtime/minimum_version_step_runner_delegate_test.go index 5bcf7cedf..a4ead89ff 100644 --- a/server/core/runtime/minimum_version_step_runner_delegate_test.go +++ b/server/core/runtime/minimum_version_step_runner_delegate_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/runtime/mocks" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" . "github.com/runatlantis/atlantis/testing" ) @@ -32,7 +32,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := models.ProjectCommandContext{} + ctx := project.Context{} When(mockDelegate.Run(ctx, extraArgs, path, envs)).ThenReturn(expectedOut, nil) @@ -54,7 +54,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ TerraformVersion: tfVersion12, } @@ -78,7 +78,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := models.ProjectCommandContext{} + ctx := project.Context{} output, err := subject.Run( ctx, @@ -100,7 +100,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ TerraformVersion: tfVersion11, } diff --git a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go index 8972dd412..93d072cb5 100644 --- a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnyModelsProjectCommandContext() models.ProjectCommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ProjectCommandContext))(nil)).Elem())) - var nullValue models.ProjectCommandContext +func AnyModelsProjectCommandContext() project.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) + var nullValue project.Context return nullValue } -func EqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func EqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func NotEqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func NotEqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) models.ProjectCommandContext { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { pegomock.RegisterMatcher(matcher) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } diff --git a/server/core/runtime/mocks/mock_runner.go b/server/core/runtime/mocks/mock_runner.go index 373cfa7f3..d793103c2 100644 --- a/server/core/runtime/mocks/mock_runner.go +++ b/server/core/runtime/mocks/mock_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockRunner struct { @@ -26,7 +26,7 @@ func NewMockRunner(options ...pegomock.Option) *MockRunner { func (mock *MockRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (mock *MockRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockRunner().") } @@ -82,7 +82,7 @@ type VerifierMockRunner struct { timeout time.Duration } -func (verifier *VerifierMockRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) *MockRunner_Run_OngoingVerification { +func (verifier *VerifierMockRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) *MockRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, extraArgs, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockRunner_Run_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, []string, string, map[string]string) { +func (c *MockRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, []string, string, map[string]string) { ctx, extraArgs, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], extraArgs[len(extraArgs)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 [][]string, _param2 []string, _param3 []map[string]string) { +func (c *MockRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 [][]string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([][]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go index 37e8a7a77..4717c1371 100644 --- a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go +++ b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go @@ -9,7 +9,7 @@ import ( go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" logging "github.com/runatlantis/atlantis/server/logging" ) @@ -47,7 +47,7 @@ func (mock *MockVersionedExecutorWorkflow) EnsureExecutorVersion(log logging.Sim return ret0, ret1 } -func (mock *MockVersionedExecutorWorkflow) Run(ctx models.ProjectCommandContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { +func (mock *MockVersionedExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockVersionedExecutorWorkflow().") } @@ -134,7 +134,7 @@ func (c *MockVersionedExecutorWorkflow_EnsureExecutorVersion_OngoingVerification return } -func (verifier *VerifierMockVersionedExecutorWorkflow) Run(ctx models.ProjectCommandContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) *MockVersionedExecutorWorkflow_Run_OngoingVerification { +func (verifier *VerifierMockVersionedExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) *MockVersionedExecutorWorkflow_Run_OngoingVerification { params := []pegomock.Param{ctx, executablePath, envs, workdir, extraArgs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockVersionedExecutorWorkflow_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -145,17 +145,17 @@ type MockVersionedExecutorWorkflow_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string, map[string]string, string, []string) { +func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, map[string]string, string, []string) { ctx, executablePath, envs, workdir, extraArgs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], executablePath[len(executablePath)-1], envs[len(envs)-1], workdir[len(workdir)-1], extraArgs[len(extraArgs)-1] } -func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 []map[string]string, _param3 []string, _param4 [][]string) { +func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []map[string]string, _param3 []string, _param4 [][]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/runtime/plan_step_runner.go b/server/core/runtime/plan_step_runner.go index 755826136..6854aabae 100644 --- a/server/core/runtime/plan_step_runner.go +++ b/server/core/runtime/plan_step_runner.go @@ -11,6 +11,7 @@ import ( version "github.com/hashicorp/go-version" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -33,7 +34,7 @@ type PlanStepRunner struct { AsyncTFExec AsyncTFExec } -func (p *PlanStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PlanStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := p.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion @@ -69,7 +70,7 @@ func (p *PlanStepRunner) isRemoteOpsErr(output string, err error) bool { // remotePlan runs a terraform plan command compatible with TFE remote // operations. -func (p *PlanStepRunner) remotePlan(ctx models.ProjectCommandContext, extraArgs []string, path string, tfVersion *version.Version, planFile string, envs map[string]string) (string, error) { +func (p *PlanStepRunner) remotePlan(ctx project.Context, extraArgs []string, path string, tfVersion *version.Version, planFile string, envs map[string]string) (string, error) { argList := [][]string{ {"plan", "-input=false", "-refresh"}, extraArgs, @@ -103,7 +104,7 @@ func (p *PlanStepRunner) remotePlan(ctx models.ProjectCommandContext, extraArgs // switchWorkspace changes the terraform workspace if necessary and will create // it if it doesn't exist. It handles differences between versions. -func (p *PlanStepRunner) switchWorkspace(ctx models.ProjectCommandContext, path string, tfVersion *version.Version, envs map[string]string) error { +func (p *PlanStepRunner) switchWorkspace(ctx project.Context, path string, tfVersion *version.Version, envs map[string]string) error { // In versions less than 0.9 there is no support for workspaces. noWorkspaceSupport := MustConstraint("<0.9").Check(tfVersion) // If the user tried to set a specific workspace in the comment but their @@ -153,7 +154,7 @@ func (p *PlanStepRunner) switchWorkspace(ctx models.ProjectCommandContext, path return nil } -func (p *PlanStepRunner) buildPlanCmd(ctx models.ProjectCommandContext, extraArgs []string, path string, tfVersion *version.Version, planFile string) []string { +func (p *PlanStepRunner) buildPlanCmd(ctx project.Context, extraArgs []string, path string, tfVersion *version.Version, planFile string) []string { tfVars := p.tfVars(ctx, tfVersion) // Check if env/{workspace}.tfvars exist and include it. This is a use-case @@ -187,7 +188,7 @@ func (p *PlanStepRunner) buildPlanCmd(ctx models.ProjectCommandContext, extraArg // those versions don't allow setting -var flags for any variables that aren't // actually used in the configuration. Since there's no way for us to detect // if the configuration is using those variables, we don't set them. -func (p *PlanStepRunner) tfVars(ctx models.ProjectCommandContext, tfVersion *version.Version) []string { +func (p *PlanStepRunner) tfVars(ctx project.Context, tfVersion *version.Version) []string { if tfVersion.GreaterThanOrEqual(version.Must(version.NewVersion("0.12.0"))) { return nil } @@ -239,7 +240,7 @@ func (p *PlanStepRunner) fmtPlanOutput(output string, tfVersion *version.Version // cmdArgs is the args to terraform to execute. // path is the path to where we need to execute. func (p *PlanStepRunner) runRemotePlan( - ctx models.ProjectCommandContext, + ctx project.Context, cmdArgs []string, path string, tfVersion *version.Version, diff --git a/server/core/runtime/plan_step_runner_test.go b/server/core/runtime/plan_step_runner_test.go index 7a23d0a6c..826ef328b 100644 --- a/server/core/runtime/plan_step_runner_test.go +++ b/server/core/runtime/plan_step_runner_test.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" . "github.com/petergtz/pegomock" @@ -34,7 +35,7 @@ func TestRun_NoWorkspaceIn08(t *testing.T) { workspace := "default" logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, @@ -121,7 +122,7 @@ func TestRun_ErrWorkspaceIn08(t *testing.T) { When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())). ThenReturn("output", nil) - _, err := s.Run(models.ProjectCommandContext{ + _, err := s.Run(project.Context{ Log: logger, Workspace: workspace, RepoRelDir: ".", @@ -161,7 +162,7 @@ func TestRun_SwitchesWorkspace(t *testing.T) { tfVersion, _ := version.NewVersion(c.tfVersion) logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -255,7 +256,7 @@ func TestRun_CreatesWorkspace(t *testing.T) { terraform := mocks.NewMockClient() tfVersion, _ := version.NewVersion(c.tfVersion) logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -321,7 +322,7 @@ func TestRun_NoWorkspaceSwitchIfNotNecessary(t *testing.T) { terraform := mocks.NewMockClient() tfVersion, _ := version.NewVersion("0.10.0") logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -417,7 +418,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) { "-var-file", envVarsFile, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -454,7 +455,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) { TerraformExecutor: terraform, DefaultTFVersion: tfVersion, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -553,7 +554,7 @@ Terraform will perform the following actions: return []ReturnValue{"", errors.New("unexpected call to RunCommandWithVersion")} } }) - actOutput, err := s.Run(models.ProjectCommandContext{Workspace: "default"}, nil, "", map[string]string(nil)) + actOutput, err := s.Run(project.Context{Workspace: "default"}, nil, "", map[string]string(nil)) Ok(t, err) Equals(t, ` An execution plan has been generated and is shown below. @@ -607,7 +608,7 @@ func TestRun_OutputOnErr(t *testing.T) { return []ReturnValue{"", errors.New("unexpected call to RunCommandWithVersion")} } }) - actOutput, actErr := s.Run(models.ProjectCommandContext{Workspace: "default"}, nil, "", map[string]string(nil)) + actOutput, actErr := s.Run(project.Context{Workspace: "default"}, nil, "", map[string]string(nil)) ErrEquals(t, expErrMsg, actErr) Equals(t, expOutput, actOutput) } @@ -660,7 +661,7 @@ func TestRun_NoOptionalVarsIn012(t *testing.T) { TerraformExecutor: terraform, DefaultTFVersion: tfVersion, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "default", RepoRelDir: ".", User: models.User{Username: "username"}, @@ -706,7 +707,7 @@ locally at this time. logger := logging.NewNoopLogger(t) // Now that mocking is set up, we're ready to run the plan. - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -886,14 +887,14 @@ type remotePlanMock struct { CalledArgs []string } -func (r *remotePlanMock) RunCommandAsync(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { +func (r *remotePlanMock) RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { input := make(chan string) defer close(input) return r.RunCommandAsyncWithInput(ctx, path, args, envs, v, workspace, input) } -func (r *remotePlanMock) RunCommandAsyncWithInput(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { +func (r *remotePlanMock) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { r.CalledArgs = args out := make(chan terraform.Line) go func() { diff --git a/server/core/runtime/plan_type_step_runner_delegate.go b/server/core/runtime/plan_type_step_runner_delegate.go index a372cd2e0..026f20a6c 100644 --- a/server/core/runtime/plan_type_step_runner_delegate.go +++ b/server/core/runtime/plan_type_step_runner_delegate.go @@ -5,13 +5,13 @@ import ( "path/filepath" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // NullRunner is a runner that isn't configured for a given plan type but outputs nothing type NullRunner struct{} -func (p NullRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p NullRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { ctx.Log.Debug("runner not configured for plan type") return "", nil @@ -20,7 +20,7 @@ func (p NullRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, pa // RemoteBackendUnsupportedRunner is a runner that is responsible for outputting that the remote backend is unsupported type RemoteBackendUnsupportedRunner struct{} -func (p RemoteBackendUnsupportedRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p RemoteBackendUnsupportedRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { ctx.Log.Debug("runner not configured for remote backend") return "Remote backend is unsupported for this step.", nil @@ -49,7 +49,7 @@ func (p *PlanTypeStepRunnerDelegate) isRemotePlan(planFile string) (bool, error) return IsRemotePlan(data), nil } -func (p *PlanTypeStepRunnerDelegate) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PlanTypeStepRunnerDelegate) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { planFile := filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName)) remotePlan, err := p.isRemotePlan(planFile) diff --git a/server/core/runtime/plan_type_step_runner_delegate_test.go b/server/core/runtime/plan_type_step_runner_delegate_test.go index 060e163a6..e1b0cc233 100644 --- a/server/core/runtime/plan_type_step_runner_delegate_test.go +++ b/server/core/runtime/plan_type_step_runner_delegate_test.go @@ -11,7 +11,7 @@ import ( . "github.com/runatlantis/atlantis/testing" "github.com/runatlantis/atlantis/server/core/runtime/mocks" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) var planFileContents = ` @@ -47,7 +47,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte("Atlantis: this plan was created by remote ops\n"+planFileContents), 0600) Ok(t, err) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -76,7 +76,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte("Atlantis: this plan was created by remote ops\n"+planFileContents), 0600) Ok(t, err) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -105,7 +105,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte(planFileContents), 0600) Ok(t, err) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -134,7 +134,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte(planFileContents), 0600) Ok(t, err) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, diff --git a/server/core/runtime/policy/conftest_client.go b/server/core/runtime/policy/conftest_client.go index 1e6bcf092..b23cf6c7a 100644 --- a/server/core/runtime/policy/conftest_client.go +++ b/server/core/runtime/policy/conftest_client.go @@ -13,7 +13,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/cache" runtime_models "github.com/runatlantis/atlantis/server/core/runtime/models" "github.com/runatlantis/atlantis/server/core/terraform" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/logging" ) @@ -159,7 +159,7 @@ func NewConfTestExecutorWorkflow(log logging.SimpleLogging, versionRootDir strin } } -func (c *ConfTestExecutorWorkflow) Run(ctx models.ProjectCommandContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { +func (c *ConfTestExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { policyArgs := []Arg{} policySetNames := []string{} ctx.Log.Debug("policy sets, %s ", ctx.PolicySets) diff --git a/server/core/runtime/policy/conftest_client_test.go b/server/core/runtime/policy/conftest_client_test.go index c08a7360f..ec012c8a9 100644 --- a/server/core/runtime/policy/conftest_client_test.go +++ b/server/core/runtime/policy/conftest_client_test.go @@ -15,7 +15,7 @@ import ( models_mocks "github.com/runatlantis/atlantis/server/core/runtime/models/mocks" conftest_mocks "github.com/runatlantis/atlantis/server/core/runtime/policy/mocks" terraform_mocks "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) @@ -159,7 +159,7 @@ func TestRun(t *testing.T) { Name: policySetName2, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ PolicySets: valid.PolicySets{ PolicySets: []valid.PolicySet{ policySet1, diff --git a/server/core/runtime/policy_check_step_runner.go b/server/core/runtime/policy_check_step_runner.go index 09321dd23..978c0cdfb 100644 --- a/server/core/runtime/policy_check_step_runner.go +++ b/server/core/runtime/policy_check_step_runner.go @@ -3,7 +3,7 @@ package runtime import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // PolicyCheckStepRunner runs a policy check command given a ctx @@ -27,7 +27,7 @@ func NewPolicyCheckStepRunner(defaultTfVersion *version.Version, executorWorkflo } // Run ensures a given version for the executable, builds the args from the project context and then runs executable returning the result -func (p *PolicyCheckStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PolicyCheckStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { executable, err := p.versionEnsurer.EnsureExecutorVersion(ctx.Log, ctx.PolicySets.Version) if err != nil { diff --git a/server/core/runtime/policy_check_step_runner_test.go b/server/core/runtime/policy_check_step_runner_test.go index daea0bcc0..94c28e98f 100644 --- a/server/core/runtime/policy_check_step_runner_test.go +++ b/server/core/runtime/policy_check_step_runner_test.go @@ -8,6 +8,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime/mocks" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" @@ -21,7 +22,7 @@ func TestRun(t *testing.T) { workdir := "/path" executablePath := "some/path/conftest" - context := models.ProjectCommandContext{ + context := project.Context{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, diff --git a/server/core/runtime/run_step_runner.go b/server/core/runtime/run_step_runner.go index 485b71cf7..0bd9fcda5 100644 --- a/server/core/runtime/run_step_runner.go +++ b/server/core/runtime/run_step_runner.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // RunStepRunner runs custom commands. @@ -19,7 +19,7 @@ type RunStepRunner struct { TerraformBinDir string } -func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, path string, envs map[string]string) (string, error) { +func (r *RunStepRunner) Run(ctx project.Context, command string, path string, envs map[string]string) (string, error) { tfVersion := r.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/run_step_runner_test.go b/server/core/runtime/run_step_runner_test.go index be6d4642a..2e5070a2e 100644 --- a/server/core/runtime/run_step_runner_test.go +++ b/server/core/runtime/run_step_runner_test.go @@ -11,6 +11,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -112,7 +113,7 @@ func TestRunStepRunner_Run(t *testing.T) { t.Run(c.Command, func(t *testing.T) { tmpDir, cleanup := TempDir(t) defer cleanup() - ctx := models.ProjectCommandContext{ + ctx := project.Context{ BaseRepo: models.Repo{ Name: "basename", Owner: "baseowner", diff --git a/server/core/runtime/runtime.go b/server/core/runtime/runtime.go index b4ec991fe..fc3cfe4f3 100644 --- a/server/core/runtime/runtime.go +++ b/server/core/runtime/runtime.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" ) @@ -26,7 +27,7 @@ const ( // TerraformExec brings the interface from TerraformClient into this package // without causing circular imports. type TerraformExec interface { - RunCommandWithVersion(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) + RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) EnsureVersion(log logging.SimpleLogging, v *version.Version) error } @@ -41,20 +42,20 @@ type AsyncTFExec interface { // Callers can use the input channel to pass stdin input to the command. // If any error is passed on the out channel, there will be no // further output (so callers are free to exit). - RunCommandAsync(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line - RunCommandAsyncWithInput(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line + RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line + RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line } // StatusUpdater brings the interface from CommitStatusUpdater into this package // without causing circular imports. type StatusUpdater interface { - UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_runner.go Runner // Runner mirrors events.StepRunner as a way to bring it into this package type Runner interface { - Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) + Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) } // MustConstraint returns a constraint. It panics on error. diff --git a/server/core/runtime/show_step_runner.go b/server/core/runtime/show_step_runner.go index e4da61620..ffbdf015e 100644 --- a/server/core/runtime/show_step_runner.go +++ b/server/core/runtime/show_step_runner.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) const minimumShowTfVersion string = "0.12.0" @@ -30,7 +30,7 @@ type ShowStepRunner struct { DefaultTFVersion *version.Version } -func (p *ShowStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *ShowStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := p.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/show_step_runner_test.go b/server/core/runtime/show_step_runner_test.go index de689000e..2a59f04da 100644 --- a/server/core/runtime/show_step_runner_test.go +++ b/server/core/runtime/show_step_runner_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) @@ -21,7 +21,7 @@ func TestShowStepRunnner(t *testing.T) { resultPath := filepath.Join(path, "test-default.json") envs := map[string]string{"key": "val"} tfVersion, _ := version.NewVersion("0.12") - context := models.ProjectCommandContext{ + context := project.Context{ Workspace: "default", ProjectName: "test", Log: logger, @@ -58,7 +58,7 @@ func TestShowStepRunnner(t *testing.T) { v, _ := version.NewVersion("0.13.0") - contextWithVersionOverride := models.ProjectCommandContext{ + contextWithVersionOverride := project.Context{ Workspace: "default", ProjectName: "test", Log: logger, diff --git a/server/core/runtime/version_step_runner.go b/server/core/runtime/version_step_runner.go index a7369af7c..2f17792f2 100644 --- a/server/core/runtime/version_step_runner.go +++ b/server/core/runtime/version_step_runner.go @@ -4,7 +4,7 @@ import ( "path/filepath" "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // VersionStepRunner runs a version command given a ctx @@ -14,7 +14,7 @@ type VersionStepRunner struct { } // Run ensures a given version for the executable, builds the args from the project context and then runs executable returning the result -func (v *VersionStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (v *VersionStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := v.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/version_step_runner_test.go b/server/core/runtime/version_step_runner_test.go index 797e4ba6c..e7597e4f9 100644 --- a/server/core/runtime/version_step_runner_test.go +++ b/server/core/runtime/version_step_runner_test.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" @@ -16,7 +17,7 @@ func TestRunVersionStep(t *testing.T) { logger := logging.NewNoopLogger(t) workspace := "default" - context := models.ProjectCommandContext{ + context := project.Context{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, diff --git a/server/core/terraform/async_client.go b/server/core/terraform/async_client.go index 76bb50ee2..027cbe6c4 100644 --- a/server/core/terraform/async_client.go +++ b/server/core/terraform/async_client.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/jobs" ) @@ -26,14 +26,14 @@ type AsyncClient struct { // Callers can use the input channel to pass stdin input to the command. // If any error is passed on the out channel, there will be no // further output (so callers are free to exit). -func (c *AsyncClient) RunCommandAsync(ctx models.ProjectCommandContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) <-chan Line { +func (c *AsyncClient) RunCommandAsync(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) <-chan Line { input := make(chan string) defer close(input) return c.RunCommandAsyncWithInput(ctx, path, args, customEnvVars, v, workspace, input) } -func (c *AsyncClient) RunCommandAsyncWithInput(ctx models.ProjectCommandContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string, input <-chan string) <-chan Line { +func (c *AsyncClient) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string, input <-chan string) <-chan Line { outCh := make(chan Line) // We start a goroutine to do our work asynchronously and then immediately diff --git a/server/core/terraform/async_client_test.go b/server/core/terraform/async_client_test.go index 79ee0049e..94e9852c7 100644 --- a/server/core/terraform/async_client_test.go +++ b/server/core/terraform/async_client_test.go @@ -10,7 +10,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -26,7 +26,7 @@ func TestDefaultClient_RunCommandAsync_Success(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo hello") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, } @@ -54,7 +54,7 @@ func TestDefaultClient_RunCommandAsync_BigOutput(t *testing.T) { workspace := "workspace" logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -101,7 +101,7 @@ func TestDefaultClient_RunCommandAsync_StderrOutput(t *testing.T) { logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -127,7 +127,7 @@ func TestDefaultClient_RunCommandAsync_ExitOne(t *testing.T) { echoCommand := exec.Command("sh", "-c", "echo dying && exit 1") logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -154,7 +154,7 @@ func TestDefaultClient_RunCommandAsync_Input(t *testing.T) { echoCommand := exec.Command("sh", "-c", "read a && echo $a") logger := logging.NewNoopLogger(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() diff --git a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go index 8972dd412..93d072cb5 100644 --- a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnyModelsProjectCommandContext() models.ProjectCommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ProjectCommandContext))(nil)).Elem())) - var nullValue models.ProjectCommandContext +func AnyModelsProjectCommandContext() project.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) + var nullValue project.Context return nullValue } -func EqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func EqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func NotEqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func NotEqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) models.ProjectCommandContext { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { pegomock.RegisterMatcher(matcher) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } diff --git a/server/core/terraform/mocks/mock_terraform_client.go b/server/core/terraform/mocks/mock_terraform_client.go index 99109b89b..6732ddb2b 100644 --- a/server/core/terraform/mocks/mock_terraform_client.go +++ b/server/core/terraform/mocks/mock_terraform_client.go @@ -9,6 +9,7 @@ import ( go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" logging "github.com/runatlantis/atlantis/server/logging" ) @@ -28,7 +29,7 @@ func NewMockClient(options ...pegomock.Option) *MockClient { func (mock *MockClient) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockClient) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockClient) RunCommandWithVersion(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) (string, error) { +func (mock *MockClient) RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } @@ -110,7 +111,7 @@ type MockClient_RunCommandWithVersion_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string, []string, map[string]string, *go_version.Version, string) { +func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetCapturedArguments() (project.Context, string, []string, map[string]string, *go_version.Version, string) { ctx, path, args, envs, v, workspace := c.GetAllCapturedArguments() return ctx[len(ctx)-1], path[len(path)-1], args[len(args)-1], envs[len(envs)-1], v[len(v)-1], workspace[len(workspace)-1] } @@ -118,9 +119,9 @@ func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetCapturedArgume func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 [][]string, _param3 []map[string]string, _param4 []*go_version.Version, _param5 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/terraform/terraform_client.go b/server/core/terraform/terraform_client.go index 48a3f832a..aab86c70f 100644 --- a/server/core/terraform/terraform_client.go +++ b/server/core/terraform/terraform_client.go @@ -30,7 +30,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/cache" runtime_models "github.com/runatlantis/atlantis/server/core/runtime/models" "github.com/runatlantis/atlantis/server/core/terraform/cloud" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/terraform/ansi" "github.com/runatlantis/atlantis/server/jobs" "github.com/runatlantis/atlantis/server/logging" @@ -45,7 +45,7 @@ type Client interface { // RunCommandWithVersion executes terraform with args in path. If v is nil, // it will use the default Terraform version. workspace is the Terraform // workspace which should be set as an environment variable. - RunCommandWithVersion(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) + RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) // EnsureVersion makes sure that terraform version `v` is available to use EnsureVersion(log logging.SimpleLogging, v *version.Version) error @@ -248,7 +248,7 @@ func (c *DefaultClient) EnsureVersion(log logging.SimpleLogging, v *version.Vers } // See Client.RunCommandWithVersion. -func (c *DefaultClient) RunCommandWithVersion(ctx models.ProjectCommandContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) (string, error) { +func (c *DefaultClient) RunCommandWithVersion(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) (string, error) { shouldAllocate, err := c.featureAllocator.ShouldAllocate(feature.LogStreaming, ctx.BaseRepo.FullName) if err != nil { diff --git a/server/core/terraform/terraform_client_internal_test.go b/server/core/terraform/terraform_client_internal_test.go index ad872528c..4d3d682ac 100644 --- a/server/core/terraform/terraform_client_internal_test.go +++ b/server/core/terraform/terraform_client_internal_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -28,7 +29,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo hello") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, BaseRepo: models.Repo{ FullName: "owner/repo", @@ -103,7 +104,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion_Error(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo dying && exit 1") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, BaseRepo: models.Repo{ FullName: "owner/repo", diff --git a/server/core/terraform/terraform_client_test.go b/server/core/terraform/terraform_client_test.go index c78833184..ba27c64f5 100644 --- a/server/core/terraform/terraform_client_test.go +++ b/server/core/terraform/terraform_client_test.go @@ -23,6 +23,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/cmd" "github.com/runatlantis/atlantis/server/core/terraform" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -56,7 +57,7 @@ func TestNewClient_DefaultTFFlagInPath(t *testing.T) { logger := logging.NewNoopLogger(t) tmp, binDir, cacheDir, cleanup := mkSubDirs(t) projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler() - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Workspace: "default", RepoRelDir: ".", @@ -90,7 +91,7 @@ func TestNewClient_DefaultTFFlagInBinDir(t *testing.T) { fakeBinOut := "Terraform v0.11.10\n" tmp, binDir, cacheDir, cleanup := mkSubDirs(t) projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler() - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Workspace: "default", RepoRelDir: ".", diff --git a/server/events/apply_command_runner.go b/server/events/apply_command_runner.go index d616b4cec..05b560e46 100644 --- a/server/events/apply_command_runner.go +++ b/server/events/apply_command_runner.go @@ -4,6 +4,7 @@ import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -112,7 +113,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { ctx.Log.Warn("unable to get pull request status: %s. Continuing with mergeable and approved assumed false", err) } - var projectCmds []models.ProjectCommandContext + var projectCmds []project.Context projectCmds, err = a.prjCmdBuilder.BuildApplyCommands(ctx, cmd) if err != nil { @@ -171,7 +172,7 @@ func (a *ApplyCommandRunner) IsLocked() (bool, error) { return lock.Locked, err } -func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []models.ProjectCommandContext) bool { +func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []project.Context) bool { return len(projectCmds) > 0 && projectCmds[0].ParallelApplyEnabled } diff --git a/server/events/apply_requirement_handler.go b/server/events/apply_requirement_handler.go index faaa44b54..6c51e53ca 100644 --- a/server/events/apply_requirement_handler.go +++ b/server/events/apply_requirement_handler.go @@ -3,19 +3,20 @@ package events import ( "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) //go:generate pegomock generate -m --package mocks -o mocks/mock_apply_handler.go ApplyRequirement type ApplyRequirement interface { - ValidateProject(repoDir string, ctx models.ProjectCommandContext) (string, error) + ValidateProject(repoDir string, ctx project.Context) (string, error) } type AggregateApplyRequirements struct { WorkingDir WorkingDir } -func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx models.ProjectCommandContext) (failure string, err error) { +func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx project.Context) (failure string, err error) { for _, req := range ctx.ApplyRequirements { switch req { case raw.ApprovedApplyRequirement: diff --git a/server/events/approve_policies_command_runner.go b/server/events/approve_policies_command_runner.go index 4f52905bd..1b64ed50a 100644 --- a/server/events/approve_policies_command_runner.go +++ b/server/events/approve_policies_command_runner.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -87,7 +88,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *command.Context, cmd *CommentCom a.updateCommitStatus(ctx, pullStatus) } -func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *command.Context, prjCmds []models.ProjectCommandContext) (result command.Result) { +func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *command.Context, prjCmds []project.Context) (result command.Result) { // Check if vcs user is in the owner list of the PolicySets. All projects // share the same Owners list at this time so no reason to iterate over each // project. @@ -96,7 +97,7 @@ func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *com return } - var prjResults []models.ProjectResult + var prjResults []project.Result for _, prjCmd := range prjCmds { prjResult := a.prjCmdRunner.ApprovePolicies(prjCmd) diff --git a/server/events/automerger.go b/server/events/automerger.go index fb052d3e5..ae462a572 100644 --- a/server/events/automerger.go +++ b/server/events/automerger.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -45,7 +46,7 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu } // automergeEnabled returns true if automerging is enabled in this context. -func (c *AutoMerger) automergeEnabled(projectCmds []models.ProjectCommandContext) bool { +func (c *AutoMerger) automergeEnabled(projectCmds []project.Context) bool { // If the global automerge is set, we always automerge. return c.GlobalAutomerge || // Otherwise we check if this repo is configured for automerging. @@ -53,7 +54,7 @@ func (c *AutoMerger) automergeEnabled(projectCmds []models.ProjectCommandContext } // deleteSourceBranchOnMergeEnabled returns true if we should delete the source branch on merge in this context. -func (c *AutoMerger) deleteSourceBranchOnMergeEnabled(projectCmds []models.ProjectCommandContext) bool { +func (c *AutoMerger) deleteSourceBranchOnMergeEnabled(projectCmds []project.Context) bool { //check if this repo is configured for automerging. return (len(projectCmds) > 0 && projectCmds[0].DeleteSourceBranchOnMerge) } diff --git a/server/events/command/project/context.go b/server/events/command/project/context.go new file mode 100644 index 000000000..073849c67 --- /dev/null +++ b/server/events/command/project/context.go @@ -0,0 +1,139 @@ +package project + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/hashicorp/go-version" + "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/logging" + "github.com/uber-go/tally" +) + +const ( + planfileSlashReplace = "::" +) + +// Context defines the context for a plan or apply stage that will +// be executed for a project. +type Context struct { + CommandName command.Name + // ApplyCmd is the command that users should run to apply this plan. If + // this is an apply then this will be empty. + ApplyCmd string + // ApplyRequirements is the list of requirements that must be satisfied + // before we will run the apply stage. + ApplyRequirements []string + // AutomergeEnabled is true if automerge is enabled for the repo that this + // project is in. + AutomergeEnabled bool + // ParallelApplyEnabled is true if parallel apply is enabled for this project. + ParallelApplyEnabled bool + // ParallelPlanEnabled is true if parallel plan is enabled for this project. + ParallelPlanEnabled bool + // ParallelPolicyCheckEnabled is true if parallel policy_check is enabled for this project. + ParallelPolicyCheckEnabled bool + // AutoplanEnabled is true if autoplanning is enabled for this project. + AutoplanEnabled bool + // BaseRepo is the repository that the pull request will be merged into. + BaseRepo models.Repo + // EscapedCommentArgs are the extra arguments that were added to the atlantis + // command, ex. atlantis plan -- -target=resource. We then escape them + // by adding a \ before each character so that they can be used within + // sh -c safely, i.e. sh -c "terraform plan $(touch bad)". + EscapedCommentArgs []string + // HeadRepo is the repository that is getting merged into the BaseRepo. + // If the pull request branch is from the same repository then HeadRepo will + // be the same as BaseRepo. + HeadRepo models.Repo + // Log is a logger that's been set up for this context. + Log logging.SimpleLogging + // Scope is the scope for reporting stats setup for this context + Scope tally.Scope + // PullReqStatus holds state about the PR that requires additional computation outside models.PullRequest + PullReqStatus models.PullReqStatus + // CurrentProjectPlanStatus is the status of the current project prior to this command. + ProjectPlanStatus models.ProjectPlanStatus + // Pull is the pull request we're responding to. + Pull models.PullRequest + // ProjectName is the name of the project set in atlantis.yaml. If there was + // no name this will be an empty string. + ProjectName string + // RepoConfigVersion is the version of the repo's atlantis.yaml file. If + // there was no file, this will be 0. + RepoConfigVersion int + // RePlanCmd is the command that users should run to re-plan this project. + // If this is an apply then this will be empty. + RePlanCmd string + // RepoRelDir is the directory of this project relative to the repo root. + RepoRelDir string + // Steps are the sequence of commands we need to run for this project and this + // stage. + Steps []valid.Step + // TerraformVersion is the version of terraform we should use when executing + // commands for this project. This can be set to nil in which case we will + // use the default Atlantis terraform version. + TerraformVersion *version.Version + // Configuration metadata for a given project. + Tags map[string]string + // User is the user that triggered this command. + User models.User + // Verbose is true when the user would like verbose output. + Verbose bool + // ForceApply is true when the apply should ignore apply_requirements. + ForceApply bool + // Workspace is the Terraform workspace this project is in. It will always + // be set. + Workspace string + // PolicySets represent the policies that are run on the plan as part of the + // policy check stage + PolicySets valid.PolicySets + // DeleteSourceBranchOnMerge will attempt to allow a branch to be deleted when merged (AzureDevOps & GitLab Support Only) + DeleteSourceBranchOnMerge bool + // UUID for atlantis logs + JobID string +} + +// ProjectCloneDir creates relative path to clone the repo to. If we are running +// plans and apply in parallel we want to have a directory per project. +func (p Context) ProjectCloneDir() string { + if p.ParallelPlanEnabled || p.ParallelApplyEnabled { + return filepath.Join(p.ProjectName, p.Workspace) + } + + return p.Workspace +} + +// SetScope sets the scope of the stats object field. Note: we deliberately set this on the value +// instead of a pointer since we want scopes to mirror our function stack +func (p Context) SetScope(scope string) { + p.Scope = p.Scope.SubScope(scope) //nolint +} + +// GetShowResultFileName returns the filename (not the path) to store the tf show result +func (p Context) GetShowResultFileName() string { + if p.ProjectName == "" { + return fmt.Sprintf("%s.json", p.Workspace) + } + projName := strings.Replace(p.ProjectName, "/", planfileSlashReplace, -1) + return fmt.Sprintf("%s-%s.json", projName, p.Workspace) +} + +// Gets a unique identifier for the current pull request as a single string +func (p Context) PullInfo() string { + return buildPullInfo(p.BaseRepo.FullName, p.Pull.Num, p.ProjectName, p.RepoRelDir, p.Workspace) +} +func buildPullInfo(repoName string, pullNum int, projectName string, relDir string, workspace string) string { + projectIdentifier := getProjectIdentifier(relDir, projectName) + return fmt.Sprintf("%s/%d/%s/%s", repoName, pullNum, projectIdentifier, workspace) +} + +func getProjectIdentifier(relRepoDir string, projectName string) string { + if projectName != "" { + return projectName + } + return strings.ReplaceAll(relRepoDir, "/", "-") +} diff --git a/server/events/command/project/result.go b/server/events/command/project/result.go new file mode 100644 index 000000000..f1f21c128 --- /dev/null +++ b/server/events/command/project/result.go @@ -0,0 +1,61 @@ +package project + +import ( + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" +) + +// Result is the result of executing a plan/policy_check/apply for a specific project. +type Result struct { + Command command.Name + RepoRelDir string + Workspace string + Error error + Failure string + PlanSuccess *PlanSuccess + PolicyCheckSuccess *PolicyCheckSuccess + ApplySuccess string + VersionSuccess string + ProjectName string +} + +// CommitStatus returns the vcs commit status of this project result. +func (p Result) CommitStatus() models.CommitStatus { + if p.Error != nil { + return models.FailedCommitStatus + } + if p.Failure != "" { + return models.FailedCommitStatus + } + return models.SuccessCommitStatus +} + +// PlanStatus returns the plan status. +func (p Result) PlanStatus() models.ProjectPlanStatus { + switch p.Command { + + case command.Plan: + if p.Error != nil { + return models.ErroredPlanStatus + } else if p.Failure != "" { + return models.ErroredPlanStatus + } + return models.PlannedPlanStatus + case command.PolicyCheck, command.ApprovePolicies: + if p.Error != nil { + return models.ErroredPolicyCheckStatus + } else if p.Failure != "" { + return models.ErroredPolicyCheckStatus + } + return models.PassedPolicyCheckStatus + case command.Apply: + if p.Error != nil { + return models.ErroredApplyStatus + } else if p.Failure != "" { + return models.ErroredApplyStatus + } + return models.AppliedPlanStatus + } + + panic("PlanStatus() missing a combination") +} diff --git a/server/events/command/result.go b/server/events/command/result.go index 49ba4db1c..1a533bc65 100644 --- a/server/events/command/result.go +++ b/server/events/command/result.go @@ -1,12 +1,12 @@ package command -import "github.com/runatlantis/atlantis/server/events/models" +import "github.com/runatlantis/atlantis/server/events/command/project" // Result is the result of running a Command. type Result struct { Error error Failure string - ProjectResults []models.ProjectResult + ProjectResults []project.Result // PlansDeleted is true if all plans created during this command were // deleted. This happens if automerging is enabled and one project has an // error since automerging requires all plans to succeed. diff --git a/server/events/command/result_test.go b/server/events/command/result_test.go index 4bdd41e88..a220051c9 100644 --- a/server/events/command/result_test.go +++ b/server/events/command/result_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -28,13 +29,13 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "empty results list": { cr: command.Result{ - ProjectResults: []models.ProjectResult{}, + ProjectResults: []project.Result{}, }, exp: false, }, "successful plan": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { PlanSuccess: &models.PlanSuccess{}, }, @@ -44,7 +45,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "successful apply": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { ApplySuccess: "success", }, @@ -54,7 +55,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "single errored project": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { Error: errors.New("err"), }, @@ -64,7 +65,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "single failed project": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { Failure: "failure", }, @@ -74,7 +75,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "two successful projects": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { PlanSuccess: &models.PlanSuccess{}, }, @@ -87,7 +88,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "one successful, one failed project": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { PlanSuccess: &models.PlanSuccess{}, }, diff --git a/server/events/command_runner_internal_test.go b/server/events/command_runner_internal_test.go index 03e367022..2005a34ad 100644 --- a/server/events/command_runner_internal_test.go +++ b/server/events/command_runner_internal_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -169,6 +170,6 @@ func (m *MockCSU) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, func (m *MockCSU) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name) error { return nil } -func (m *MockCSU) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { +func (m *MockCSU) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { return nil } diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index de6e802b1..f7df9efb5 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -24,6 +24,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/vcs" lyft_vcs "github.com/runatlantis/atlantis/server/events/vcs/lyft" "github.com/runatlantis/atlantis/server/logging" @@ -421,7 +422,7 @@ func TestRunCommentCommand_DisableDisableAutoplan(t *testing.T) { defer func() { ch.DisableAutoplan = false }() When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). - ThenReturn([]models.ProjectCommandContext{ + ThenReturn([]project.Context{ { CommandName: command.Plan, }, @@ -537,7 +538,7 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). - ThenReturn([]models.ProjectCommandContext{ + ThenReturn([]project.Context{ { CommandName: command.Plan, }, @@ -551,14 +552,14 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { // The first call, we return a successful result. callCount++ return ReturnValues{ - models.ProjectResult{ + project.Result{ PlanSuccess: &models.PlanSuccess{}, }, } } // The second call, we return a failed result. return ReturnValues{ - models.ProjectResult{ + project.Result{ Error: errors.New("err"), }, } @@ -596,7 +597,7 @@ func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]models.ProjectCommandContext{ + When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]project.Context{ { CommandName: command.ApprovePolicies, }, @@ -643,7 +644,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]models.ProjectCommandContext{ + When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]project.Context{ { CommandName: command.ApprovePolicies, PolicySets: valid.PolicySets{ @@ -657,7 +658,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(workingDir.GetPullDir(fixtures.GithubRepo, fixtures.Pull)).ThenReturn(tmp, nil) When(projectCommandRunner.ApprovePolicies(matchers.AnyModelsProjectCommandContext())).Then(func(_ []Param) ReturnValues { return ReturnValues{ - models.ProjectResult{ + project.Result{ Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, @@ -699,7 +700,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil) When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - _, _ = boltDB.UpdatePullWithResults(modelPull, []models.ProjectResult{ + _, _ = boltDB.UpdatePullWithResults(modelPull, []project.Result{ { Command: command.PolicyCheck, Error: fmt.Errorf("failing policy"), @@ -713,7 +714,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { When(projectCommandBuilder.BuildApplyCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).Then(func(args []Param) ReturnValues { return ReturnValues{ - []models.ProjectCommandContext{ + []project.Context{ { CommandName: command.Apply, ProjectName: "default", @@ -766,7 +767,7 @@ func TestRunApply_DiscardedProjects(t *testing.T) { applyCommandRunner.DB = boltDB pull := fixtures.Pull pull.BaseRepo = fixtures.GithubRepo - _, err = boltDB.UpdatePullWithResults(pull, []models.ProjectResult{ + _, err = boltDB.UpdatePullWithResults(pull, []project.Result{ { Command: command.Plan, RepoRelDir: ".", diff --git a/server/events/commit_status_updater.go b/server/events/commit_status_updater.go index 6009e0901..0b343f605 100644 --- a/server/events/commit_status_updater.go +++ b/server/events/commit_status_updater.go @@ -18,6 +18,7 @@ import ( "strings" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -35,7 +36,7 @@ type CommitStatusUpdater interface { UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error } // DefaultCommitStatusUpdater implements CommitStatusUpdater. @@ -66,7 +67,7 @@ func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull return d.Client.UpdateStatus(repo, pull, status, src, fmt.Sprintf("%d/%d projects %s successfully.", numSuccess, numTotal, cmdVerb), "") } -func (d *DefaultCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { +func (d *DefaultCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { projectID := ctx.ProjectName if projectID == "" { projectID = fmt.Sprintf("%s/%s", ctx.RepoRelDir, ctx.Workspace) diff --git a/server/events/commit_status_updater_test.go b/server/events/commit_status_updater_test.go index 17a576983..6ef8fffaf 100644 --- a/server/events/commit_status_updater_test.go +++ b/server/events/commit_status_updater_test.go @@ -20,6 +20,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -176,7 +177,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectSrc(t *testing.T) { client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "atlantis"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(models.ProjectCommandContext{ + err := s.UpdateProject(project.Context{ ProjectName: c.projectName, RepoRelDir: c.repoRelDir, Workspace: c.workspace, @@ -235,7 +236,7 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "atlantis"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(models.ProjectCommandContext{ + err := s.UpdateProject(project.Context{ RepoRelDir: ".", Workspace: "default", }, @@ -254,7 +255,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectCustomStatusName(t *testing.T) client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "custom"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(models.ProjectCommandContext{ + err := s.UpdateProject(project.Context{ RepoRelDir: ".", Workspace: "default", }, diff --git a/server/events/db_updater.go b/server/events/db_updater.go index 20c9c59c3..73c39e7d2 100644 --- a/server/events/db_updater.go +++ b/server/events/db_updater.go @@ -3,6 +3,7 @@ package events import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -10,11 +11,11 @@ type DBUpdater struct { DB *db.BoltDB } -func (c *DBUpdater) updateDB(ctx *command.Context, pull models.PullRequest, results []models.ProjectResult) (models.PullStatus, error) { +func (c *DBUpdater) updateDB(ctx *command.Context, pull models.PullRequest, results []project.Result) (models.PullStatus, error) { // Filter out results that errored due to the directory not existing. We // don't store these in the database because they would never be "apply-able" // and so the pull request would always have errors. - var filtered []models.ProjectResult + var filtered []project.Result for _, r := range results { if _, ok := r.Error.(DirNotExistErr); ok { ctx.Log.Debug("ignoring error result from project at dir %q workspace %q because it is dir not exist error", r.RepoRelDir, r.Workspace) diff --git a/server/events/instrumented_project_command_builder.go b/server/events/instrumented_project_command_builder.go index 1c6e7ef0d..4284fcd8c 100644 --- a/server/events/instrumented_project_command_builder.go +++ b/server/events/instrumented_project_command_builder.go @@ -2,8 +2,8 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/metrics" - "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" ) @@ -12,7 +12,7 @@ type InstrumentedProjectCommandBuilder struct { Logger logging.SimpleLogging } -func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -33,7 +33,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Cont return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -54,7 +54,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.C return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() diff --git a/server/events/instrumented_project_command_runner.go b/server/events/instrumented_project_command_runner.go index b060b12f1..da305eddd 100644 --- a/server/events/instrumented_project_command_runner.go +++ b/server/events/instrumented_project_command_runner.go @@ -1,27 +1,27 @@ package events import ( + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/metrics" - "github.com/runatlantis/atlantis/server/events/models" ) type InstrumentedProjectCommandRunner struct { ProjectCommandRunner } -func (p *InstrumentedProjectCommandRunner) Plan(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *InstrumentedProjectCommandRunner) Plan(ctx project.Context) project.Result { return RunAndEmitStats("plan", ctx, p.ProjectCommandRunner.Plan) } -func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { return RunAndEmitStats("policy check", ctx, p.ProjectCommandRunner.PolicyCheck) } -func (p *InstrumentedProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *InstrumentedProjectCommandRunner) Apply(ctx project.Context) project.Result { return RunAndEmitStats("apply", ctx, p.ProjectCommandRunner.Apply) } -func RunAndEmitStats(commandName string, ctx models.ProjectCommandContext, execute func(ctx models.ProjectCommandContext) models.ProjectResult) models.ProjectResult { +func RunAndEmitStats(commandName string, ctx project.Context, execute func(ctx project.Context) project.Result) project.Result { // ensures we are differentiating between project level command and overall command ctx.SetScope("project") diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index e14710009..f1dc88030 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -24,6 +24,7 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -124,7 +125,7 @@ func (m *MarkdownRenderer) Render(res command.Result, cmdName command.Name, log return m.renderProjectResults(res.ProjectResults, common, vcsHost, templateOverrides) } -func (m *MarkdownRenderer) renderProjectResults(results []models.ProjectResult, common commonData, vcsHost models.VCSHostType, templateOverrides map[string]string) string { +func (m *MarkdownRenderer) renderProjectResults(results []project.Result, common commonData, vcsHost models.VCSHostType, templateOverrides map[string]string) string { var resultsTmplData []projectResultTmplData numPlanSuccesses := 0 numPolicyCheckSuccesses := 0 diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 835cda0ed..00855a6b3 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -21,6 +21,7 @@ import ( "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -29,7 +30,7 @@ func TestCustomTemplates(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string TemplateOverrides map[string]string @@ -37,7 +38,7 @@ func TestCustomTemplates(t *testing.T) { { "Plan Override", command.Plan, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Custom Template", map[string]string{"plan": "testdata/custom_template.tmpl"}, @@ -45,7 +46,7 @@ func TestCustomTemplates(t *testing.T) { { "Default Plan", command.Plan, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", map[string]string{"apply": "testdata/custom_template.tmpl"}, @@ -53,7 +54,7 @@ func TestCustomTemplates(t *testing.T) { { "Apply Override", command.Apply, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Custom Template", map[string]string{"apply": "testdata/custom_template.tmpl"}, @@ -61,7 +62,7 @@ func TestCustomTemplates(t *testing.T) { { "Project Plan Successful Custom Template", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path1", @@ -109,7 +110,7 @@ Custom Template { "Only Use Plan Success Override with failed, and errored plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -282,28 +283,28 @@ func TestRenderProjectResults(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string }{ { "no projects", command.Plan, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "approve policies", command.ApprovePolicies, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Approved Policies for 0 projects:\n\n\n\n", }, { "single successful plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -338,7 +339,7 @@ $$$ { "single successful plan with master ahead", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -376,7 +377,7 @@ $$$ { "single successful plan with project name", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -412,7 +413,7 @@ $$$ { "single successful policy check with project name", command.PolicyCheck, - []models.ProjectResult{ + []project.Result{ { PolicyCheckSuccess: &models.PolicyCheckSuccess{ PolicyCheckOutput: "2 tests, 1 passed, 0 warnings, 0 failure, 0 exceptions", @@ -448,7 +449,7 @@ $$$ { "single successful apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { ApplySuccess: "success", Workspace: "workspace", @@ -467,7 +468,7 @@ $$$ { "single successful apply with project name", command.Apply, - []models.ProjectResult{ + []project.Result{ { ApplySuccess: "success", Workspace: "workspace", @@ -487,7 +488,7 @@ $$$ { "multiple successful plans", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -549,7 +550,7 @@ $$$ { "multiple successful policy checks", command.PolicyCheck, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -611,7 +612,7 @@ $$$ { "multiple successful applies", command.Apply, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: "path", Workspace: "workspace", @@ -648,7 +649,7 @@ $$$ { "single errored plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { Error: errors.New("error"), RepoRelDir: "path", @@ -668,7 +669,7 @@ $$$ { "single failed plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: "path", Workspace: "workspace", @@ -685,7 +686,7 @@ $$$ { "successful, failed, and errored plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -747,7 +748,7 @@ $$$ { "successful, failed, and errored policy check", command.PolicyCheck, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -811,7 +812,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -858,7 +859,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -930,14 +931,14 @@ func TestRenderProjectResultsDisableApplyAll(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply all set", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -968,7 +969,7 @@ $$$ { "single successful plan with project name with disable apply all set", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1000,7 +1001,7 @@ $$$ { "multiple successful plans, disable apply all set", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -1083,14 +1084,14 @@ func TestRenderProjectResultsDisableApply(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply set", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1119,7 +1120,7 @@ $$$ { "single successful plan with project name with disable apply set", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1149,7 +1150,7 @@ $$$ { "multiple successful plans, disable apply set", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -1231,7 +1232,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { } rendered := mr.Render(command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "default", @@ -1315,7 +1316,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { } rendered := mr.Render(command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "default", @@ -1425,10 +1426,10 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { mr := events.MarkdownRenderer{ GitlabSupportsCommonMark: c.GitlabCommonMarkSupport, } - var pr models.ProjectResult + var pr project.Result switch cmd { case command.Plan: - pr = models.ProjectResult{ + pr = project.Result{ RepoRelDir: ".", Workspace: "default", PlanSuccess: &models.PlanSuccess{ @@ -1439,14 +1440,14 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { }, } case command.Apply: - pr = models.ProjectResult{ + pr = project.Result{ RepoRelDir: ".", Workspace: "default", ApplySuccess: c.Output, } } rendered := mr.Render(command.Result{ - ProjectResults: []models.ProjectResult{pr}, + ProjectResults: []project.Result{pr}, }, cmd, "log", false, c.VCSHost, make(map[string]string)) // Check result. @@ -1530,7 +1531,7 @@ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) rendered := mr.Render(command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -1576,7 +1577,7 @@ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) + "Plan: 1 to add, 0 to change, 0 to destroy." rendered := mr.Render(command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -1654,7 +1655,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }{ "one failure": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -1671,7 +1672,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }, "two failures": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -1703,7 +1704,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }, "one failure, one success": { cr: command.Result{ - ProjectResults: []models.ProjectResult{ + ProjectResults: []project.Result{ { RepoRelDir: ".", Workspace: "staging", @@ -1759,21 +1760,21 @@ func TestRenderProjectResultsWithRepoLockingDisabled(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string }{ { "no projects", command.Plan, - []models.ProjectResult{}, + []project.Result{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "single successful plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1807,7 +1808,7 @@ $$$ { "single successful plan with master ahead", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1844,7 +1845,7 @@ $$$ { "single successful plan with project name", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1879,7 +1880,7 @@ $$$ { "single successful apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { ApplySuccess: "success", Workspace: "workspace", @@ -1898,7 +1899,7 @@ $$$ { "single successful apply with project name", command.Apply, - []models.ProjectResult{ + []project.Result{ { ApplySuccess: "success", Workspace: "workspace", @@ -1918,7 +1919,7 @@ $$$ { "multiple successful plans", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -1978,7 +1979,7 @@ $$$ { "multiple successful applies", command.Apply, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: "path", Workspace: "workspace", @@ -2015,7 +2016,7 @@ $$$ { "single errored plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { Error: errors.New("error"), RepoRelDir: "path", @@ -2035,7 +2036,7 @@ $$$ { "single failed plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { RepoRelDir: "path", Workspace: "workspace", @@ -2052,7 +2053,7 @@ $$$ { "successful, failed, and errored plan", command.Plan, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -2113,7 +2114,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -2160,7 +2161,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []models.ProjectResult{ + []project.Result{ { Workspace: "workspace", RepoRelDir: "path", @@ -2339,14 +2340,14 @@ Plan: 1 to add, 1 to change, 1 to destroy. cases := []struct { Description string Command command.Name - ProjectResults []models.ProjectResult + ProjectResults []project.Result VCSHost models.VCSHostType Expected string }{ { "single successful plan with diff markdown formatted", command.Plan, - []models.ProjectResult{ + []project.Result{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: tfOutput, diff --git a/server/events/mocks/matchers/models_projectcommandcontext.go b/server/events/mocks/matchers/models_projectcommandcontext.go index 8972dd412..93d072cb5 100644 --- a/server/events/mocks/matchers/models_projectcommandcontext.go +++ b/server/events/mocks/matchers/models_projectcommandcontext.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnyModelsProjectCommandContext() models.ProjectCommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ProjectCommandContext))(nil)).Elem())) - var nullValue models.ProjectCommandContext +func AnyModelsProjectCommandContext() project.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) + var nullValue project.Context return nullValue } -func EqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func EqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func NotEqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func NotEqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) models.ProjectCommandContext { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { pegomock.RegisterMatcher(matcher) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } diff --git a/server/events/mocks/matchers/models_projectresult.go b/server/events/mocks/matchers/models_projectresult.go index 368a046f4..55db043a4 100644 --- a/server/events/mocks/matchers/models_projectresult.go +++ b/server/events/mocks/matchers/models_projectresult.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnyModelsProjectResult() models.ProjectResult { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ProjectResult))(nil)).Elem())) - var nullValue models.ProjectResult +func AnyModelsProjectResult() project.Result { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Result))(nil)).Elem())) + var nullValue project.Result return nullValue } -func EqModelsProjectResult(value models.ProjectResult) models.ProjectResult { +func EqModelsProjectResult(value project.Result) project.Result { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.ProjectResult + var nullValue project.Result return nullValue } -func NotEqModelsProjectResult(value models.ProjectResult) models.ProjectResult { +func NotEqModelsProjectResult(value project.Result) project.Result { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.ProjectResult + var nullValue project.Result return nullValue } -func ModelsProjectResultThat(matcher pegomock.ArgumentMatcher) models.ProjectResult { +func ModelsProjectResultThat(matcher pegomock.ArgumentMatcher) project.Result { pegomock.RegisterMatcher(matcher) - var nullValue models.ProjectResult + var nullValue project.Result return nullValue } diff --git a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go index 7dd1ec51b..ea31d6b3a 100644 --- a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go +++ b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnySliceOfModelsProjectCommandContext() []models.ProjectCommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*([]models.ProjectCommandContext))(nil)).Elem())) - var nullValue []models.ProjectCommandContext +func AnySliceOfModelsProjectCommandContext() []project.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*([]project.Context))(nil)).Elem())) + var nullValue []project.Context return nullValue } -func EqSliceOfModelsProjectCommandContext(value []models.ProjectCommandContext) []models.ProjectCommandContext { +func EqSliceOfModelsProjectCommandContext(value []project.Context) []project.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue []models.ProjectCommandContext + var nullValue []project.Context return nullValue } -func NotEqSliceOfModelsProjectCommandContext(value []models.ProjectCommandContext) []models.ProjectCommandContext { +func NotEqSliceOfModelsProjectCommandContext(value []project.Context) []project.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue []models.ProjectCommandContext + var nullValue []project.Context return nullValue } -func SliceOfModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) []models.ProjectCommandContext { +func SliceOfModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) []project.Context { pegomock.RegisterMatcher(matcher) - var nullValue []models.ProjectCommandContext + var nullValue []project.Context return nullValue } diff --git a/server/events/mocks/mock_apply_handler.go b/server/events/mocks/mock_apply_handler.go index fb303e9bc..8c64583a0 100644 --- a/server/events/mocks/mock_apply_handler.go +++ b/server/events/mocks/mock_apply_handler.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockApplyRequirement struct { @@ -26,7 +26,7 @@ func NewMockApplyRequirement(options ...pegomock.Option) *MockApplyRequirement { func (mock *MockApplyRequirement) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockApplyRequirement) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockApplyRequirement) ValidateProject(_param0 string, _param1 models.ProjectCommandContext) (string, error) { +func (mock *MockApplyRequirement) ValidateProject(_param0 string, _param1 project.Context) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockApplyRequirement().") } @@ -82,7 +82,7 @@ type VerifierMockApplyRequirement struct { timeout time.Duration } -func (verifier *VerifierMockApplyRequirement) ValidateProject(_param0 string, _param1 models.ProjectCommandContext) *MockApplyRequirement_ValidateProject_OngoingVerification { +func (verifier *VerifierMockApplyRequirement) ValidateProject(_param0 string, _param1 project.Context) *MockApplyRequirement_ValidateProject_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidateProject", params, verifier.timeout) return &MockApplyRequirement_ValidateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,21 +93,21 @@ type MockApplyRequirement_ValidateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetCapturedArguments() (string, models.ProjectCommandContext) { +func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetCapturedArguments() (string, project.Context) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []models.ProjectCommandContext) { +func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(string) } - _param1 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param1 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(models.ProjectCommandContext) + _param1[u] = param.(project.Context) } } return diff --git a/server/events/mocks/mock_commit_status_updater.go b/server/events/mocks/mock_commit_status_updater.go index 00bf6032f..561338798 100644 --- a/server/events/mocks/mock_commit_status_updater.go +++ b/server/events/mocks/mock_commit_status_updater.go @@ -9,6 +9,7 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -57,7 +58,7 @@ func (mock *MockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull return ret0 } -func (mock *MockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error { +func (mock *MockCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCommitStatusUpdater().") } @@ -195,7 +196,7 @@ func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAll return } -func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{ctx, cmdName, status, url} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockCommitStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -206,17 +207,17 @@ type MockCommitStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus, string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus, string) { ctx, cmdName, status, url := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], url[len(url)-1] } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_custom_step_runner.go b/server/events/mocks/mock_custom_step_runner.go index 5a4f22a59..c3ca4756c 100644 --- a/server/events/mocks/mock_custom_step_runner.go +++ b/server/events/mocks/mock_custom_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockCustomStepRunner struct { @@ -26,7 +26,7 @@ func NewMockCustomStepRunner(options ...pegomock.Option) *MockCustomStepRunner { func (mock *MockCustomStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockCustomStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockCustomStepRunner) Run(ctx models.ProjectCommandContext, cmd string, path string, envs map[string]string) (string, error) { +func (mock *MockCustomStepRunner) Run(ctx project.Context, cmd string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCustomStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockCustomStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockCustomStepRunner) Run(ctx models.ProjectCommandContext, cmd string, path string, envs map[string]string) *MockCustomStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockCustomStepRunner) Run(ctx project.Context, cmd string, path string, envs map[string]string) *MockCustomStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, cmd, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockCustomStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockCustomStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCustomStepRunner_Run_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string, string, map[string]string) { +func (c *MockCustomStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, string, map[string]string) { ctx, cmd, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmd[len(cmd)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockCustomStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 []string, _param3 []map[string]string) { +func (c *MockCustomStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_env_step_runner.go b/server/events/mocks/mock_env_step_runner.go index 1d8188d3a..fd97c5319 100644 --- a/server/events/mocks/mock_env_step_runner.go +++ b/server/events/mocks/mock_env_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockEnvStepRunner struct { @@ -26,7 +26,7 @@ func NewMockEnvStepRunner(options ...pegomock.Option) *MockEnvStepRunner { func (mock *MockEnvStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockEnvStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockEnvStepRunner) Run(ctx models.ProjectCommandContext, cmd string, value string, path string, envs map[string]string) (string, error) { +func (mock *MockEnvStepRunner) Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockEnvStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockEnvStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockEnvStepRunner) Run(ctx models.ProjectCommandContext, cmd string, value string, path string, envs map[string]string) *MockEnvStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockEnvStepRunner) Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) *MockEnvStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, cmd, value, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockEnvStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockEnvStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockEnvStepRunner_Run_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string, string, string, map[string]string) { +func (c *MockEnvStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, string, string, map[string]string) { ctx, cmd, value, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmd[len(cmd)-1], value[len(value)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockEnvStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 []string, _param3 []string, _param4 []map[string]string) { +func (c *MockEnvStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []string, _param3 []string, _param4 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_job_message_sender.go b/server/events/mocks/mock_job_message_sender.go index 224f05c99..14b5c07c2 100644 --- a/server/events/mocks/mock_job_message_sender.go +++ b/server/events/mocks/mock_job_message_sender.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockJobMessageSender struct { @@ -26,7 +26,7 @@ func NewMockJobMessageSender(options ...pegomock.Option) *MockJobMessageSender { func (mock *MockJobMessageSender) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobMessageSender) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobMessageSender) Send(_param0 models.ProjectCommandContext, _param1 string, _param2 bool) { +func (mock *MockJobMessageSender) Send(_param0 project.Context, _param1 string, _param2 bool) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobMessageSender().") } @@ -71,7 +71,7 @@ type VerifierMockJobMessageSender struct { timeout time.Duration } -func (verifier *VerifierMockJobMessageSender) Send(_param0 models.ProjectCommandContext, _param1 string, _param2 bool) *MockJobMessageSender_Send_OngoingVerification { +func (verifier *VerifierMockJobMessageSender) Send(_param0 project.Context, _param1 string, _param2 bool) *MockJobMessageSender_Send_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) return &MockJobMessageSender_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -82,17 +82,17 @@ type MockJobMessageSender_Send_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobMessageSender_Send_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string, bool) { +func (c *MockJobMessageSender_Send_OngoingVerification) GetCapturedArguments() (project.Context, string, bool) { _param0, _param1, _param2 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] } -func (c *MockJobMessageSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 []bool) { +func (c *MockJobMessageSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []bool) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index e9b95b0bb..89e291404 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -9,6 +9,7 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -27,7 +28,7 @@ func NewMockJobURLSetter(options ...pegomock.Option) *MockJobURLSetter { func (mock *MockJobURLSetter) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobURLSetter) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus) error { +func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobURLSetter().") } @@ -79,7 +80,7 @@ type VerifierMockJobURLSetter struct { timeout time.Duration } -func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { +func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", params, verifier.timeout) return &MockJobURLSetter_SetJobURLWithStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -90,17 +91,17 @@ type MockJobURLSetter_SetJobURLWithStatus_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus) { _param0, _param1, _param2 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_log_stream_url_generator.go b/server/events/mocks/mock_log_stream_url_generator.go index 0707eab5c..a903f0acb 100644 --- a/server/events/mocks/mock_log_stream_url_generator.go +++ b/server/events/mocks/mock_log_stream_url_generator.go @@ -8,6 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" + "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -26,7 +27,7 @@ func NewMockJobsUrlGenerator(options ...pegomock.Option) *MockJobsUrlGenerator { func (mock *MockJobsUrlGenerator) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobsUrlGenerator) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p models.ProjectCommandContext) string { +func (mock *MockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p project.Context) string { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobsUrlGenerator().") } @@ -78,7 +79,7 @@ type VerifierMockJobsUrlGenerator struct { timeout time.Duration } -func (verifier *VerifierMockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p models.ProjectCommandContext) *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification { +func (verifier *VerifierMockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p project.Context) *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification { params := []pegomock.Param{pull, p} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateProjectJobsUrl", params, verifier.timeout) return &MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -89,21 +90,21 @@ type MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetCapturedArguments() (models.PullRequest, models.ProjectCommandContext) { +func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetCapturedArguments() (models.PullRequest, project.Context) { pull, p := c.GetAllCapturedArguments() return pull[len(pull)-1], p[len(p)-1] } -func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest, _param1 []models.ProjectCommandContext) { +func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest, _param1 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.PullRequest, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(models.PullRequest) } - _param1 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param1 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(models.ProjectCommandContext) + _param1[u] = param.(project.Context) } } return diff --git a/server/events/mocks/mock_project_command_builder.go b/server/events/mocks/mock_project_command_builder.go index 6e4178b70..87e5cc80c 100644 --- a/server/events/mocks/mock_project_command_builder.go +++ b/server/events/mocks/mock_project_command_builder.go @@ -10,7 +10,7 @@ import ( pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockProjectCommandBuilder struct { @@ -28,17 +28,17 @@ func NewMockProjectCommandBuilder(options ...pegomock.Option) *MockProjectComman func (mock *MockProjectCommandBuilder) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandBuilder) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", params, []reflect.Type{reflect.TypeOf((*[]models.ProjectCommandContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []models.ProjectCommandContext + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []project.Context var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]models.ProjectCommandContext) + ret0 = result[0].([]project.Context) } if result[1] != nil { ret1 = result[1].(error) @@ -47,17 +47,17 @@ func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Contex return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", params, []reflect.Type{reflect.TypeOf((*[]models.ProjectCommandContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []models.ProjectCommandContext + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []project.Context var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]models.ProjectCommandContext) + ret0 = result[0].([]project.Context) } if result[1] != nil { ret1 = result[1].(error) @@ -66,17 +66,17 @@ func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, c return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", params, []reflect.Type{reflect.TypeOf((*[]models.ProjectCommandContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []models.ProjectCommandContext + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []project.Context var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]models.ProjectCommandContext) + ret0 = result[0].([]project.Context) } if result[1] != nil { ret1 = result[1].(error) @@ -85,17 +85,17 @@ func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", params, []reflect.Type{reflect.TypeOf((*[]models.ProjectCommandContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []models.ProjectCommandContext + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []project.Context var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]models.ProjectCommandContext) + ret0 = result[0].([]project.Context) } if result[1] != nil { ret1 = result[1].(error) @@ -104,17 +104,17 @@ func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]models.ProjectCommandContext, error) { +func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", params, []reflect.Type{reflect.TypeOf((*[]models.ProjectCommandContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []models.ProjectCommandContext + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []project.Context var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]models.ProjectCommandContext) + ret0 = result[0].([]project.Context) } if result[1] != nil { ret1 = result[1].(error) diff --git a/server/events/mocks/mock_project_command_runner.go b/server/events/mocks/mock_project_command_runner.go index 9fd049fdd..682e2051a 100644 --- a/server/events/mocks/mock_project_command_runner.go +++ b/server/events/mocks/mock_project_command_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockProjectCommandRunner struct { @@ -26,76 +26,76 @@ func NewMockProjectCommandRunner(options ...pegomock.Option) *MockProjectCommand func (mock *MockProjectCommandRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandRunner) Plan(ctx models.ProjectCommandContext) models.ProjectResult { +func (mock *MockProjectCommandRunner) Plan(ctx project.Context) project.Result { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", params, []reflect.Type{reflect.TypeOf((*models.ProjectResult)(nil)).Elem()}) - var ret0 models.ProjectResult + result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) + var ret0 project.Result if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(models.ProjectResult) + ret0 = result[0].(project.Result) } } return ret0 } -func (mock *MockProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (mock *MockProjectCommandRunner) Apply(ctx project.Context) project.Result { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", params, []reflect.Type{reflect.TypeOf((*models.ProjectResult)(nil)).Elem()}) - var ret0 models.ProjectResult + result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) + var ret0 project.Result if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(models.ProjectResult) + ret0 = result[0].(project.Result) } } return ret0 } -func (mock *MockProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult { +func (mock *MockProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", params, []reflect.Type{reflect.TypeOf((*models.ProjectResult)(nil)).Elem()}) - var ret0 models.ProjectResult + result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) + var ret0 project.Result if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(models.ProjectResult) + ret0 = result[0].(project.Result) } } return ret0 } -func (mock *MockProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandContext) models.ProjectResult { +func (mock *MockProjectCommandRunner) ApprovePolicies(ctx project.Context) project.Result { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", params, []reflect.Type{reflect.TypeOf((*models.ProjectResult)(nil)).Elem()}) - var ret0 models.ProjectResult + result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) + var ret0 project.Result if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(models.ProjectResult) + ret0 = result[0].(project.Result) } } return ret0 } -func (mock *MockProjectCommandRunner) Version(ctx models.ProjectCommandContext) models.ProjectResult { +func (mock *MockProjectCommandRunner) Version(ctx project.Context) project.Result { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*models.ProjectResult)(nil)).Elem()}) - var ret0 models.ProjectResult + result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) + var ret0 project.Result if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(models.ProjectResult) + ret0 = result[0].(project.Result) } } return ret0 @@ -138,7 +138,7 @@ type VerifierMockProjectCommandRunner struct { timeout time.Duration } -func (verifier *VerifierMockProjectCommandRunner) Plan(ctx models.ProjectCommandContext) *MockProjectCommandRunner_Plan_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Plan(ctx project.Context) *MockProjectCommandRunner_Plan_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Plan", params, verifier.timeout) return &MockProjectCommandRunner_Plan_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -149,23 +149,23 @@ type MockProjectCommandRunner_Plan_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetCapturedArguments() project.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return } -func (verifier *VerifierMockProjectCommandRunner) Apply(ctx models.ProjectCommandContext) *MockProjectCommandRunner_Apply_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Apply(ctx project.Context) *MockProjectCommandRunner_Apply_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Apply", params, verifier.timeout) return &MockProjectCommandRunner_Apply_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -176,23 +176,23 @@ type MockProjectCommandRunner_Apply_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetCapturedArguments() project.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return } -func (verifier *VerifierMockProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) *MockProjectCommandRunner_PolicyCheck_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) PolicyCheck(ctx project.Context) *MockProjectCommandRunner_PolicyCheck_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PolicyCheck", params, verifier.timeout) return &MockProjectCommandRunner_PolicyCheck_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -203,23 +203,23 @@ type MockProjectCommandRunner_PolicyCheck_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetCapturedArguments() project.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return } -func (verifier *VerifierMockProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandContext) *MockProjectCommandRunner_ApprovePolicies_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) ApprovePolicies(ctx project.Context) *MockProjectCommandRunner_ApprovePolicies_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ApprovePolicies", params, verifier.timeout) return &MockProjectCommandRunner_ApprovePolicies_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -230,23 +230,23 @@ type MockProjectCommandRunner_ApprovePolicies_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetCapturedArguments() project.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return } -func (verifier *VerifierMockProjectCommandRunner) Version(ctx models.ProjectCommandContext) *MockProjectCommandRunner_Version_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Version(ctx project.Context) *MockProjectCommandRunner_Version_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) return &MockProjectCommandRunner_Version_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -257,17 +257,17 @@ type MockProjectCommandRunner_Version_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Version_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectCommandRunner_Version_OngoingVerification) GetCapturedArguments() project.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Version_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectCommandRunner_Version_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return diff --git a/server/events/mocks/mock_step_runner.go b/server/events/mocks/mock_step_runner.go index aed553c40..fcdac101c 100644 --- a/server/events/mocks/mock_step_runner.go +++ b/server/events/mocks/mock_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockStepRunner struct { @@ -26,7 +26,7 @@ func NewMockStepRunner(options ...pegomock.Option) *MockStepRunner { func (mock *MockStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (mock *MockStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) *MockStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) *MockStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, extraArgs, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockStepRunner_Run_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, []string, string, map[string]string) { +func (c *MockStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, []string, string, map[string]string) { ctx, extraArgs, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], extraArgs[len(extraArgs)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 [][]string, _param2 []string, _param3 []map[string]string) { +func (c *MockStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 [][]string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([][]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/models/models.go b/server/events/models/models.go index aad976fe0..9626db093 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -20,21 +20,14 @@ import ( "fmt" "net/url" paths "path" - "path/filepath" "regexp" "strings" "time" - "github.com/hashicorp/go-version" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" - "github.com/uber-go/tally" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/core/config/valid" -) - -const ( - planfileSlashReplace = "::" ) type PullReqStatus struct { @@ -242,7 +235,7 @@ type LockMetadata struct { type CommandLock struct { // Time is the time at which the lock was first created. LockMetadata LockMetadata - CommandName command.CommandName + CommandName command.Name } func (l *CommandLock) LockTime() time.Time { @@ -348,128 +341,6 @@ func (h VCSHostType) String() string { return "" } -// ProjectCommandContext defines the context for a plan or apply stage that will -// be executed for a project. -type ProjectCommandContext struct { - CommandName command.CommandName - // ApplyCmd is the command that users should run to apply this plan. If - // this is an apply then this will be empty. - ApplyCmd string - // ApplyRequirements is the list of requirements that must be satisfied - // before we will run the apply stage. - ApplyRequirements []string - // AutomergeEnabled is true if automerge is enabled for the repo that this - // project is in. - AutomergeEnabled bool - // ParallelApplyEnabled is true if parallel apply is enabled for this project. - ParallelApplyEnabled bool - // ParallelPlanEnabled is true if parallel plan is enabled for this project. - ParallelPlanEnabled bool - // ParallelPolicyCheckEnabled is true if parallel policy_check is enabled for this project. - ParallelPolicyCheckEnabled bool - // AutoplanEnabled is true if autoplanning is enabled for this project. - AutoplanEnabled bool - // BaseRepo is the repository that the pull request will be merged into. - BaseRepo Repo - // EscapedCommentArgs are the extra arguments that were added to the atlantis - // command, ex. atlantis plan -- -target=resource. We then escape them - // by adding a \ before each character so that they can be used within - // sh -c safely, i.e. sh -c "terraform plan $(touch bad)". - EscapedCommentArgs []string - // HeadRepo is the repository that is getting merged into the BaseRepo. - // If the pull request branch is from the same repository then HeadRepo will - // be the same as BaseRepo. - HeadRepo Repo - // Log is a logger that's been set up for this context. - Log logging.SimpleLogging - // Scope is the scope for reporting stats setup for this context - Scope tally.Scope - // PullReqStatus holds state about the PR that requires additional computation outside models.PullRequest - PullReqStatus PullReqStatus - // CurrentProjectPlanStatus is the status of the current project prior to this command. - ProjectPlanStatus ProjectPlanStatus - // Pull is the pull request we're responding to. - Pull PullRequest - // ProjectName is the name of the project set in atlantis.yaml. If there was - // no name this will be an empty string. - ProjectName string - // RepoConfigVersion is the version of the repo's atlantis.yaml file. If - // there was no file, this will be 0. - RepoConfigVersion int - // RePlanCmd is the command that users should run to re-plan this project. - // If this is an apply then this will be empty. - RePlanCmd string - // RepoRelDir is the directory of this project relative to the repo root. - RepoRelDir string - // Steps are the sequence of commands we need to run for this project and this - // stage. - Steps []valid.Step - // TerraformVersion is the version of terraform we should use when executing - // commands for this project. This can be set to nil in which case we will - // use the default Atlantis terraform version. - TerraformVersion *version.Version - // Configuration metadata for a given project. - Tags map[string]string - // User is the user that triggered this command. - User User - // Verbose is true when the user would like verbose output. - Verbose bool - // ForceApply is true when the apply should ignore apply_requirements. - ForceApply bool - // Workspace is the Terraform workspace this project is in. It will always - // be set. - Workspace string - // PolicySets represent the policies that are run on the plan as part of the - // policy check stage - PolicySets valid.PolicySets - // DeleteSourceBranchOnMerge will attempt to allow a branch to be deleted when merged (AzureDevOps & GitLab Support Only) - DeleteSourceBranchOnMerge bool - // UUID for atlantis logs - JobID string -} - -// ProjectCloneDir creates relative path to clone the repo to. If we are running -// plans and apply in parallel we want to have a directory per project. -func (p ProjectCommandContext) ProjectCloneDir() string { - if p.ParallelPlanEnabled || p.ParallelApplyEnabled { - return filepath.Join(p.ProjectName, p.Workspace) - } - - return p.Workspace -} - -// SetScope sets the scope of the stats object field. Note: we deliberately set this on the value -// instead of a pointer since we want scopes to mirror our function stack -func (p ProjectCommandContext) SetScope(scope string) { - p.Scope = p.Scope.SubScope(scope) //nolint -} - -// GetShowResultFileName returns the filename (not the path) to store the tf show result -func (p ProjectCommandContext) GetShowResultFileName() string { - if p.ProjectName == "" { - return fmt.Sprintf("%s.json", p.Workspace) - } - projName := strings.Replace(p.ProjectName, "/", planfileSlashReplace, -1) - return fmt.Sprintf("%s-%s.json", projName, p.Workspace) -} - -// Gets a unique identifier for the current pull request as a single string -func (p ProjectCommandContext) PullInfo() string { - return BuildPullInfo(p.BaseRepo.FullName, p.Pull.Num, p.ProjectName, p.RepoRelDir, p.Workspace) -} - -func BuildPullInfo(repoName string, pullNum int, projectName string, relDir string, workspace string) string { - projectIdentifier := GetProjectIdentifier(relDir, projectName) - return fmt.Sprintf("%s/%d/%s/%s", repoName, pullNum, projectIdentifier, workspace) -} - -func GetProjectIdentifier(relRepoDir string, projectName string) string { - if projectName != "" { - return projectName - } - return strings.ReplaceAll(relRepoDir, "/", "-") -} - // SplitRepoFullName splits a repo full name up into its owner and repo // name segments. If the repoFullName is malformed, may return empty // strings for owner or repo. @@ -485,66 +356,6 @@ func SplitRepoFullName(repoFullName string) (owner string, repo string) { return repoFullName[:lastSlashIdx], repoFullName[lastSlashIdx+1:] } -// ProjectResult is the result of executing a plan/policy_check/apply for a specific project. -type ProjectResult struct { - Command CommandName - RepoRelDir string - Workspace string - Error error - Failure string - PlanSuccess *PlanSuccess - PolicyCheckSuccess *PolicyCheckSuccess - ApplySuccess string - VersionSuccess string - ProjectName string -} - -// CommitStatus returns the vcs commit status of this project result. -func (p ProjectResult) CommitStatus() CommitStatus { - if p.Error != nil { - return FailedCommitStatus - } - if p.Failure != "" { - return FailedCommitStatus - } - return SuccessCommitStatus -} - -// PlanStatus returns the plan status. -func (p ProjectResult) PlanStatus() ProjectPlanStatus { - switch p.Command { - - case PlanCommand: - if p.Error != nil { - return ErroredPlanStatus - } else if p.Failure != "" { - return ErroredPlanStatus - } - return PlannedPlanStatus - case PolicyCheckCommand, ApprovePoliciesCommand: - if p.Error != nil { - return ErroredPolicyCheckStatus - } else if p.Failure != "" { - return ErroredPolicyCheckStatus - } - return PassedPolicyCheckStatus - case ApplyCommand: - if p.Error != nil { - return ErroredApplyStatus - } else if p.Failure != "" { - return ErroredApplyStatus - } - return AppliedPlanStatus - } - - panic("PlanStatus() missing a combination") -} - -// IsSuccessful returns true if this project result had no errors. -func (p ProjectResult) IsSuccessful() bool { - return p.PlanSuccess != nil || p.PolicyCheckSuccess != nil || p.ApplySuccess != "" -} - // PlanSuccess is the result of a successful plan. type PlanSuccess struct { // TerraformOutput is the output from Terraform of running plan. diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index 242b437a3..248f3a566 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -18,6 +18,7 @@ import ( "fmt" "testing" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" . "github.com/runatlantis/atlantis/testing" @@ -358,35 +359,35 @@ func TestAzureDevopsSplitRepoFullName(t *testing.T) { func TestProjectResult_IsSuccessful(t *testing.T) { cases := map[string]struct { - pr models.ProjectResult + pr project.Result exp bool }{ "plan success": { - models.ProjectResult{ + project.Result{ PlanSuccess: &models.PlanSuccess{}, }, true, }, "policy_check success": { - models.ProjectResult{ + project.Result{ PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, true, }, "apply success": { - models.ProjectResult{ + project.Result{ ApplySuccess: "success", }, true, }, "failure": { - models.ProjectResult{ + project.Result{ Failure: "failure", }, false, }, "error": { - models.ProjectResult{ + project.Result{ Error: errors.New("error"), }, false, @@ -402,74 +403,74 @@ func TestProjectResult_IsSuccessful(t *testing.T) { func TestProjectResult_PlanStatus(t *testing.T) { cases := []struct { - p models.ProjectResult + p project.Result expStatus models.ProjectPlanStatus }{ { - p: models.ProjectResult{ + p: project.Result{ Command: command.Plan, Error: errors.New("err"), }, expStatus: models.ErroredPlanStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.Plan, Failure: "failure", }, expStatus: models.ErroredPlanStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.Plan, PlanSuccess: &models.PlanSuccess{}, }, expStatus: models.PlannedPlanStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.Apply, Error: errors.New("err"), }, expStatus: models.ErroredApplyStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.Apply, Failure: "failure", }, expStatus: models.ErroredApplyStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.Apply, ApplySuccess: "success", }, expStatus: models.AppliedPlanStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.PolicyCheck, Failure: "failure", }, expStatus: models.ErroredPolicyCheckStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.ApprovePolicies, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { - p: models.ProjectResult{ + p: project.Result{ Command: command.ApprovePolicies, Failure: "failure", }, @@ -486,11 +487,11 @@ func TestProjectResult_PlanStatus(t *testing.T) { func TestPlanSuccess_Summary(t *testing.T) { cases := []struct { - p models.ProjectResult + p project.Result expResult string }{ { - p: models.ProjectResult{ + p: project.Result{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` An execution plan has been generated and is shown below. @@ -508,7 +509,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", }, { - p: models.ProjectResult{ + p: project.Result{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` An execution plan has been generated and is shown below. @@ -520,7 +521,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "No changes. Infrastructure is up-to-date.", }, { - p: models.ProjectResult{ + p: project.Result{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` Note: Objects have changed outside of Terraform @@ -534,7 +535,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "\n**Note: Objects have changed outside of Terraform**\nNo changes. Your infrastructure matches the configuration.", }, { - p: models.ProjectResult{ + p: project.Result{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` Note: Objects have changed outside of Terraform @@ -557,7 +558,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "\n**Note: Objects have changed outside of Terraform**\nPlan: 0 to add, 0 to change, 1 to destroy.", }, { - p: models.ProjectResult{ + p: project.Result{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: `No match, expect empty`, }, diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 9a25131b0..5b43f4943 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -2,6 +2,7 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -265,10 +266,10 @@ func (p *PlanCommandRunner) deletePlans(ctx *command.Context) { func (p *PlanCommandRunner) partitionProjectCmds( ctx *command.Context, - cmds []models.ProjectCommandContext, + cmds []project.Context, ) ( - projectCmds []models.ProjectCommandContext, - policyCheckCmds []models.ProjectCommandContext, + projectCmds []project.Context, + policyCheckCmds []project.Context, ) { for _, cmd := range cmds { switch cmd.CommandName { @@ -283,6 +284,6 @@ func (p *PlanCommandRunner) partitionProjectCmds( return } -func (p *PlanCommandRunner) isParallelEnabled(projectCmds []models.ProjectCommandContext) bool { +func (p *PlanCommandRunner) isParallelEnabled(projectCmds []project.Context) bool { return len(projectCmds) > 0 && projectCmds[0].ParallelPlanEnabled } diff --git a/server/events/policy_check_command_runner.go b/server/events/policy_check_command_runner.go index 830c8380c..6662c469f 100644 --- a/server/events/policy_check_command_runner.go +++ b/server/events/policy_check_command_runner.go @@ -2,6 +2,7 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -34,7 +35,7 @@ type PolicyCheckCommandRunner struct { silenceVCSStatusNoProjects bool } -func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []models.ProjectCommandContext) { +func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []project.Context) { if len(cmds) == 0 { ctx.Log.Info("no projects to run policy_check in") if !p.silenceVCSStatusNoProjects { @@ -89,6 +90,6 @@ func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *command.Context, pull } } -func (p *PolicyCheckCommandRunner) isParallelEnabled(cmds []models.ProjectCommandContext) bool { +func (p *PolicyCheckCommandRunner) isParallelEnabled(cmds []project.Context) bool { return len(cmds) > 0 && cmds[0].ParallelPolicyCheckEnabled } diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 07fb21b85..cbda6582c 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -119,30 +119,30 @@ func NewProjectCommandBuilderWithLimit( type ProjectPlanCommandBuilder interface { // BuildAutoplanCommands builds project commands that will run plan on // the projects determined to be modified. - BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) + BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) // BuildPlanCommands builds project plan commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) } type ProjectApplyCommandBuilder interface { // BuildApplyCommands builds project Apply commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) } type ProjectApprovePoliciesCommandBuilder interface { // BuildApprovePoliciesCommands builds project PolicyCheck commands for this ctx and comment. - BuildApprovePoliciesCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildApprovePoliciesCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) } type ProjectVersionCommandBuilder interface { // BuildVersionCommands builds project Version commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildVersionCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) + BuildVersionCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder @@ -174,12 +174,12 @@ type DefaultProjectCommandBuilder struct { } // See ProjectCommandBuilder.BuildAutoplanCommands. -func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { projCtxs, err := p.buildPlanAllCommands(ctx, nil, false, false) if err != nil { return nil, err } - var autoplanEnabled []models.ProjectCommandContext + var autoplanEnabled []project.Context for _, projCtx := range projCtxs { if !projCtx.AutoplanEnabled { ctx.Log.Debug("ignoring project at dir %q, workspace: %q because autoplan is disabled", projCtx.RepoRelDir, projCtx.Workspace) @@ -191,7 +191,7 @@ func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Contex } // See ProjectCommandBuilder.BuildPlanCommands. -func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { if !cmd.IsForSpecificProject() { return p.buildPlanAllCommands(ctx, cmd.Flags, cmd.Verbose, cmd.ForceApply) } @@ -200,7 +200,7 @@ func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, c } // See ProjectCommandBuilder.BuildApplyCommands. -func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -208,11 +208,11 @@ func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, return pac, err } -func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { return p.buildAllProjectCommands(ctx, cmd) } -func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -222,7 +222,7 @@ func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context // buildPlanAllCommands builds plan contexts for all projects we determine were // modified in this ctx. -func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context, commentFlags []string, verbose bool, forceApply bool) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context, commentFlags []string, verbose bool, forceApply bool) ([]project.Context, error) { // We'll need the list of modified files. modifiedFiles, err := p.VCSClient.GetModifiedFiles(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { @@ -249,7 +249,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context ctx.Log.Info("%d projects are changed on MR %q based on their when_modified config", len(matchingProjects), ctx.Pull.Num) if len(matchingProjects) == 0 { ctx.Log.Info("skipping repo clone since no project was modified") - return []models.ProjectCommandContext{}, nil + return []project.Context{}, nil } // NOTE: We discard this work here and end up doing it again after // cloning to ensure all the return values are set properly with @@ -279,7 +279,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context return nil, errors.Wrapf(err, "looking for %s file in %q", config.AtlantisYAMLFilename, repoDir) } - var projCtxs []models.ProjectCommandContext + var projCtxs []project.Context if hasRepoCfg { // If there's a repo cfg then we'll use it to figure out which projects @@ -354,13 +354,13 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context // buildProjectPlanCommand builds a plan context for a single project. // cmd must be for only one project. -func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var pcc []models.ProjectCommandContext + var pcc []project.Context ctx.Log.Debug("building plan command") unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { @@ -453,7 +453,7 @@ func (p *DefaultProjectCommandBuilder) getCfg(ctx *command.Context, projectName // buildAllProjectCommands builds contexts for a command for every project that has // pending plans in this ctx. -func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Context, commentCmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Context, commentCmd *CommentCommand) ([]project.Context, error) { // Lock all dirs in this pull request (instead of a single dir) because we // don't know how many dirs we'll need to run the command in. unlockFn, err := p.WorkingDirLocker.TryLockPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num) @@ -479,7 +479,7 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Cont return nil, err } - var cmds []models.ProjectCommandContext + var cmds []project.Context for _, plan := range plans { commentCmds, err := p.buildProjectCommandCtx(ctx, commentCmd.CommandName(), plan.ProjectName, commentCmd.Flags, defaultRepoDir, plan.RepoRelDir, plan.Workspace, commentCmd.Verbose, commentCmd.ForceApply) if err != nil { @@ -492,13 +492,13 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Cont // buildProjectApplyCommand builds an apply command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var projCtx []models.ProjectCommandContext + var projCtx []project.Context unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { return projCtx, err @@ -534,13 +534,13 @@ func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Con // buildProjectVersionCommand builds a version command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.Context, cmd *CommentCommand) ([]models.ProjectCommandContext, error) { +func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var projCtx []models.ProjectCommandContext + var projCtx []project.Context unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { return projCtx, err @@ -584,13 +584,13 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte repoRelDir string, workspace string, verbose bool, - forceApply bool) ([]models.ProjectCommandContext, error) { + forceApply bool) ([]project.Context, error) { matchingProjects, repoCfgPtr, err := p.getCfg(ctx, projectName, repoRelDir, workspace, repoDir) if err != nil { - return []models.ProjectCommandContext{}, err + return []project.Context{}, err } - var projCtxs []models.ProjectCommandContext + var projCtxs []project.Context var projCfg valid.MergedProjectCfg automerge := DefaultAutomergeEnabled parallelApply := DefaultParallelApplyEnabled @@ -652,7 +652,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte } if err := p.validateWorkspaceAllowed(repoCfgPtr, repoRelDir, workspace); err != nil { - return []models.ProjectCommandContext{}, err + return []project.Context{}, err } return projCtxs, nil diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index 5d2dc7aff..dd4e0f941 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -11,6 +11,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -39,7 +40,7 @@ func TestBuildProjectCmdCtx(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx models.ProjectCommandContext + expCtx project.Context expPlanSteps []string expApplySteps []string }{ @@ -60,7 +61,7 @@ workflows: steps: - apply`, repoCfg: "", - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -112,7 +113,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -166,7 +167,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -228,7 +229,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -377,7 +378,7 @@ workflows: steps: - apply `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -435,7 +436,7 @@ projects: terraform_version: v10.0 workflow: custom `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -496,7 +497,7 @@ workflows: apply: steps: [] `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -541,7 +542,7 @@ projects: - dir: project1 workspace: myworkspace `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -694,7 +695,7 @@ func TestBuildProjectCmdCtx_WithRegExpCmdEnabled(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx models.ProjectCommandContext + expCtx project.Context expPlanSteps []string expApplySteps []string }{ @@ -741,7 +742,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -p myproject_1", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -891,7 +892,7 @@ func TestBuildProjectCmdCtx_WithPolicCheckEnabled(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx models.ProjectCommandContext + expCtx project.Context expPolicyCheckSteps []string }{ // Test that if we've set global defaults and no project config @@ -902,7 +903,7 @@ repos: - id: /.*/ `, repoCfg: "", - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -959,7 +960,7 @@ workflows: steps: - policy_check `, - expCtx: models.ProjectCommandContext{ + expCtx: project.Context{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index a754cb15b..de72b7841 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -12,6 +12,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" @@ -431,7 +432,7 @@ projects: logger, ) - var actCtxs []models.ProjectCommandContext + var actCtxs []project.Context var err error if cmdName == command.Plan { actCtxs, err = builder.BuildPlanCommands(&command.Context{ @@ -841,7 +842,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { logger, ) - var actCtxs []models.ProjectCommandContext + var actCtxs []project.Context var err error actCtxs, err = builder.BuildPlanCommands(&command.Context{ Log: logger, @@ -1091,7 +1092,7 @@ projects: logger, ) - var actCtxs []models.ProjectCommandContext + var actCtxs []project.Context var err error actCtxs, err = builder.BuildAutoplanCommands(&command.Context{ HeadRepo: models.Repo{}, diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index ea0b21563..c8a66dc40 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-config-inspect/tfconfig" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/uber-go/tally" ) @@ -51,7 +52,7 @@ type ProjectCommandContextBuilder interface { commentFlags []string, repoDir string, contextFlags *ContextFlags, - ) []models.ProjectCommandContext + ) []project.Context } // CommandScopedStatsProjectCommandContextBuilder ensures that project command context contains a scoped stats @@ -70,14 +71,14 @@ func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []models.ProjectCommandContext) { +) (projectCmds []project.Context) { cb.ProjectCounter.Inc(1) cmds := cb.ProjectCommandContextBuilder.BuildProjectContext( ctx, cmdName, prjCfg, commentFlags, repoDir, contextFlags, ) - projectCmds = []models.ProjectCommandContext{} + projectCmds = []project.Context{} for _, cmd := range cmds { @@ -102,7 +103,7 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []models.ProjectCommandContext) { +) (projectCmds []project.Context) { ctx.Log.Debug("Building project command context for %s", cmdName) var steps []valid.Step @@ -156,7 +157,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []models.ProjectCommandContext) { +) (projectCmds []project.Context) { ctx.Log.Debug("PolicyChecks are enabled") // If TerraformVersion not defined in config file look for a @@ -211,7 +212,7 @@ func newProjectCommandContext(ctx *command.Context, contextFlags *ContextFlags, scope tally.Scope, pullStatus models.PullReqStatus, -) models.ProjectCommandContext { +) project.Context { var projectPlanStatus models.ProjectPlanStatus @@ -231,7 +232,7 @@ func newProjectCommandContext(ctx *command.Context, } } - return models.ProjectCommandContext{ + return project.Context{ CommandName: cmd, ApplyCmd: applyCmd, BaseRepo: ctx.Pull.BaseRepo, diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index 56f51e9c7..c55605df1 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -5,17 +5,17 @@ import ( "github.com/remeh/sizedwaitgroup" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -type prjCmdRunnerFunc func(ctx models.ProjectCommandContext) models.ProjectResult +type prjCmdRunnerFunc func(ctx project.Context) project.Result func runProjectCmdsParallel( - cmds []models.ProjectCommandContext, + cmds []project.Context, runnerFunc prjCmdRunnerFunc, poolSize int, ) command.Result { - var results []models.ProjectResult + var results []project.Result mux := &sync.Mutex{} wg := sizedwaitgroup.New(poolSize) @@ -40,10 +40,10 @@ func runProjectCmdsParallel( } func runProjectCmds( - cmds []models.ProjectCommandContext, + cmds []project.Context, runnerFunc prjCmdRunnerFunc, ) command.Result { - var results []models.ProjectResult + var results []project.Result for _, pCmd := range cmds { res := runnerFunc(pCmd) diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index ec6b04798..ec47a96be 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -23,6 +23,7 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/webhooks" "github.com/runatlantis/atlantis/server/logging" @@ -55,7 +56,7 @@ type LockURLGenerator interface { // `terraform plan`. type StepRunner interface { // Run runs the step. - Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) + Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_custom_step_runner.go CustomStepRunner @@ -63,14 +64,14 @@ type StepRunner interface { // CustomStepRunner runs custom run steps. type CustomStepRunner interface { // Run cmd in path. - Run(ctx models.ProjectCommandContext, cmd string, path string, envs map[string]string) (string, error) + Run(ctx project.Context, cmd string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_env_step_runner.go EnvStepRunner // EnvStepRunner runs env steps. type EnvStepRunner interface { - Run(ctx models.ProjectCommandContext, cmd string, value string, path string, envs map[string]string) (string, error) + Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_webhooks_sender.go WebhooksSender @@ -85,27 +86,27 @@ type WebhooksSender interface { type ProjectPlanCommandRunner interface { // Plan runs terraform plan for the project described by ctx. - Plan(ctx models.ProjectCommandContext) models.ProjectResult + Plan(ctx project.Context) project.Result } type ProjectApplyCommandRunner interface { // Apply runs terraform apply for the project described by ctx. - Apply(ctx models.ProjectCommandContext) models.ProjectResult + Apply(ctx project.Context) project.Result } type ProjectPolicyCheckCommandRunner interface { // PolicyCheck runs OPA defined policies for the project desribed by ctx. - PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult + PolicyCheck(ctx project.Context) project.Result } type ProjectApprovePoliciesCommandRunner interface { // Approves any failing OPA policies. - ApprovePolicies(ctx models.ProjectCommandContext) models.ProjectResult + ApprovePolicies(ctx project.Context) project.Result } type ProjectVersionCommandRunner interface { // Version runs terraform version for the project described by ctx. - Version(ctx models.ProjectCommandContext) models.ProjectResult + Version(ctx project.Context) project.Result } // ProjectCommandRunner runs project commands. A project command is a command @@ -123,7 +124,7 @@ type ProjectCommandRunner interface { type JobURLSetter interface { // SetJobURLWithStatus sets the commit status for the project represented by // ctx and updates the status with and url to a job. - SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus) error + SetJobURLWithStatus(ctx project.Context, cmdName command.Name, status models.CommitStatus) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_job_closer.go JobCloser @@ -141,19 +142,19 @@ type ProjectOutputWrapper struct { JobCloser JobCloser } -func (p *ProjectOutputWrapper) Plan(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *ProjectOutputWrapper) Plan(ctx project.Context) project.Result { result := p.updateProjectPRStatus(command.Plan, ctx, p.ProjectCommandRunner.Plan) p.JobCloser.CloseJob(ctx.JobID) return result } -func (p *ProjectOutputWrapper) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *ProjectOutputWrapper) Apply(ctx project.Context) project.Result { result := p.updateProjectPRStatus(command.Apply, ctx, p.ProjectCommandRunner.Apply) p.JobCloser.CloseJob(ctx.JobID) return result } -func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx models.ProjectCommandContext, execute func(ctx models.ProjectCommandContext) models.ProjectResult) models.ProjectResult { +func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx project.Context, execute func(ctx project.Context) project.Result) project.Result { // Create a PR status to track project's plan status. The status will // include a link to view the progress of atlantis plan command in real // time @@ -184,7 +185,7 @@ type FeatureAwareProjectCommandRunner struct { FeatureAllocator feature.Allocator } -func (f *FeatureAwareProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (f *FeatureAwareProjectCommandRunner) Apply(ctx project.Context) project.Result { return f.ProjectCommandRunner.Apply(ctx) } @@ -208,9 +209,9 @@ type DefaultProjectCommandRunner struct { //create object and test } // Plan runs terraform plan for the project described by ctx. -func (p *DefaultProjectCommandRunner) Plan(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *DefaultProjectCommandRunner) Plan(ctx project.Context) project.Result { planSuccess, failure, err := p.doPlan(ctx) - return models.ProjectResult{ + return project.Result{ Command: command.Plan, PlanSuccess: planSuccess, Error: err, @@ -222,9 +223,9 @@ func (p *DefaultProjectCommandRunner) Plan(ctx models.ProjectCommandContext) mod } // PolicyCheck evaluates policies defined with Rego for the project described by ctx. -func (p *DefaultProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *DefaultProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { policySuccess, failure, err := p.doPolicyCheck(ctx) - return models.ProjectResult{ + return project.Result{ Command: command.PolicyCheck, PolicyCheckSuccess: policySuccess, Error: err, @@ -236,9 +237,9 @@ func (p *DefaultProjectCommandRunner) PolicyCheck(ctx models.ProjectCommandConte } // Apply runs terraform apply for the project described by ctx. -func (p *DefaultProjectCommandRunner) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *DefaultProjectCommandRunner) Apply(ctx project.Context) project.Result { applyOut, failure, err := p.doApply(ctx) - return models.ProjectResult{ + return project.Result{ Command: command.Apply, Failure: failure, Error: err, @@ -249,9 +250,9 @@ func (p *DefaultProjectCommandRunner) Apply(ctx models.ProjectCommandContext) mo } } -func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx project.Context) project.Result { approvedOut, failure, err := p.doApprovePolicies(ctx) - return models.ProjectResult{ + return project.Result{ Command: command.PolicyCheck, Failure: failure, Error: err, @@ -262,9 +263,9 @@ func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx models.ProjectCommandC } } -func (p *DefaultProjectCommandRunner) Version(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *DefaultProjectCommandRunner) Version(ctx project.Context) project.Result { versionOut, failure, err := p.doVersion(ctx) - return models.ProjectResult{ + return project.Result{ Command: command.Version, Failure: failure, Error: err, @@ -275,7 +276,7 @@ func (p *DefaultProjectCommandRunner) Version(ctx models.ProjectCommandContext) } } -func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx models.ProjectCommandContext) (*models.PolicyCheckSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx project.Context) (*models.PolicyCheckSuccess, string, error) { // TODO: Make this a bit smarter // without checking some sort of state that the policy check has indeed passed this is likely to cause issues @@ -285,7 +286,7 @@ func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx models.ProjectComman }, "", nil } -func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx models.ProjectCommandContext) (*models.PolicyCheckSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx project.Context) (*models.PolicyCheckSuccess, string, error) { // Acquire Atlantis lock for this repo/dir/workspace. // This should already be acquired from the prior plan operation. // if for some reason an unlock happens between the plan and policy check step @@ -356,7 +357,7 @@ func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx models.ProjectCommandCon }, "", nil } -func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) (*models.PlanSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doPlan(ctx project.Context) (*models.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.Pull.BaseRepo.FullName, ctx.RepoRelDir)) if err != nil { @@ -405,7 +406,7 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx models.ProjectCommandContext) ( }, "", nil } -func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext) (applyOut string, failure string, err error) { +func (p *DefaultProjectCommandRunner) doApply(ctx project.Context) (applyOut string, failure string, err error) { repoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, ctx.Workspace) if err != nil { if os.IsNotExist(err) { @@ -449,7 +450,7 @@ func (p *DefaultProjectCommandRunner) doApply(ctx models.ProjectCommandContext) return strings.Join(outputs, "\n"), "", nil } -func (p *DefaultProjectCommandRunner) doVersion(ctx models.ProjectCommandContext) (versionOut string, failure string, err error) { +func (p *DefaultProjectCommandRunner) doVersion(ctx project.Context) (versionOut string, failure string, err error) { repoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, ctx.Workspace) if err != nil { if os.IsNotExist(err) { @@ -477,7 +478,7 @@ func (p *DefaultProjectCommandRunner) doVersion(ctx models.ProjectCommandContext return strings.Join(outputs, "\n"), "", nil } -func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx models.ProjectCommandContext, absPath string) ([]string, error) { +func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx project.Context, absPath string) ([]string, error) { var outputs []string envs := make(map[string]string) diff --git a/server/events/project_command_runner_test.go b/server/events/project_command_runner_test.go index c53da626e..0f12719e8 100644 --- a/server/events/project_command_runner_test.go +++ b/server/events/project_command_runner_test.go @@ -26,6 +26,7 @@ import ( tmocks "github.com/runatlantis/atlantis/server/core/terraform/mocks" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" eventmocks "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" @@ -83,7 +84,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) { expEnvs := map[string]string{ "name": "value", } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -134,7 +135,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) { func TestProjectOutputWrapper(t *testing.T) { RegisterMockTestingT(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -186,7 +187,7 @@ func TestProjectOutputWrapper(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - var prjResult models.ProjectResult + var prjResult project.Result var expCommitStatus models.CommitStatus mockJobURLSetter := eventmocks.NewMockJobURLSetter() @@ -200,18 +201,18 @@ func TestProjectOutputWrapper(t *testing.T) { } if c.Success { - prjResult = models.ProjectResult{ + prjResult = project.Result{ PlanSuccess: &models.PlanSuccess{}, ApplySuccess: "exists", } expCommitStatus = models.SuccessCommitStatus } else if c.Failure { - prjResult = models.ProjectResult{ + prjResult = project.Result{ Failure: "failure", } expCommitStatus = models.FailedCommitStatus } else if c.Error { - prjResult = models.ProjectResult{ + prjResult = project.Result{ Error: errors.New("error"), } expCommitStatus = models.FailedCommitStatus @@ -247,7 +248,7 @@ func TestDefaultProjectCommandRunner_ApplyNotCloned(t *testing.T) { runner := &events.DefaultProjectCommandRunner{ WorkingDir: mockWorkingDir, } - ctx := models.ProjectCommandContext{} + ctx := project.Context{} When(mockWorkingDir.GetWorkingDir(ctx.BaseRepo, ctx.Pull, ctx.Workspace)).ThenReturn("", os.ErrNotExist) res := runner.Apply(ctx) @@ -267,7 +268,7 @@ func TestDefaultProjectCommandRunner_ApplyNotApproved(t *testing.T) { }, Webhooks: mockSender, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ ApplyRequirements: []string{"approved"}, PullReqStatus: models.PullReqStatus{ ApprovalStatus: models.ApprovalStatus{ @@ -295,7 +296,7 @@ func TestDefaultProjectCommandRunner_ForceOverridesApplyReqs(t *testing.T) { }, Webhooks: mockSender, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ PullReqStatus: models.PullReqStatus{ ApprovalStatus: models.ApprovalStatus{ IsApproved: false, @@ -327,7 +328,7 @@ func TestFeatureAwareProjectCommandRunner_ForceOverrideWhenEnabled(t *testing.T) featureAwareRunner := &events.FeatureAwareProjectCommandRunner{ ProjectCommandRunner: runner, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ ApplyRequirements: []string{"approved"}, ForceApply: true, PullReqStatus: models.PullReqStatus{ @@ -356,7 +357,7 @@ func TestDefaultProjectCommandRunner_ApplyNotMergeable(t *testing.T) { WorkingDir: mockWorkingDir, }, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ PullReqStatus: models.PullReqStatus{ Mergeable: false, }, @@ -381,7 +382,7 @@ func TestDefaultProjectCommandRunner_ApplyDiverged(t *testing.T) { WorkingDir: mockWorkingDir, }, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ ApplyRequirements: []string{"undiverged"}, } tmp, cleanup := TempDir(t) @@ -507,7 +508,7 @@ func TestDefaultProjectCommandRunner_Apply(t *testing.T) { AnyString(), )).ThenReturn(repoDir, nil) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Steps: c.steps, Workspace: "default", @@ -579,7 +580,7 @@ func TestDefaultProjectCommandRunner_ApplyRunStepFailure(t *testing.T) { AnyString(), )).ThenReturn(repoDir, nil) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -648,7 +649,7 @@ func TestDefaultProjectCommandRunner_RunEnvSteps(t *testing.T) { LockKey: "lock-key", }, nil) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { diff --git a/server/events/pull_closed_executor_test.go b/server/events/pull_closed_executor_test.go index c9c3340b2..cae9e57c7 100644 --- a/server/events/pull_closed_executor_test.go +++ b/server/events/pull_closed_executor_test.go @@ -27,6 +27,7 @@ import ( . "github.com/petergtz/pegomock" lockmocks "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -201,7 +202,7 @@ func TestCleanUpLogStreaming(t *testing.T) { prjCmdOutput := make(chan *jobs.ProjectCmdOutputLine) storageBackend := jobmocks.NewMockStorageBackend() prjCmdOutHandler := jobs.NewAsyncProjectCommandOutputHandler(prjCmdOutput, logger, jobs.NewJobStore(storageBackend)) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ BaseRepo: fixtures.GithubRepo, Pull: fixtures.Pull, ProjectName: *fixtures.Project.Name, @@ -237,7 +238,7 @@ func TestCleanUpLogStreaming(t *testing.T) { panic(errors.Wrap(err, "could not create bucket")) } db, _ := db.NewWithDB(boltDB, lockBucket, configBucket) - result := []models.ProjectResult{ + result := []project.Result{ { RepoRelDir: fixtures.GithubRepo.FullName, Workspace: "default", diff --git a/server/events/pull_updater.go b/server/events/pull_updater.go index c91d2c7c2..34b68ada4 100644 --- a/server/events/pull_updater.go +++ b/server/events/pull_updater.go @@ -25,7 +25,7 @@ func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res // clutter in a pull/merge request. This will not delete the comment, since the // comment trail may be useful in auditing or backtracing problems. if c.HidePrevPlanComments { - if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, command.CommandName().TitleString()); err != nil { + if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, command.Name().TitleString()); err != nil { ctx.Log.Err("unable to hide old comments: %s", err) } } @@ -36,8 +36,8 @@ func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res templateOverrides = repoCfg.TemplateOverrides } - comment := c.MarkdownRenderer.Render(res, command.CommandName(), ctx.Log.GetHistory(), command.IsVerbose(), ctx.Pull.BaseRepo.VCSHost.Type, templateOverrides) - if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, comment, command.CommandName().String()); err != nil { + comment := c.MarkdownRenderer.Render(res, command.Name(), ctx.Log.GetHistory(), command.IsVerbose(), ctx.Pull.BaseRepo.VCSHost.Type, templateOverrides) + if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, comment, command.Name().String()); err != nil { ctx.Log.Err("unable to comment: %s", err) } } diff --git a/server/events/size_limited_project_command_builder.go b/server/events/size_limited_project_command_builder.go index c8d336723..af96c6f07 100644 --- a/server/events/size_limited_project_command_builder.go +++ b/server/events/size_limited_project_command_builder.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type SizeLimitedProjectCommandBuilder struct { @@ -13,7 +13,7 @@ type SizeLimitedProjectCommandBuilder struct { ProjectCommandBuilder } -func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { projects, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) if err != nil { @@ -23,7 +23,7 @@ func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Co return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]models.ProjectCommandContext, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { projects, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) if err != nil { @@ -33,9 +33,9 @@ func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Contex return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []models.ProjectCommandContext) error { +func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []project.Context) error { - var planCommands []models.ProjectCommandContext + var planCommands []project.Context for _, project := range projects { diff --git a/server/events/size_limited_project_command_builder_test.go b/server/events/size_limited_project_command_builder_test.go index 31765d5f7..77073498e 100644 --- a/server/events/size_limited_project_command_builder_test.go +++ b/server/events/size_limited_project_command_builder_test.go @@ -6,8 +6,8 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" - "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -18,22 +18,22 @@ func TestSizeLimitedProjectCommandBuilder_autoplan(t *testing.T) { ctx := &command.Context{} - project1 := models.ProjectCommandContext{ + project1 := project.Context{ ProjectName: "test1", CommandName: command.Plan, } - project2 := models.ProjectCommandContext{ + project2 := project.Context{ ProjectName: "test2", CommandName: command.Plan, } - project3 := models.ProjectCommandContext{ + project3 := project.Context{ ProjectName: "test1", CommandName: command.PolicyCheck, } - expectedResult := []models.ProjectCommandContext{project1, project2} + expectedResult := []project.Context{project1, project2} t.Run("Limit Defined and Breached", func(t *testing.T) { subject := &events.SizeLimitedProjectCommandBuilder{ @@ -88,7 +88,7 @@ Please break this pull request into smaller batches and try again.`, err) ProjectCommandBuilder: delegate, } - resultWithPolicyCheckCommand := []models.ProjectCommandContext{project1, project2, project3} + resultWithPolicyCheckCommand := []project.Context{project1, project2, project3} When(delegate.BuildAutoplanCommands(ctx)).ThenReturn(resultWithPolicyCheckCommand, nil) @@ -109,17 +109,17 @@ func TestSizeLimitedProjectCommandBuilder_planComment(t *testing.T) { comment := &events.CommentCommand{} - project1 := models.ProjectCommandContext{ + project1 := project.Context{ ProjectName: "test1", CommandName: command.Plan, } - project2 := models.ProjectCommandContext{ + project2 := project.Context{ ProjectName: "test2", CommandName: command.Plan, } - expectedResult := []models.ProjectCommandContext{project1, project2} + expectedResult := []project.Context{project1, project2} t.Run("Limit Defined and Breached", func(t *testing.T) { subject := &events.SizeLimitedProjectCommandBuilder{ diff --git a/server/events/version_command_runner.go b/server/events/version_command_runner.go index 1fa6377e4..20c973b13 100644 --- a/server/events/version_command_runner.go +++ b/server/events/version_command_runner.go @@ -2,7 +2,7 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) func NewVersionCommandRunner( @@ -33,7 +33,7 @@ type VersionCommandRunner struct { func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { var err error - var projectCmds []models.ProjectCommandContext + var projectCmds []project.Context projectCmds, err = v.prjCmdBuilder.BuildVersionCommands(ctx, cmd) if err != nil { ctx.Log.Warn("Error %s", err) @@ -56,6 +56,6 @@ func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { v.pullUpdater.updatePull(ctx, cmd, result) } -func (v *VersionCommandRunner) isParallelEnabled(cmds []models.ProjectCommandContext) bool { +func (v *VersionCommandRunner) isParallelEnabled(cmds []project.Context) bool { return len(cmds) > 0 && cmds[0].ParallelPolicyCheckEnabled } diff --git a/server/jobs/job_url_setter.go b/server/jobs/job_url_setter.go index 1ae6eba2a..2eba7ff66 100644 --- a/server/jobs/job_url_setter.go +++ b/server/jobs/job_url_setter.go @@ -2,6 +2,7 @@ package jobs import ( "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -9,7 +10,7 @@ import ( // ProjectJobURLGenerator generates urls to view project's progress. type ProjectJobURLGenerator interface { - GenerateProjectJobURL(p models.ProjectCommandContext) (string, error) + GenerateProjectJobURL(p project.Context) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_status_updater.go ProjectStatusUpdater @@ -17,7 +18,7 @@ type ProjectJobURLGenerator interface { type ProjectStatusUpdater interface { // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error } type JobURLSetter struct { @@ -32,7 +33,7 @@ func NewJobURLSetter(projectJobURLGenerator ProjectJobURLGenerator, projectStatu } } -func (j *JobURLSetter) SetJobURLWithStatus(ctx models.ProjectCommandContext, cmdName command.Name, status models.CommitStatus) error { +func (j *JobURLSetter) SetJobURLWithStatus(ctx project.Context, cmdName command.Name, status models.CommitStatus) error { url, err := j.projectJobURLGenerator.GenerateProjectJobURL(ctx) if err != nil { diff --git a/server/jobs/mocks/matchers/models_projectcommandcontext.go b/server/jobs/mocks/matchers/models_projectcommandcontext.go index 8972dd412..93d072cb5 100644 --- a/server/jobs/mocks/matchers/models_projectcommandcontext.go +++ b/server/jobs/mocks/matchers/models_projectcommandcontext.go @@ -5,30 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) -func AnyModelsProjectCommandContext() models.ProjectCommandContext { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.ProjectCommandContext))(nil)).Elem())) - var nullValue models.ProjectCommandContext +func AnyModelsProjectCommandContext() project.Context { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) + var nullValue project.Context return nullValue } -func EqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func EqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func NotEqModelsProjectCommandContext(value models.ProjectCommandContext) models.ProjectCommandContext { +func NotEqModelsProjectCommandContext(value project.Context) project.Context { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) models.ProjectCommandContext { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { pegomock.RegisterMatcher(matcher) - var nullValue models.ProjectCommandContext + var nullValue project.Context return nullValue } diff --git a/server/jobs/mocks/mock_project_command_output_handler.go b/server/jobs/mocks/mock_project_command_output_handler.go index 967d159d0..9be526169 100644 --- a/server/jobs/mocks/mock_project_command_output_handler.go +++ b/server/jobs/mocks/mock_project_command_output_handler.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" jobs "github.com/runatlantis/atlantis/server/jobs" ) @@ -59,7 +59,7 @@ func (mock *MockProjectCommandOutputHandler) Register(_param0 string, _param1 ch pegomock.GetGenericMockFrom(mock).Invoke("Register", params, []reflect.Type{}) } -func (mock *MockProjectCommandOutputHandler) Send(_param0 models.ProjectCommandContext, _param1 string) { +func (mock *MockProjectCommandOutputHandler) Send(_param0 project.Context, _param1 string) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandOutputHandler().") } @@ -206,7 +206,7 @@ func (c *MockProjectCommandOutputHandler_Register_OngoingVerification) GetAllCap return } -func (verifier *VerifierMockProjectCommandOutputHandler) Send(_param0 models.ProjectCommandContext, _param1 string) *MockProjectCommandOutputHandler_Send_OngoingVerification { +func (verifier *VerifierMockProjectCommandOutputHandler) Send(_param0 project.Context, _param1 string) *MockProjectCommandOutputHandler_Send_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) return &MockProjectCommandOutputHandler_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -217,17 +217,17 @@ type MockProjectCommandOutputHandler_Send_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, string) { +func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetCapturedArguments() (project.Context, string) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string) { +func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/jobs/mocks/mock_project_job_url_generator.go b/server/jobs/mocks/mock_project_job_url_generator.go index 6f365d6cf..073b3da00 100644 --- a/server/jobs/mocks/mock_project_job_url_generator.go +++ b/server/jobs/mocks/mock_project_job_url_generator.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) type MockProjectJobURLGenerator struct { @@ -26,7 +26,7 @@ func NewMockProjectJobURLGenerator(options ...pegomock.Option) *MockProjectJobUR func (mock *MockProjectJobURLGenerator) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectJobURLGenerator) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectJobURLGenerator) GenerateProjectJobURL(_param0 models.ProjectCommandContext) (string, error) { +func (mock *MockProjectJobURLGenerator) GenerateProjectJobURL(_param0 project.Context) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectJobURLGenerator().") } @@ -82,7 +82,7 @@ type VerifierMockProjectJobURLGenerator struct { timeout time.Duration } -func (verifier *VerifierMockProjectJobURLGenerator) GenerateProjectJobURL(_param0 models.ProjectCommandContext) *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification { +func (verifier *VerifierMockProjectJobURLGenerator) GenerateProjectJobURL(_param0 project.Context) *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification { params := []pegomock.Param{_param0} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateProjectJobURL", params, verifier.timeout) return &MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification struct methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetCapturedArguments() models.ProjectCommandContext { +func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetCapturedArguments() project.Context { _param0 := c.GetAllCapturedArguments() return _param0[len(_param0)-1] } -func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext) { +func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } } return diff --git a/server/jobs/mocks/mock_project_status_updater.go b/server/jobs/mocks/mock_project_status_updater.go index 792126aa0..7167ebe15 100644 --- a/server/jobs/mocks/mock_project_status_updater.go +++ b/server/jobs/mocks/mock_project_status_updater.go @@ -9,6 +9,7 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -27,7 +28,7 @@ func NewMockProjectStatusUpdater(options ...pegomock.Option) *MockProjectStatusU func (mock *MockProjectStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) error { +func (mock *MockProjectStatusUpdater) UpdateProject(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus, _param3 string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectStatusUpdater().") } @@ -79,7 +80,7 @@ type VerifierMockProjectStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 models.ProjectCommandContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2, _param3} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockProjectStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -90,17 +91,17 @@ type MockProjectStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (models.ProjectCommandContext, command.Name, models.CommitStatus, string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus, string) { _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]models.ProjectCommandContext, len(c.methodInvocations)) + _param0 = make([]project.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(models.ProjectCommandContext) + _param0[u] = param.(project.Context) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/jobs/project_command_output_handler.go b/server/jobs/project_command_output_handler.go index 49fb9c463..22d03405d 100644 --- a/server/jobs/project_command_output_handler.go +++ b/server/jobs/project_command_output_handler.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/logging" ) @@ -35,7 +35,7 @@ type ProjectCmdOutputLine struct { type ProjectCommandOutputHandler interface { // Send will enqueue the msg and wait for Handle() to receive the message. - Send(ctx models.ProjectCommandContext, msg string) + Send(ctx project.Context, msg string) // Listens for msg from channel Handle() @@ -82,7 +82,7 @@ func NewAsyncProjectCommandOutputHandler( } } -func (p *AsyncProjectCommandOutputHandler) Send(ctx models.ProjectCommandContext, msg string) { +func (p *AsyncProjectCommandOutputHandler) Send(ctx project.Context, msg string) { p.projectCmdOutput <- &ProjectCmdOutputLine{ JobID: ctx.JobID, JobInfo: JobInfo{ @@ -191,7 +191,7 @@ func (p *AsyncProjectCommandOutputHandler) GetJobIdMapForPull(pullInfo PullInfo) // NoopProjectOutputHandler is a mock that doesn't do anything type NoopProjectOutputHandler struct{} -func (p *NoopProjectOutputHandler) Send(ctx models.ProjectCommandContext, msg string) { +func (p *NoopProjectOutputHandler) Send(ctx project.Context, msg string) { } func (p *NoopProjectOutputHandler) Handle() { diff --git a/server/jobs/project_command_output_handler_test.go b/server/jobs/project_command_output_handler_test.go index e9c1d89d6..c61114b5c 100644 --- a/server/jobs/project_command_output_handler_test.go +++ b/server/jobs/project_command_output_handler_test.go @@ -8,6 +8,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/stretchr/testify/assert" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/jobs" "github.com/runatlantis/atlantis/server/jobs/mocks" @@ -16,9 +17,9 @@ import ( . "github.com/runatlantis/atlantis/testing" ) -func createTestProjectCmdContext(t *testing.T) models.ProjectCommandContext { +func createTestProjectCmdContext(t *testing.T) project.Context { logger := logging.NewNoopLogger(t) - return models.ProjectCommandContext{ + return project.Context{ BaseRepo: models.Repo{ Name: "test-repo", Owner: "test-org", diff --git a/server/lyft/decorators/audit_project_commands_wrapper.go b/server/lyft/decorators/audit_project_commands_wrapper.go index 72918bc91..313748197 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper.go +++ b/server/lyft/decorators/audit_project_commands_wrapper.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/lyft/aws/sns" ) @@ -38,7 +38,7 @@ type AuditProjectCommandWrapper struct { events.ProjectCommandRunner } -func (p *AuditProjectCommandWrapper) Apply(ctx models.ProjectCommandContext) models.ProjectResult { +func (p *AuditProjectCommandWrapper) Apply(ctx project.Context) project.Result { id := uuid.New() startTime := strconv.FormatInt(time.Now().Unix(), 10) @@ -59,7 +59,7 @@ func (p *AuditProjectCommandWrapper) Apply(ctx models.ProjectCommandContext) mod if err := p.emit(ctx, AtlantisJobStateRunning, atlantisJobEvent); err != nil { // return an error if we are not able to write to sns - return models.ProjectResult{ + return project.Result{ Error: errors.Wrap(err, "emitting atlantis job event"), } } @@ -82,7 +82,7 @@ func (p *AuditProjectCommandWrapper) Apply(ctx models.ProjectCommandContext) mod } func (p *AuditProjectCommandWrapper) emit( - ctx models.ProjectCommandContext, + ctx project.Context, state AtlantisJobState, atlantisJobEvent *AtlantisJobEvent, ) error { diff --git a/server/lyft/decorators/audit_project_commands_wrapper_test.go b/server/lyft/decorators/audit_project_commands_wrapper_test.go index cccb76d9b..dfde97bbe 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper_test.go +++ b/server/lyft/decorators/audit_project_commands_wrapper_test.go @@ -9,6 +9,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config/valid" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -50,7 +51,7 @@ func TestAuditProjectCommandsWrapper(t *testing.T) { ProjectCommandRunner: projectCmdRunnerMock, } - prjRslt := models.ProjectResult{} + prjRslt := project.Result{} if c.Error { prjRslt.Error = errors.New("oh-no") @@ -64,7 +65,7 @@ func TestAuditProjectCommandsWrapper(t *testing.T) { scope, _, _ := metrics.NewLoggingScope(logger, "atlantis") - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Scope: scope, Log: logger, Steps: []valid.Step{}, diff --git a/server/lyft/decorators/destroy_plan_step_runner_wrapper.go b/server/lyft/decorators/destroy_plan_step_runner_wrapper.go index 1db1da8c2..a628875d7 100644 --- a/server/lyft/decorators/destroy_plan_step_runner_wrapper.go +++ b/server/lyft/decorators/destroy_plan_step_runner_wrapper.go @@ -2,7 +2,7 @@ package decorators import ( "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) const Deprecated = "deprecated" @@ -12,7 +12,7 @@ type DestroyPlanStepRunnerWrapper struct { events.StepRunner } -func (d *DestroyPlanStepRunnerWrapper) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { +func (d *DestroyPlanStepRunnerWrapper) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { // DestroyPlan tag is true when the Terraform client should construct a destroy plan given a repo config. if ctx.Tags[Deprecated] == Destroy { extraArgs = append(extraArgs, Destroy) diff --git a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go index 76d0ab66b..972ba5f8a 100644 --- a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go +++ b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go @@ -10,6 +10,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" "github.com/runatlantis/atlantis/server/lyft/decorators" @@ -100,7 +101,7 @@ func TestRun_DestroyPlan(t *testing.T) { stepRunner := decorators.DestroyPlanStepRunnerWrapper{ StepRunner: &planStepRunner, } - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Log: logger, Workspace: "workspace", RepoRelDir: ".", diff --git a/server/router.go b/server/router.go index 58e2d800a..538f11572 100644 --- a/server/router.go +++ b/server/router.go @@ -6,7 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command/project" ) // Router can be used to retrieve Atlantis URLs. It acts as an intermediary @@ -39,7 +39,7 @@ func (r *Router) GenerateLockURL(lockID string) string { return r.AtlantisURL.String() + lockURL.String() } -func (r *Router) GenerateProjectJobURL(ctx models.ProjectCommandContext) (string, error) { +func (r *Router) GenerateProjectJobURL(ctx project.Context) (string, error) { if ctx.JobID == "" { return "", fmt.Errorf("no job id in ctx") } diff --git a/server/router_test.go b/server/router_test.go index f5af05084..371c42fc2 100644 --- a/server/router_test.go +++ b/server/router_test.go @@ -8,6 +8,7 @@ import ( "github.com/google/uuid" "github.com/gorilla/mux" "github.com/runatlantis/atlantis/server" + "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" "github.com/stretchr/testify/assert" @@ -82,7 +83,7 @@ func setupJobsRouter(t *testing.T) *server.Router { func TestGenerateProjectJobURL_ShouldGenerateURLWhenJobIDSpecified(t *testing.T) { router := setupJobsRouter(t) jobID := uuid.New().String() - ctx := models.ProjectCommandContext{ + ctx := project.Context{ JobID: jobID, } expectedURL := fmt.Sprintf("http://localhost:4141/jobs/%s", jobID) @@ -94,7 +95,7 @@ func TestGenerateProjectJobURL_ShouldGenerateURLWhenJobIDSpecified(t *testing.T) func TestGenerateProjectJobURL_ShouldReturnErrorWhenJobIDNotSpecified(t *testing.T) { router := setupJobsRouter(t) - ctx := models.ProjectCommandContext{ + ctx := project.Context{ Pull: models.PullRequest{ BaseRepo: models.Repo{ Owner: "test-owner", From 482d680932a8c9ff1bc191640dc32f93b435f3ec Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Thu, 24 Feb 2022 17:07:14 -0800 Subject: [PATCH 5/7] move project command context and project result --- CONTRIBUTING.md | 2 +- .../events/events_controller_e2e_test.go | 3 +- server/controllers/locks_controller_test.go | 3 +- server/core/db/boltdb.go | 15 ++- server/core/db/boltdb_test.go | 14 +-- server/core/locking/locking.go | 4 +- server/core/locking/locking_test.go | 4 +- .../mocks/matchers/models_commandlock.go | 12 +- .../matchers/ptr_to_models_commandlock.go | 20 +-- server/core/locking/mocks/mock_backend.go | 16 +-- server/core/runtime/apply_step_runner.go | 7 +- server/core/runtime/apply_step_runner_test.go | 21 ++-- server/core/runtime/env_step_runner.go | 4 +- server/core/runtime/env_step_runner_test.go | 4 +- server/core/runtime/executor.go | 4 +- server/core/runtime/init_step_runner.go | 4 +- server/core/runtime/init_step_runner_test.go | 18 +-- .../minimum_version_step_runner_delegate.go | 4 +- ...nimum_version_step_runner_delegate_test.go | 10 +- .../matchers/models_projectcommandcontext.go | 20 +-- server/core/runtime/mocks/mock_runner.go | 14 +-- .../mocks/mock_versionedexecutorworkflow.go | 14 +-- server/core/runtime/plan_step_runner.go | 13 +- server/core/runtime/plan_step_runner_test.go | 27 ++-- .../runtime/plan_type_step_runner_delegate.go | 8 +- .../plan_type_step_runner_delegate_test.go | 10 +- server/core/runtime/policy/conftest_client.go | 4 +- .../runtime/policy/conftest_client_test.go | 4 +- .../core/runtime/policy_check_step_runner.go | 4 +- .../runtime/policy_check_step_runner_test.go | 4 +- server/core/runtime/run_step_runner.go | 4 +- server/core/runtime/run_step_runner_test.go | 4 +- server/core/runtime/runtime.go | 11 +- server/core/runtime/show_step_runner.go | 4 +- server/core/runtime/show_step_runner_test.go | 6 +- server/core/runtime/version_step_runner.go | 4 +- .../core/runtime/version_step_runner_test.go | 4 +- server/core/terraform/async_client.go | 6 +- server/core/terraform/async_client_test.go | 12 +- .../matchers/models_projectcommandcontext.go | 20 +-- .../terraform/mocks/mock_terraform_client.go | 15 ++- server/core/terraform/terraform_client.go | 6 +- .../terraform_client_internal_test.go | 6 +- .../core/terraform/terraform_client_test.go | 6 +- server/events/apply_command_runner.go | 5 +- server/events/apply_command_runner_test.go | 2 +- server/events/apply_requirement_handler.go | 6 +- .../events/approve_policies_command_runner.go | 5 +- server/events/automerger.go | 5 +- server/events/command/context.go | 4 +- server/events/command/lock.go | 26 ++++ .../context.go => project_context.go} | 17 ++- .../{project/result.go => project_result.go} | 28 +++-- server/events/command/result.go | 4 +- server/events/command/result_test.go | 15 ++- server/events/command_runner.go | 4 +- server/events/command_runner_internal_test.go | 3 +- server/events/command_runner_test.go | 40 +++--- server/events/comment_parser.go | 38 +++--- server/events/commit_status_updater.go | 5 +- server/events/commit_status_updater_test.go | 7 +- server/events/db_updater.go | 5 +- .../instrumented_project_command_builder.go | 7 +- .../instrumented_project_command_runner.go | 10 +- server/events/markdown_renderer.go | 3 +- server/events/markdown_renderer_test.go | 119 +++++++++--------- .../matchers/models_projectcommandcontext.go | 20 +-- .../mocks/matchers/models_projectresult.go | 20 +-- .../slice_of_models_projectcommandcontext.go | 20 +-- server/events/mocks/mock_apply_handler.go | 14 +-- .../mocks/mock_commit_status_updater.go | 19 ++- .../events/mocks/mock_custom_step_runner.go | 14 +-- server/events/mocks/mock_env_step_runner.go | 14 +-- .../events/mocks/mock_job_message_sender.go | 14 +-- server/events/mocks/mock_job_url_setter.go | 13 +- .../mocks/mock_log_stream_url_generator.go | 14 +-- ...mock_pre_workflows_hooks_command_runner.go | 14 +-- .../mocks/mock_project_command_builder.go | 41 +++--- .../mocks/mock_project_command_runner.go | 92 +++++++------- server/events/mocks/mock_step_runner.go | 14 +-- server/events/models/models.go | 22 ---- server/events/models/models_test.go | 50 ++++---- server/events/plan_command_runner.go | 11 +- server/events/policy_check_command_runner.go | 5 +- server/events/project_command_builder.go | 53 ++++---- .../project_command_builder_internal_test.go | 29 +++-- server/events/project_command_builder_test.go | 7 +- .../events/project_command_context_builder.go | 15 ++- .../events/project_command_pool_executor.go | 11 +- server/events/project_command_runner.go | 59 +++++---- server/events/project_command_runner_test.go | 31 +++-- server/events/pull_closed_executor_test.go | 6 +- server/events/pull_updater.go | 8 +- .../size_limited_project_command_builder.go | 9 +- ...ze_limited_project_command_builder_test.go | 17 ++- server/events/unlock_command_runner.go | 2 +- server/events/version_command_runner.go | 5 +- server/jobs/job_url_setter.go | 7 +- .../matchers/models_projectcommandcontext.go | 20 +-- .../mock_project_command_output_handler.go | 14 +-- .../mocks/mock_project_job_url_generator.go | 14 +-- .../jobs/mocks/mock_project_status_updater.go | 13 +- server/jobs/project_command_output_handler.go | 8 +- .../project_command_output_handler_test.go | 6 +- .../audit_project_commands_wrapper.go | 8 +- .../audit_project_commands_wrapper_test.go | 6 +- .../destroy_plan_step_runner_wrapper.go | 4 +- .../destroy_plan_step_runner_wrapper_test.go | 4 +- server/router.go | 4 +- server/router_test.go | 6 +- server/server.go | 14 +-- 111 files changed, 758 insertions(+), 790 deletions(-) create mode 100644 server/events/command/lock.go rename server/events/command/{project/context.go => project_context.go} (93%) rename server/events/command/{project/result.go => project_result.go} (63%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99ab6a993..bb536bf4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -160,7 +160,7 @@ Each interface that is mocked has a `go:generate` command above it, e.g. //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder type ProjectCommandBuilder interface { - BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) + BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) } ``` diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index 5c5d544c4..b088576d3 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -29,6 +29,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/policy" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -1054,7 +1055,7 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl command.Plan: planCommandRunner, command.Apply: applyCommandRunner, command.ApprovePolicies: approvePoliciesCommandRunner, - command.UnlockCommand: unlockCommandRunner, + command.Unlock: unlockCommandRunner, command.Version: versionCommandRunner, } staleCommandChecker := mocks.NewMockStaleCommandChecker() diff --git a/server/controllers/locks_controller_test.go b/server/controllers/locks_controller_test.go index 63a1099a5..01dddf6dd 100644 --- a/server/controllers/locks_controller_test.go +++ b/server/controllers/locks_controller_test.go @@ -23,7 +23,6 @@ import ( "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -304,7 +303,7 @@ func TestDeleteLock_UpdateProjectStatus(t *testing.T) { db, err := db.New(tmp) Ok(t, err) // Seed the DB with a successful plan for that project (that is later discarded). - _, err = db.UpdatePullWithResults(pull, []project.Result{ + _, err = db.UpdatePullWithResults(pull, []command.ProjectResult{ { Command: command.Plan, RepoRelDir: projectPath, diff --git a/server/core/db/boltdb.go b/server/core/db/boltdb.go index 5abff70ae..48c115755 100644 --- a/server/core/db/boltdb.go +++ b/server/core/db/boltdb.go @@ -12,7 +12,6 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" bolt "go.etcd.io/bbolt" ) @@ -175,10 +174,10 @@ func (b *BoltDB) List() ([]models.ProjectLock, error) { // LockCommand attempts to create a new lock for a CommandName. // If the lock doesn't exists, it will create a lock and return a pointer to it. // If the lock already exists, it will return an "lock already exists" error -func (b *BoltDB) LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) { - lock := models.CommandLock{ +func (b *BoltDB) LockCommand(cmdName command.Name, lockTime time.Time) (*command.Lock, error) { + lock := command.Lock{ CommandName: cmdName, - LockMetadata: models.LockMetadata{ + LockMetadata: command.LockMetadata{ UnixTime: lockTime.Unix(), }, } @@ -226,8 +225,8 @@ func (b *BoltDB) UnlockCommand(cmdName command.Name) error { // CheckCommandLock checks if CommandName lock was set. // If the lock exists return the pointer to the lock object, otherwise return nil -func (b *BoltDB) CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) { - cmdLock := models.CommandLock{} +func (b *BoltDB) CheckCommandLock(cmdName command.Name) (*command.Lock, error) { + cmdLock := command.Lock{} found := false @@ -314,7 +313,7 @@ func (b *BoltDB) GetLock(p models.Project, workspace string) (*models.ProjectLoc // UpdatePullWithResults updates pull's status with the latest project results. // It returns the new PullStatus object. -func (b *BoltDB) UpdatePullWithResults(pull models.PullRequest, newResults []project.Result) (models.PullStatus, error) { +func (b *BoltDB) UpdatePullWithResults(pull models.PullRequest, newResults []command.ProjectResult) (models.PullStatus, error) { key, err := b.pullKey(pull) if err != nil { return models.PullStatus{}, err @@ -484,7 +483,7 @@ func (b *BoltDB) writePullToBucket(bucket *bolt.Bucket, key []byte, pull models. return bucket.Put(key, serialized) } -func (b *BoltDB) projectResultToProject(p project.Result) models.ProjectStatus { +func (b *BoltDB) projectResultToProject(p command.ProjectResult) models.ProjectStatus { return models.ProjectStatus{ Workspace: p.Workspace, RepoRelDir: p.RepoRelDir, diff --git a/server/core/db/boltdb_test.go b/server/core/db/boltdb_test.go index c3c98255d..c8600489c 100644 --- a/server/core/db/boltdb_test.go +++ b/server/core/db/boltdb_test.go @@ -458,7 +458,7 @@ func TestPullStatus_UpdateGet(t *testing.T) { } status, err := b.UpdatePullWithResults( pull, - []project.Result{ + []command.ProjectResult{ { Command: command.Plan, RepoRelDir: ".", @@ -510,7 +510,7 @@ func TestPullStatus_UpdateDeleteGet(t *testing.T) { } _, err := b.UpdatePullWithResults( pull, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: ".", Workspace: "default", @@ -556,7 +556,7 @@ func TestPullStatus_UpdateProject(t *testing.T) { } _, err := b.UpdatePullWithResults( pull, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: ".", Workspace: "default", @@ -621,7 +621,7 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { } initialStatus, err := b.UpdatePullWithResults( pull, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: ".", Workspace: "default", @@ -635,7 +635,7 @@ func TestPullStatus_UpdateNewCommit(t *testing.T) { pull.HeadCommit = "newsha" status, err := b.UpdatePullWithResults(pull, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -688,7 +688,7 @@ func TestPullStatus_UpdateMerge(t *testing.T) { } initialStatus, err := b.UpdatePullWithResults( pull, - []project.Result{ + []command.ProjectResult{ { Command: command.Plan, RepoRelDir: "mergeme", @@ -720,7 +720,7 @@ func TestPullStatus_UpdateMerge(t *testing.T) { time.Sleep(1 * time.Second) updateStatus, err := b.UpdatePullWithResults(pull, - []project.Result{ + []command.ProjectResult{ { Command: command.Apply, RepoRelDir: "mergeme", diff --git a/server/core/locking/locking.go b/server/core/locking/locking.go index 7b92bcef7..2abb0a4dc 100644 --- a/server/core/locking/locking.go +++ b/server/core/locking/locking.go @@ -34,9 +34,9 @@ type Backend interface { GetLock(project models.Project, workspace string) (*models.ProjectLock, error) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error) - LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) + LockCommand(cmdName command.Name, lockTime time.Time) (*command.Lock, error) UnlockCommand(cmdName command.Name) error - CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) + CheckCommandLock(cmdName command.Name) (*command.Lock, error) } // TryLockResponse results from an attempted lock. diff --git a/server/core/locking/locking_test.go b/server/core/locking/locking_test.go index 1d2f7303c..2fe123da8 100644 --- a/server/core/locking/locking_test.go +++ b/server/core/locking/locking_test.go @@ -185,9 +185,9 @@ func TestGetLock_NoOpLocker(t *testing.T) { func TestApplyLocker(t *testing.T) { RegisterMockTestingT(t) - applyLock := &models.CommandLock{ + applyLock := &command.Lock{ CommandName: command.Apply, - LockMetadata: models.LockMetadata{ + LockMetadata: command.LockMetadata{ UnixTime: time.Now().Unix(), }, } diff --git a/server/core/locking/mocks/matchers/models_commandlock.go b/server/core/locking/mocks/matchers/models_commandlock.go index 212dcafb1..c4078950a 100644 --- a/server/core/locking/mocks/matchers/models_commandlock.go +++ b/server/core/locking/mocks/matchers/models_commandlock.go @@ -5,17 +5,17 @@ import ( "reflect" "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + command "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsCommandLock() models.CommandLock { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(models.CommandLock))(nil)).Elem())) - var nullValue models.CommandLock +func AnyModelsCommandLock() command.Lock { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.Lock))(nil)).Elem())) + var nullValue command.Lock return nullValue } -func EqModelsCommandLock(value models.CommandLock) models.CommandLock { +func EqModelsCommandLock(value command.Lock) command.Lock { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue models.CommandLock + var nullValue command.Lock return nullValue } diff --git a/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go b/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go index 962a3b7df..b4785494b 100644 --- a/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go +++ b/server/core/locking/mocks/matchers/ptr_to_models_commandlock.go @@ -6,29 +6,29 @@ import ( "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + command "github.com/runatlantis/atlantis/server/events/command" ) -func AnyPtrToModelsCommandLock() *models.CommandLock { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*models.CommandLock))(nil)).Elem())) - var nullValue *models.CommandLock +func AnyPtrToModelsCommandLock() *command.Lock { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(*command.Lock))(nil)).Elem())) + var nullValue *command.Lock return nullValue } -func EqPtrToModelsCommandLock(value *models.CommandLock) *models.CommandLock { +func EqPtrToModelsCommandLock(value *command.Lock) *command.Lock { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue *models.CommandLock + var nullValue *command.Lock return nullValue } -func NotEqPtrToModelsCommandLock(value *models.CommandLock) *models.CommandLock { +func NotEqPtrToModelsCommandLock(value *command.Lock) *command.Lock { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue *models.CommandLock + var nullValue *command.Lock return nullValue } -func PtrToModelsCommandLockThat(matcher pegomock.ArgumentMatcher) *models.CommandLock { +func PtrToModelsCommandLockThat(matcher pegomock.ArgumentMatcher) *command.Lock { pegomock.RegisterMatcher(matcher) - var nullValue *models.CommandLock + var nullValue *command.Lock return nullValue } diff --git a/server/core/locking/mocks/mock_backend.go b/server/core/locking/mocks/mock_backend.go index b86550ec8..edfb55055 100644 --- a/server/core/locking/mocks/mock_backend.go +++ b/server/core/locking/mocks/mock_backend.go @@ -126,17 +126,17 @@ func (mock *MockBackend) UnlockByPull(repoFullName string, pullNum int) ([]model return ret0, ret1 } -func (mock *MockBackend) LockCommand(cmdName command.Name, lockTime time.Time) (*models.CommandLock, error) { +func (mock *MockBackend) LockCommand(cmdName command.Name, lockTime time.Time) (*command.Lock, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockBackend().") } params := []pegomock.Param{cmdName, lockTime} - result := pegomock.GetGenericMockFrom(mock).Invoke("LockCommand", params, []reflect.Type{reflect.TypeOf((**models.CommandLock)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *models.CommandLock + result := pegomock.GetGenericMockFrom(mock).Invoke("LockCommand", params, []reflect.Type{reflect.TypeOf((**command.Lock)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *command.Lock var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(*models.CommandLock) + ret0 = result[0].(*command.Lock) } if result[1] != nil { ret1 = result[1].(error) @@ -160,17 +160,17 @@ func (mock *MockBackend) UnlockCommand(cmdName command.Name) error { return ret0 } -func (mock *MockBackend) CheckCommandLock(cmdName command.Name) (*models.CommandLock, error) { +func (mock *MockBackend) CheckCommandLock(cmdName command.Name) (*command.Lock, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockBackend().") } params := []pegomock.Param{cmdName} - result := pegomock.GetGenericMockFrom(mock).Invoke("CheckCommandLock", params, []reflect.Type{reflect.TypeOf((**models.CommandLock)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *models.CommandLock + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckCommandLock", params, []reflect.Type{reflect.TypeOf((**command.Lock)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 *command.Lock var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(*models.CommandLock) + ret0 = result[0].(*command.Lock) } if result[1] != nil { ret1 = result[1].(error) diff --git a/server/core/runtime/apply_step_runner.go b/server/core/runtime/apply_step_runner.go index 0c0270e6b..6dd3859f3 100644 --- a/server/core/runtime/apply_step_runner.go +++ b/server/core/runtime/apply_step_runner.go @@ -12,7 +12,6 @@ import ( version "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -23,7 +22,7 @@ type ApplyStepRunner struct { AsyncTFExec AsyncTFExec } -func (a *ApplyStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (a *ApplyStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { if a.hasTargetFlag(ctx, extraArgs) { return "", errors.New("cannot run apply with -target because we are applying an already generated plan. Instead, run -target with atlantis plan") } @@ -64,7 +63,7 @@ func (a *ApplyStepRunner) Run(ctx project.Context, extraArgs []string, path stri return out, err } -func (a *ApplyStepRunner) hasTargetFlag(ctx project.Context, extraArgs []string) bool { +func (a *ApplyStepRunner) hasTargetFlag(ctx command.ProjectContext, extraArgs []string) bool { isTargetFlag := func(s string) bool { if s == "-target" { return true @@ -111,7 +110,7 @@ func (a *ApplyStepRunner) cleanRemoteApplyOutput(out string) string { // manual diff. // It also writes "yes" or "no" to the process to confirm the apply. func (a *ApplyStepRunner) runRemoteApply( - ctx project.Context, + ctx command.ProjectContext, applyArgs []string, path string, absPlanPath string, diff --git a/server/core/runtime/apply_step_runner_test.go b/server/core/runtime/apply_step_runner_test.go index c7b1c9a0c..495ad8e3f 100644 --- a/server/core/runtime/apply_step_runner_test.go +++ b/server/core/runtime/apply_step_runner_test.go @@ -17,7 +17,6 @@ import ( "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -30,7 +29,7 @@ func TestRun_NoDir(t *testing.T) { o := runtime.ApplyStepRunner{ TerraformExecutor: nil, } - _, err := o.Run(project.Context{ + _, err := o.Run(command.ProjectContext{ RepoRelDir: ".", Workspace: "workspace", }, nil, "/nonexistent/path", map[string]string(nil)) @@ -43,7 +42,7 @@ func TestRun_NoPlanFile(t *testing.T) { o := runtime.ApplyStepRunner{ TerraformExecutor: nil, } - _, err := o.Run(project.Context{ + _, err := o.Run(command.ProjectContext{ RepoRelDir: ".", Workspace: "workspace", }, nil, tmpDir, map[string]string(nil)) @@ -56,7 +55,7 @@ func TestRun_Success(t *testing.T) { planPath := filepath.Join(tmpDir, "workspace.tfplan") err := ioutil.WriteFile(planPath, nil, 0600) logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -88,7 +87,7 @@ func TestRun_AppliesCorrectProjectPlan(t *testing.T) { err := ioutil.WriteFile(planPath, nil, 0600) logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -122,7 +121,7 @@ func TestRun_UsesConfiguredTFVersion(t *testing.T) { logger := logging.NewNoopLogger(t) tfVersion, _ := version.NewVersion("0.11.0") - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -211,7 +210,7 @@ func TestRun_UsingTarget(t *testing.T) { TerraformExecutor: terraform, } - output, err := step.Run(project.Context{ + output, err := step.Run(command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -255,7 +254,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.` CommitStatusUpdater: updater, } tfVersion, _ := version.NewVersion("0.11.0") - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Workspace: "workspace", RepoRelDir: ".", @@ -317,7 +316,7 @@ Plan: 0 to add, 0 to change, 1 to destroy.` } tfVersion, _ := version.NewVersion("0.11.0") - output, err := o.Run(project.Context{ + output, err := o.Run(command.ProjectContext{ Log: logging.NewNoopLogger(t), Workspace: "workspace", RepoRelDir: ".", @@ -371,7 +370,7 @@ type remoteApplyMock struct { DoneCh chan bool } -func (r *remoteApplyMock) RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { +func (r *remoteApplyMock) RunCommandAsync(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { in := make(chan string) defer close(in) @@ -380,7 +379,7 @@ func (r *remoteApplyMock) RunCommandAsync(ctx project.Context, path string, args } // RunCommandAsync fakes out running terraform async. -func (r *remoteApplyMock) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { +func (r *remoteApplyMock) RunCommandAsyncWithInput(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { r.CalledArgs = args out := make(chan terraform.Line) diff --git a/server/core/runtime/env_step_runner.go b/server/core/runtime/env_step_runner.go index f20c5fe52..ae7c27dd5 100644 --- a/server/core/runtime/env_step_runner.go +++ b/server/core/runtime/env_step_runner.go @@ -3,7 +3,7 @@ package runtime import ( "strings" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // EnvStepRunner set environment variables. @@ -14,7 +14,7 @@ type EnvStepRunner struct { // Run runs the env step command. // value is the value for the environment variable. If set this is returned as // the value. Otherwise command is run and its output is the value returned. -func (r *EnvStepRunner) Run(ctx project.Context, command string, value string, path string, envs map[string]string) (string, error) { +func (r *EnvStepRunner) Run(ctx command.ProjectContext, command string, value string, path string, envs map[string]string) (string, error) { if value != "" { return value, nil } diff --git a/server/core/runtime/env_step_runner_test.go b/server/core/runtime/env_step_runner_test.go index cb1ebad2d..0084ca97b 100644 --- a/server/core/runtime/env_step_runner_test.go +++ b/server/core/runtime/env_step_runner_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -51,7 +51,7 @@ func TestEnvStepRunner_Run(t *testing.T) { t.Run(c.Command, func(t *testing.T) { tmpDir, cleanup := TempDir(t) defer cleanup() - ctx := project.Context{ + ctx := command.ProjectContext{ BaseRepo: models.Repo{ Name: "basename", Owner: "baseowner", diff --git a/server/core/runtime/executor.go b/server/core/runtime/executor.go index f7c4c9db2..69b6bb78b 100644 --- a/server/core/runtime/executor.go +++ b/server/core/runtime/executor.go @@ -2,7 +2,7 @@ package runtime import ( version "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" ) @@ -16,7 +16,7 @@ type VersionedExecutorWorkflow interface { // Executor runs an executable with provided environment variables and arguments and returns stdout type Executor interface { - Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) + Run(ctx command.ProjectContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) } // ExecutorVersionEnsurer ensures a given version exists and outputs a path to the executable diff --git a/server/core/runtime/init_step_runner.go b/server/core/runtime/init_step_runner.go index 5b088eff7..66c1a15d8 100644 --- a/server/core/runtime/init_step_runner.go +++ b/server/core/runtime/init_step_runner.go @@ -5,7 +5,7 @@ import ( "path/filepath" version "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/runtime/common" ) @@ -15,7 +15,7 @@ type InitStepRunner struct { DefaultTFVersion *version.Version } -func (i *InitStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (i *InitStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { lockFileName := ".terraform.lock.hcl" terraformLockfilePath := filepath.Join(path, lockFileName) terraformLockFileTracked, err := common.IsFileTracked(path, lockFileName) diff --git a/server/core/runtime/init_step_runner_test.go b/server/core/runtime/init_step_runner_test.go index d337d30f5..9cdec25c3 100644 --- a/server/core/runtime/init_step_runner_test.go +++ b/server/core/runtime/init_step_runner_test.go @@ -14,7 +14,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" @@ -49,7 +49,7 @@ func TestRun_UsesGetOrInitForRightVersion(t *testing.T) { terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -92,7 +92,7 @@ func TestRun_ShowInitOutputOnError(t *testing.T) { DefaultTFVersion: tfVersion, } - output, err := iso.Run(project.Context{ + output, err := iso.Run(command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -114,7 +114,7 @@ func TestRun_InitOmitsUpgradeFlagIfLockFileTracked(t *testing.T) { runCmd(t, repoDir, "git", "commit", "-m", "add .terraform.lock.hcl") logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -131,7 +131,7 @@ func TestRun_InitOmitsUpgradeFlagIfLockFileTracked(t *testing.T) { When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())). ThenReturn("output", nil) - output, err := iso.Run(project.Context{ + output, err := iso.Run(command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -151,7 +151,7 @@ func TestRun_InitKeepsUpgradeFlagIfLockFileNotPresent(t *testing.T) { RegisterMockTestingT(t) terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -185,7 +185,7 @@ func TestRun_InitKeepUpgradeFlagIfLockFilePresentAndTFLessThanPoint14(t *testing terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -252,7 +252,7 @@ func TestRun_InitExtraArgsDeDupe(t *testing.T) { terraform := mocks.NewMockClient() logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, @@ -291,7 +291,7 @@ func TestRun_InitDeletesLockFileIfPresentAndNotTracked(t *testing.T) { logger := logging.NewNoopLogger(t) tfVersion, _ := version.NewVersion("0.14.0") - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", Log: logger, diff --git a/server/core/runtime/minimum_version_step_runner_delegate.go b/server/core/runtime/minimum_version_step_runner_delegate.go index 742c2a958..f32e0cb42 100644 --- a/server/core/runtime/minimum_version_step_runner_delegate.go +++ b/server/core/runtime/minimum_version_step_runner_delegate.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // MinimumVersionStepRunnerDelegate ensures that a given step runner can't run unless the command version being used @@ -30,7 +30,7 @@ func NewMinimumVersionStepRunnerDelegate(minimumVersionStr string, defaultVersio }, nil } -func (r *MinimumVersionStepRunnerDelegate) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (r *MinimumVersionStepRunnerDelegate) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := r.defaultTfVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/minimum_version_step_runner_delegate_test.go b/server/core/runtime/minimum_version_step_runner_delegate_test.go index a4ead89ff..5b624446b 100644 --- a/server/core/runtime/minimum_version_step_runner_delegate_test.go +++ b/server/core/runtime/minimum_version_step_runner_delegate_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/runtime/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" . "github.com/runatlantis/atlantis/testing" ) @@ -32,7 +32,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := project.Context{} + ctx := command.ProjectContext{} When(mockDelegate.Run(ctx, extraArgs, path, envs)).ThenReturn(expectedOut, nil) @@ -54,7 +54,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := project.Context{ + ctx := command.ProjectContext{ TerraformVersion: tfVersion12, } @@ -78,7 +78,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := project.Context{} + ctx := command.ProjectContext{} output, err := subject.Run( ctx, @@ -100,7 +100,7 @@ func TestRunMinimumVersionDelegate(t *testing.T) { delegate: mockDelegate, } - ctx := project.Context{ + ctx := command.ProjectContext{ TerraformVersion: tfVersion11, } diff --git a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go index 93d072cb5..90db05bac 100644 --- a/server/core/runtime/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/runtime/mocks/matchers/models_projectcommandcontext.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsProjectCommandContext() project.Context { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) - var nullValue project.Context +func AnyModelsProjectCommandContext() command.ProjectContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.ProjectContext))(nil)).Elem())) + var nullValue command.ProjectContext return nullValue } -func EqModelsProjectCommandContext(value project.Context) project.Context { +func EqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func NotEqModelsProjectCommandContext(value project.Context) project.Context { +func NotEqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) command.ProjectContext { pegomock.RegisterMatcher(matcher) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } diff --git a/server/core/runtime/mocks/mock_runner.go b/server/core/runtime/mocks/mock_runner.go index d793103c2..46b944603 100644 --- a/server/core/runtime/mocks/mock_runner.go +++ b/server/core/runtime/mocks/mock_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockRunner struct { @@ -26,7 +26,7 @@ func NewMockRunner(options ...pegomock.Option) *MockRunner { func (mock *MockRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (mock *MockRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockRunner().") } @@ -82,7 +82,7 @@ type VerifierMockRunner struct { timeout time.Duration } -func (verifier *VerifierMockRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) *MockRunner_Run_OngoingVerification { +func (verifier *VerifierMockRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) *MockRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, extraArgs, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, []string, string, map[string]string) { +func (c *MockRunner_Run_OngoingVerification) GetCapturedArguments() (command.ProjectContext, []string, string, map[string]string) { ctx, extraArgs, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], extraArgs[len(extraArgs)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 [][]string, _param2 []string, _param3 []map[string]string) { +func (c *MockRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 [][]string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([][]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go index 4717c1371..b8b3e2ea3 100644 --- a/server/core/runtime/mocks/mock_versionedexecutorworkflow.go +++ b/server/core/runtime/mocks/mock_versionedexecutorworkflow.go @@ -9,7 +9,7 @@ import ( go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" logging "github.com/runatlantis/atlantis/server/logging" ) @@ -47,7 +47,7 @@ func (mock *MockVersionedExecutorWorkflow) EnsureExecutorVersion(log logging.Sim return ret0, ret1 } -func (mock *MockVersionedExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { +func (mock *MockVersionedExecutorWorkflow) Run(ctx command.ProjectContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockVersionedExecutorWorkflow().") } @@ -134,7 +134,7 @@ func (c *MockVersionedExecutorWorkflow_EnsureExecutorVersion_OngoingVerification return } -func (verifier *VerifierMockVersionedExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) *MockVersionedExecutorWorkflow_Run_OngoingVerification { +func (verifier *VerifierMockVersionedExecutorWorkflow) Run(ctx command.ProjectContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) *MockVersionedExecutorWorkflow_Run_OngoingVerification { params := []pegomock.Param{ctx, executablePath, envs, workdir, extraArgs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockVersionedExecutorWorkflow_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -145,17 +145,17 @@ type MockVersionedExecutorWorkflow_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, map[string]string, string, []string) { +func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string, map[string]string, string, []string) { ctx, executablePath, envs, workdir, extraArgs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], executablePath[len(executablePath)-1], envs[len(envs)-1], workdir[len(workdir)-1], extraArgs[len(extraArgs)-1] } -func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []map[string]string, _param3 []string, _param4 [][]string) { +func (c *MockVersionedExecutorWorkflow_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []map[string]string, _param3 []string, _param4 [][]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/runtime/plan_step_runner.go b/server/core/runtime/plan_step_runner.go index 6854aabae..bef03d384 100644 --- a/server/core/runtime/plan_step_runner.go +++ b/server/core/runtime/plan_step_runner.go @@ -11,7 +11,6 @@ import ( version "github.com/hashicorp/go-version" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -34,7 +33,7 @@ type PlanStepRunner struct { AsyncTFExec AsyncTFExec } -func (p *PlanStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PlanStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := p.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion @@ -70,7 +69,7 @@ func (p *PlanStepRunner) isRemoteOpsErr(output string, err error) bool { // remotePlan runs a terraform plan command compatible with TFE remote // operations. -func (p *PlanStepRunner) remotePlan(ctx project.Context, extraArgs []string, path string, tfVersion *version.Version, planFile string, envs map[string]string) (string, error) { +func (p *PlanStepRunner) remotePlan(ctx command.ProjectContext, extraArgs []string, path string, tfVersion *version.Version, planFile string, envs map[string]string) (string, error) { argList := [][]string{ {"plan", "-input=false", "-refresh"}, extraArgs, @@ -104,7 +103,7 @@ func (p *PlanStepRunner) remotePlan(ctx project.Context, extraArgs []string, pat // switchWorkspace changes the terraform workspace if necessary and will create // it if it doesn't exist. It handles differences between versions. -func (p *PlanStepRunner) switchWorkspace(ctx project.Context, path string, tfVersion *version.Version, envs map[string]string) error { +func (p *PlanStepRunner) switchWorkspace(ctx command.ProjectContext, path string, tfVersion *version.Version, envs map[string]string) error { // In versions less than 0.9 there is no support for workspaces. noWorkspaceSupport := MustConstraint("<0.9").Check(tfVersion) // If the user tried to set a specific workspace in the comment but their @@ -154,7 +153,7 @@ func (p *PlanStepRunner) switchWorkspace(ctx project.Context, path string, tfVer return nil } -func (p *PlanStepRunner) buildPlanCmd(ctx project.Context, extraArgs []string, path string, tfVersion *version.Version, planFile string) []string { +func (p *PlanStepRunner) buildPlanCmd(ctx command.ProjectContext, extraArgs []string, path string, tfVersion *version.Version, planFile string) []string { tfVars := p.tfVars(ctx, tfVersion) // Check if env/{workspace}.tfvars exist and include it. This is a use-case @@ -188,7 +187,7 @@ func (p *PlanStepRunner) buildPlanCmd(ctx project.Context, extraArgs []string, p // those versions don't allow setting -var flags for any variables that aren't // actually used in the configuration. Since there's no way for us to detect // if the configuration is using those variables, we don't set them. -func (p *PlanStepRunner) tfVars(ctx project.Context, tfVersion *version.Version) []string { +func (p *PlanStepRunner) tfVars(ctx command.ProjectContext, tfVersion *version.Version) []string { if tfVersion.GreaterThanOrEqual(version.Must(version.NewVersion("0.12.0"))) { return nil } @@ -240,7 +239,7 @@ func (p *PlanStepRunner) fmtPlanOutput(output string, tfVersion *version.Version // cmdArgs is the args to terraform to execute. // path is the path to where we need to execute. func (p *PlanStepRunner) runRemotePlan( - ctx project.Context, + ctx command.ProjectContext, cmdArgs []string, path string, tfVersion *version.Version, diff --git a/server/core/runtime/plan_step_runner_test.go b/server/core/runtime/plan_step_runner_test.go index 826ef328b..e2cc03b1d 100644 --- a/server/core/runtime/plan_step_runner_test.go +++ b/server/core/runtime/plan_step_runner_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" mocks2 "github.com/runatlantis/atlantis/server/events/mocks" . "github.com/petergtz/pegomock" @@ -35,7 +34,7 @@ func TestRun_NoWorkspaceIn08(t *testing.T) { workspace := "default" logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, @@ -122,7 +121,7 @@ func TestRun_ErrWorkspaceIn08(t *testing.T) { When(terraform.RunCommandWithVersion(matchers.AnyModelsProjectCommandContext(), AnyString(), AnyStringSlice(), matchers2.AnyMapOfStringToString(), matchers2.AnyPtrToGoVersionVersion(), AnyString())). ThenReturn("output", nil) - _, err := s.Run(project.Context{ + _, err := s.Run(command.ProjectContext{ Log: logger, Workspace: workspace, RepoRelDir: ".", @@ -162,7 +161,7 @@ func TestRun_SwitchesWorkspace(t *testing.T) { tfVersion, _ := version.NewVersion(c.tfVersion) logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -256,7 +255,7 @@ func TestRun_CreatesWorkspace(t *testing.T) { terraform := mocks.NewMockClient() tfVersion, _ := version.NewVersion(c.tfVersion) logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -322,7 +321,7 @@ func TestRun_NoWorkspaceSwitchIfNotNecessary(t *testing.T) { terraform := mocks.NewMockClient() tfVersion, _ := version.NewVersion("0.10.0") logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -418,7 +417,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) { "-var-file", envVarsFile, } - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", @@ -455,7 +454,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) { TerraformExecutor: terraform, DefaultTFVersion: tfVersion, } - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -554,7 +553,7 @@ Terraform will perform the following actions: return []ReturnValue{"", errors.New("unexpected call to RunCommandWithVersion")} } }) - actOutput, err := s.Run(project.Context{Workspace: "default"}, nil, "", map[string]string(nil)) + actOutput, err := s.Run(command.ProjectContext{Workspace: "default"}, nil, "", map[string]string(nil)) Ok(t, err) Equals(t, ` An execution plan has been generated and is shown below. @@ -608,7 +607,7 @@ func TestRun_OutputOnErr(t *testing.T) { return []ReturnValue{"", errors.New("unexpected call to RunCommandWithVersion")} } }) - actOutput, actErr := s.Run(project.Context{Workspace: "default"}, nil, "", map[string]string(nil)) + actOutput, actErr := s.Run(command.ProjectContext{Workspace: "default"}, nil, "", map[string]string(nil)) ErrEquals(t, expErrMsg, actErr) Equals(t, expOutput, actOutput) } @@ -661,7 +660,7 @@ func TestRun_NoOptionalVarsIn012(t *testing.T) { TerraformExecutor: terraform, DefaultTFVersion: tfVersion, } - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "default", RepoRelDir: ".", User: models.User{Username: "username"}, @@ -707,7 +706,7 @@ locally at this time. logger := logging.NewNoopLogger(t) // Now that mocking is set up, we're ready to run the plan. - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "default", RepoRelDir: ".", @@ -887,14 +886,14 @@ type remotePlanMock struct { CalledArgs []string } -func (r *remotePlanMock) RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { +func (r *remotePlanMock) RunCommandAsync(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line { input := make(chan string) defer close(input) return r.RunCommandAsyncWithInput(ctx, path, args, envs, v, workspace, input) } -func (r *remotePlanMock) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { +func (r *remotePlanMock) RunCommandAsyncWithInput(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line { r.CalledArgs = args out := make(chan terraform.Line) go func() { diff --git a/server/core/runtime/plan_type_step_runner_delegate.go b/server/core/runtime/plan_type_step_runner_delegate.go index 026f20a6c..22d0343c8 100644 --- a/server/core/runtime/plan_type_step_runner_delegate.go +++ b/server/core/runtime/plan_type_step_runner_delegate.go @@ -5,13 +5,13 @@ import ( "path/filepath" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // NullRunner is a runner that isn't configured for a given plan type but outputs nothing type NullRunner struct{} -func (p NullRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p NullRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { ctx.Log.Debug("runner not configured for plan type") return "", nil @@ -20,7 +20,7 @@ func (p NullRunner) Run(ctx project.Context, extraArgs []string, path string, en // RemoteBackendUnsupportedRunner is a runner that is responsible for outputting that the remote backend is unsupported type RemoteBackendUnsupportedRunner struct{} -func (p RemoteBackendUnsupportedRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p RemoteBackendUnsupportedRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { ctx.Log.Debug("runner not configured for remote backend") return "Remote backend is unsupported for this step.", nil @@ -49,7 +49,7 @@ func (p *PlanTypeStepRunnerDelegate) isRemotePlan(planFile string) (bool, error) return IsRemotePlan(data), nil } -func (p *PlanTypeStepRunnerDelegate) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PlanTypeStepRunnerDelegate) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { planFile := filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName)) remotePlan, err := p.isRemotePlan(planFile) diff --git a/server/core/runtime/plan_type_step_runner_delegate_test.go b/server/core/runtime/plan_type_step_runner_delegate_test.go index e1b0cc233..01910a153 100644 --- a/server/core/runtime/plan_type_step_runner_delegate_test.go +++ b/server/core/runtime/plan_type_step_runner_delegate_test.go @@ -11,7 +11,7 @@ import ( . "github.com/runatlantis/atlantis/testing" "github.com/runatlantis/atlantis/server/core/runtime/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) var planFileContents = ` @@ -47,7 +47,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte("Atlantis: this plan was created by remote ops\n"+planFileContents), 0600) Ok(t, err) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -76,7 +76,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte("Atlantis: this plan was created by remote ops\n"+planFileContents), 0600) Ok(t, err) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -105,7 +105,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte(planFileContents), 0600) Ok(t, err) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, @@ -134,7 +134,7 @@ func TestRunDelegate(t *testing.T) { err := ioutil.WriteFile(planPath, []byte(planFileContents), 0600) Ok(t, err) - ctx := project.Context{ + ctx := command.ProjectContext{ Workspace: "workspace", RepoRelDir: ".", EscapedCommentArgs: []string{"comment", "args"}, diff --git a/server/core/runtime/policy/conftest_client.go b/server/core/runtime/policy/conftest_client.go index b23cf6c7a..d55882643 100644 --- a/server/core/runtime/policy/conftest_client.go +++ b/server/core/runtime/policy/conftest_client.go @@ -13,7 +13,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/cache" runtime_models "github.com/runatlantis/atlantis/server/core/runtime/models" "github.com/runatlantis/atlantis/server/core/terraform" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" ) @@ -159,7 +159,7 @@ func NewConfTestExecutorWorkflow(log logging.SimpleLogging, versionRootDir strin } } -func (c *ConfTestExecutorWorkflow) Run(ctx project.Context, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { +func (c *ConfTestExecutorWorkflow) Run(ctx command.ProjectContext, executablePath string, envs map[string]string, workdir string, extraArgs []string) (string, error) { policyArgs := []Arg{} policySetNames := []string{} ctx.Log.Debug("policy sets, %s ", ctx.PolicySets) diff --git a/server/core/runtime/policy/conftest_client_test.go b/server/core/runtime/policy/conftest_client_test.go index ec012c8a9..5251fcc63 100644 --- a/server/core/runtime/policy/conftest_client_test.go +++ b/server/core/runtime/policy/conftest_client_test.go @@ -15,7 +15,7 @@ import ( models_mocks "github.com/runatlantis/atlantis/server/core/runtime/models/mocks" conftest_mocks "github.com/runatlantis/atlantis/server/core/runtime/policy/mocks" terraform_mocks "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) @@ -159,7 +159,7 @@ func TestRun(t *testing.T) { Name: policySetName2, } - ctx := project.Context{ + ctx := command.ProjectContext{ PolicySets: valid.PolicySets{ PolicySets: []valid.PolicySet{ policySet1, diff --git a/server/core/runtime/policy_check_step_runner.go b/server/core/runtime/policy_check_step_runner.go index 978c0cdfb..41677ff73 100644 --- a/server/core/runtime/policy_check_step_runner.go +++ b/server/core/runtime/policy_check_step_runner.go @@ -3,7 +3,7 @@ package runtime import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // PolicyCheckStepRunner runs a policy check command given a ctx @@ -27,7 +27,7 @@ func NewPolicyCheckStepRunner(defaultTfVersion *version.Version, executorWorkflo } // Run ensures a given version for the executable, builds the args from the project context and then runs executable returning the result -func (p *PolicyCheckStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *PolicyCheckStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { executable, err := p.versionEnsurer.EnsureExecutorVersion(ctx.Log, ctx.PolicySets.Version) if err != nil { diff --git a/server/core/runtime/policy_check_step_runner_test.go b/server/core/runtime/policy_check_step_runner_test.go index 94c28e98f..3562371cf 100644 --- a/server/core/runtime/policy_check_step_runner_test.go +++ b/server/core/runtime/policy_check_step_runner_test.go @@ -8,7 +8,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" @@ -22,7 +22,7 @@ func TestRun(t *testing.T) { workdir := "/path" executablePath := "some/path/conftest" - context := project.Context{ + context := command.ProjectContext{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, diff --git a/server/core/runtime/run_step_runner.go b/server/core/runtime/run_step_runner.go index 0bd9fcda5..6a7673bf3 100644 --- a/server/core/runtime/run_step_runner.go +++ b/server/core/runtime/run_step_runner.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // RunStepRunner runs custom commands. @@ -19,7 +19,7 @@ type RunStepRunner struct { TerraformBinDir string } -func (r *RunStepRunner) Run(ctx project.Context, command string, path string, envs map[string]string) (string, error) { +func (r *RunStepRunner) Run(ctx command.ProjectContext, command string, path string, envs map[string]string) (string, error) { tfVersion := r.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/run_step_runner_test.go b/server/core/runtime/run_step_runner_test.go index 2e5070a2e..8536a331e 100644 --- a/server/core/runtime/run_step_runner_test.go +++ b/server/core/runtime/run_step_runner_test.go @@ -11,7 +11,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" matchers2 "github.com/runatlantis/atlantis/server/core/terraform/mocks/matchers" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" @@ -113,7 +113,7 @@ func TestRunStepRunner_Run(t *testing.T) { t.Run(c.Command, func(t *testing.T) { tmpDir, cleanup := TempDir(t) defer cleanup() - ctx := project.Context{ + ctx := command.ProjectContext{ BaseRepo: models.Repo{ Name: "basename", Owner: "baseowner", diff --git a/server/core/runtime/runtime.go b/server/core/runtime/runtime.go index fc3cfe4f3..ee9c59e80 100644 --- a/server/core/runtime/runtime.go +++ b/server/core/runtime/runtime.go @@ -12,7 +12,6 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" ) @@ -27,7 +26,7 @@ const ( // TerraformExec brings the interface from TerraformClient into this package // without causing circular imports. type TerraformExec interface { - RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) + RunCommandWithVersion(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) EnsureVersion(log logging.SimpleLogging, v *version.Version) error } @@ -42,20 +41,20 @@ type AsyncTFExec interface { // Callers can use the input channel to pass stdin input to the command. // If any error is passed on the out channel, there will be no // further output (so callers are free to exit). - RunCommandAsync(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line - RunCommandAsyncWithInput(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line + RunCommandAsync(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) <-chan terraform.Line + RunCommandAsyncWithInput(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string, input <-chan string) <-chan terraform.Line } // StatusUpdater brings the interface from CommitStatusUpdater into this package // without causing circular imports. type StatusUpdater interface { - UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_runner.go Runner // Runner mirrors events.StepRunner as a way to bring it into this package type Runner interface { - Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) + Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) } // MustConstraint returns a constraint. It panics on error. diff --git a/server/core/runtime/show_step_runner.go b/server/core/runtime/show_step_runner.go index ffbdf015e..a322ddc4f 100644 --- a/server/core/runtime/show_step_runner.go +++ b/server/core/runtime/show_step_runner.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) const minimumShowTfVersion string = "0.12.0" @@ -30,7 +30,7 @@ type ShowStepRunner struct { DefaultTFVersion *version.Version } -func (p *ShowStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (p *ShowStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := p.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/show_step_runner_test.go b/server/core/runtime/show_step_runner_test.go index 2a59f04da..581bb458c 100644 --- a/server/core/runtime/show_step_runner_test.go +++ b/server/core/runtime/show_step_runner_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) @@ -21,7 +21,7 @@ func TestShowStepRunnner(t *testing.T) { resultPath := filepath.Join(path, "test-default.json") envs := map[string]string{"key": "val"} tfVersion, _ := version.NewVersion("0.12") - context := project.Context{ + context := command.ProjectContext{ Workspace: "default", ProjectName: "test", Log: logger, @@ -58,7 +58,7 @@ func TestShowStepRunnner(t *testing.T) { v, _ := version.NewVersion("0.13.0") - contextWithVersionOverride := project.Context{ + contextWithVersionOverride := command.ProjectContext{ Workspace: "default", ProjectName: "test", Log: logger, diff --git a/server/core/runtime/version_step_runner.go b/server/core/runtime/version_step_runner.go index 2f17792f2..8485e1230 100644 --- a/server/core/runtime/version_step_runner.go +++ b/server/core/runtime/version_step_runner.go @@ -4,7 +4,7 @@ import ( "path/filepath" "github.com/hashicorp/go-version" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // VersionStepRunner runs a version command given a ctx @@ -14,7 +14,7 @@ type VersionStepRunner struct { } // Run ensures a given version for the executable, builds the args from the project context and then runs executable returning the result -func (v *VersionStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (v *VersionStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { tfVersion := v.DefaultTFVersion if ctx.TerraformVersion != nil { tfVersion = ctx.TerraformVersion diff --git a/server/core/runtime/version_step_runner_test.go b/server/core/runtime/version_step_runner_test.go index e7597e4f9..ea20cf45e 100644 --- a/server/core/runtime/version_step_runner_test.go +++ b/server/core/runtime/version_step_runner_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" @@ -17,7 +17,7 @@ func TestRunVersionStep(t *testing.T) { logger := logging.NewNoopLogger(t) workspace := "default" - context := project.Context{ + context := command.ProjectContext{ Log: logger, EscapedCommentArgs: []string{"comment", "args"}, Workspace: workspace, diff --git a/server/core/terraform/async_client.go b/server/core/terraform/async_client.go index 027cbe6c4..6bcf9da58 100644 --- a/server/core/terraform/async_client.go +++ b/server/core/terraform/async_client.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/go-version" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/jobs" ) @@ -26,14 +26,14 @@ type AsyncClient struct { // Callers can use the input channel to pass stdin input to the command. // If any error is passed on the out channel, there will be no // further output (so callers are free to exit). -func (c *AsyncClient) RunCommandAsync(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) <-chan Line { +func (c *AsyncClient) RunCommandAsync(ctx command.ProjectContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) <-chan Line { input := make(chan string) defer close(input) return c.RunCommandAsyncWithInput(ctx, path, args, customEnvVars, v, workspace, input) } -func (c *AsyncClient) RunCommandAsyncWithInput(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string, input <-chan string) <-chan Line { +func (c *AsyncClient) RunCommandAsyncWithInput(ctx command.ProjectContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string, input <-chan string) <-chan Line { outCh := make(chan Line) // We start a goroutine to do our work asynchronously and then immediately diff --git a/server/core/terraform/async_client_test.go b/server/core/terraform/async_client_test.go index 94e9852c7..8febec0c0 100644 --- a/server/core/terraform/async_client_test.go +++ b/server/core/terraform/async_client_test.go @@ -10,7 +10,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -26,7 +26,7 @@ func TestDefaultClient_RunCommandAsync_Success(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo hello") - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, } @@ -54,7 +54,7 @@ func TestDefaultClient_RunCommandAsync_BigOutput(t *testing.T) { workspace := "workspace" logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -101,7 +101,7 @@ func TestDefaultClient_RunCommandAsync_StderrOutput(t *testing.T) { logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -127,7 +127,7 @@ func TestDefaultClient_RunCommandAsync_ExitOne(t *testing.T) { echoCommand := exec.Command("sh", "-c", "echo dying && exit 1") logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() @@ -154,7 +154,7 @@ func TestDefaultClient_RunCommandAsync_Input(t *testing.T) { echoCommand := exec.Command("sh", "-c", "read a && echo $a") logger := logging.NewNoopLogger(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, } mockBuilder := mocks.NewMockcommandBuilder() diff --git a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go index 93d072cb5..90db05bac 100644 --- a/server/core/terraform/mocks/matchers/models_projectcommandcontext.go +++ b/server/core/terraform/mocks/matchers/models_projectcommandcontext.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsProjectCommandContext() project.Context { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) - var nullValue project.Context +func AnyModelsProjectCommandContext() command.ProjectContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.ProjectContext))(nil)).Elem())) + var nullValue command.ProjectContext return nullValue } -func EqModelsProjectCommandContext(value project.Context) project.Context { +func EqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func NotEqModelsProjectCommandContext(value project.Context) project.Context { +func NotEqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) command.ProjectContext { pegomock.RegisterMatcher(matcher) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } diff --git a/server/core/terraform/mocks/mock_terraform_client.go b/server/core/terraform/mocks/mock_terraform_client.go index 6732ddb2b..de316998d 100644 --- a/server/core/terraform/mocks/mock_terraform_client.go +++ b/server/core/terraform/mocks/mock_terraform_client.go @@ -9,8 +9,7 @@ import ( go_version "github.com/hashicorp/go-version" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" - models "github.com/runatlantis/atlantis/server/events/models" + "github.com/runatlantis/atlantis/server/events/command" logging "github.com/runatlantis/atlantis/server/logging" ) @@ -29,7 +28,7 @@ func NewMockClient(options ...pegomock.Option) *MockClient { func (mock *MockClient) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockClient) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockClient) RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) (string, error) { +func (mock *MockClient) RunCommandWithVersion(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClient().") } @@ -100,7 +99,7 @@ type VerifierMockClient struct { timeout time.Duration } -func (verifier *VerifierMockClient) RunCommandWithVersion(ctx models.ProjectCommandContext, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) *MockClient_RunCommandWithVersion_OngoingVerification { +func (verifier *VerifierMockClient) RunCommandWithVersion(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *go_version.Version, workspace string) *MockClient_RunCommandWithVersion_OngoingVerification { params := []pegomock.Param{ctx, path, args, envs, v, workspace} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RunCommandWithVersion", params, verifier.timeout) return &MockClient_RunCommandWithVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -111,17 +110,17 @@ type MockClient_RunCommandWithVersion_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetCapturedArguments() (project.Context, string, []string, map[string]string, *go_version.Version, string) { +func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string, []string, map[string]string, *go_version.Version, string) { ctx, path, args, envs, v, workspace := c.GetAllCapturedArguments() return ctx[len(ctx)-1], path[len(path)-1], args[len(args)-1], envs[len(envs)-1], v[len(v)-1], workspace[len(workspace)-1] } -func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetAllCapturedArguments() (_param0 []models.ProjectCommandContext, _param1 []string, _param2 [][]string, _param3 []map[string]string, _param4 []*go_version.Version, _param5 []string) { +func (c *MockClient_RunCommandWithVersion_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 [][]string, _param3 []map[string]string, _param4 []*go_version.Version, _param5 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/core/terraform/terraform_client.go b/server/core/terraform/terraform_client.go index aab86c70f..5783bac65 100644 --- a/server/core/terraform/terraform_client.go +++ b/server/core/terraform/terraform_client.go @@ -30,7 +30,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/cache" runtime_models "github.com/runatlantis/atlantis/server/core/runtime/models" "github.com/runatlantis/atlantis/server/core/terraform/cloud" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/terraform/ansi" "github.com/runatlantis/atlantis/server/jobs" "github.com/runatlantis/atlantis/server/logging" @@ -45,7 +45,7 @@ type Client interface { // RunCommandWithVersion executes terraform with args in path. If v is nil, // it will use the default Terraform version. workspace is the Terraform // workspace which should be set as an environment variable. - RunCommandWithVersion(ctx project.Context, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) + RunCommandWithVersion(ctx command.ProjectContext, path string, args []string, envs map[string]string, v *version.Version, workspace string) (string, error) // EnsureVersion makes sure that terraform version `v` is available to use EnsureVersion(log logging.SimpleLogging, v *version.Version) error @@ -248,7 +248,7 @@ func (c *DefaultClient) EnsureVersion(log logging.SimpleLogging, v *version.Vers } // See Client.RunCommandWithVersion. -func (c *DefaultClient) RunCommandWithVersion(ctx project.Context, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) (string, error) { +func (c *DefaultClient) RunCommandWithVersion(ctx command.ProjectContext, path string, args []string, customEnvVars map[string]string, v *version.Version, workspace string) (string, error) { shouldAllocate, err := c.featureAllocator.ShouldAllocate(feature.LogStreaming, ctx.BaseRepo.FullName) if err != nil { diff --git a/server/core/terraform/terraform_client_internal_test.go b/server/core/terraform/terraform_client_internal_test.go index 4d3d682ac..de0a75134 100644 --- a/server/core/terraform/terraform_client_internal_test.go +++ b/server/core/terraform/terraform_client_internal_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/go-version" . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -29,7 +29,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo hello") - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, BaseRepo: models.Repo{ FullName: "owner/repo", @@ -104,7 +104,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion_Error(t *testing.T) { logger := logging.NewNoopLogger(t) echoCommand := exec.Command("sh", "-c", "echo dying && exit 1") - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, BaseRepo: models.Repo{ FullName: "owner/repo", diff --git a/server/core/terraform/terraform_client_test.go b/server/core/terraform/terraform_client_test.go index ba27c64f5..a8c591d26 100644 --- a/server/core/terraform/terraform_client_test.go +++ b/server/core/terraform/terraform_client_test.go @@ -23,7 +23,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/cmd" "github.com/runatlantis/atlantis/server/core/terraform" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" jobmocks "github.com/runatlantis/atlantis/server/jobs/mocks" "github.com/runatlantis/atlantis/server/logging" @@ -57,7 +57,7 @@ func TestNewClient_DefaultTFFlagInPath(t *testing.T) { logger := logging.NewNoopLogger(t) tmp, binDir, cacheDir, cleanup := mkSubDirs(t) projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler() - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Workspace: "default", RepoRelDir: ".", @@ -91,7 +91,7 @@ func TestNewClient_DefaultTFFlagInBinDir(t *testing.T) { fakeBinOut := "Terraform v0.11.10\n" tmp, binDir, cacheDir, cleanup := mkSubDirs(t) projectCmdOutputHandler := jobmocks.NewMockProjectCommandOutputHandler() - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Workspace: "default", RepoRelDir: ".", diff --git a/server/events/apply_command_runner.go b/server/events/apply_command_runner.go index 05b560e46..db8e27c16 100644 --- a/server/events/apply_command_runner.go +++ b/server/events/apply_command_runner.go @@ -4,7 +4,6 @@ import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -113,7 +112,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { ctx.Log.Warn("unable to get pull request status: %s. Continuing with mergeable and approved assumed false", err) } - var projectCmds []project.Context + var projectCmds []command.ProjectContext projectCmds, err = a.prjCmdBuilder.BuildApplyCommands(ctx, cmd) if err != nil { @@ -172,7 +171,7 @@ func (a *ApplyCommandRunner) IsLocked() (bool, error) { return lock.Locked, err } -func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []project.Context) bool { +func (a *ApplyCommandRunner) isParallelEnabled(projectCmds []command.ProjectContext) bool { return len(projectCmds) > 0 && projectCmds[0].ParallelApplyEnabled } diff --git a/server/events/apply_command_runner_test.go b/server/events/apply_command_runner_test.go index 336dca672..fd731b2ed 100644 --- a/server/events/apply_command_runner_test.go +++ b/server/events/apply_command_runner_test.go @@ -63,7 +63,7 @@ func TestApplyCommandRunner_IsLocked(t *testing.T) { Log: logger, Pull: modelPull, HeadRepo: fixtures.GithubRepo, - Trigger: models.Comment, + Trigger: command.CommentTrigger, Scope: scopeNull, } diff --git a/server/events/apply_requirement_handler.go b/server/events/apply_requirement_handler.go index 6c51e53ca..62e514ab0 100644 --- a/server/events/apply_requirement_handler.go +++ b/server/events/apply_requirement_handler.go @@ -3,20 +3,20 @@ package events import ( "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) //go:generate pegomock generate -m --package mocks -o mocks/mock_apply_handler.go ApplyRequirement type ApplyRequirement interface { - ValidateProject(repoDir string, ctx project.Context) (string, error) + ValidateProject(repoDir string, ctx command.ProjectContext) (string, error) } type AggregateApplyRequirements struct { WorkingDir WorkingDir } -func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx project.Context) (failure string, err error) { +func (a *AggregateApplyRequirements) ValidateProject(repoDir string, ctx command.ProjectContext) (failure string, err error) { for _, req := range ctx.ApplyRequirements { switch req { case raw.ApprovedApplyRequirement: diff --git a/server/events/approve_policies_command_runner.go b/server/events/approve_policies_command_runner.go index 1b64ed50a..7e9a56e1a 100644 --- a/server/events/approve_policies_command_runner.go +++ b/server/events/approve_policies_command_runner.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -88,7 +87,7 @@ func (a *ApprovePoliciesCommandRunner) Run(ctx *command.Context, cmd *CommentCom a.updateCommitStatus(ctx, pullStatus) } -func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *command.Context, prjCmds []project.Context) (result command.Result) { +func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *command.Context, prjCmds []command.ProjectContext) (result command.Result) { // Check if vcs user is in the owner list of the PolicySets. All projects // share the same Owners list at this time so no reason to iterate over each // project. @@ -97,7 +96,7 @@ func (a *ApprovePoliciesCommandRunner) buildApprovePolicyCommandResults(ctx *com return } - var prjResults []project.Result + var prjResults []command.ProjectResult for _, prjCmd := range prjCmds { prjResult := a.prjCmdRunner.ApprovePolicies(prjCmd) diff --git a/server/events/automerger.go b/server/events/automerger.go index ae462a572..2dc55dacd 100644 --- a/server/events/automerger.go +++ b/server/events/automerger.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -46,7 +45,7 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu } // automergeEnabled returns true if automerging is enabled in this context. -func (c *AutoMerger) automergeEnabled(projectCmds []project.Context) bool { +func (c *AutoMerger) automergeEnabled(projectCmds []command.ProjectContext) bool { // If the global automerge is set, we always automerge. return c.GlobalAutomerge || // Otherwise we check if this repo is configured for automerging. @@ -54,7 +53,7 @@ func (c *AutoMerger) automergeEnabled(projectCmds []project.Context) bool { } // deleteSourceBranchOnMergeEnabled returns true if we should delete the source branch on merge in this context. -func (c *AutoMerger) deleteSourceBranchOnMergeEnabled(projectCmds []project.Context) bool { +func (c *AutoMerger) deleteSourceBranchOnMergeEnabled(projectCmds []command.ProjectContext) bool { //check if this repo is configured for automerging. return (len(projectCmds) > 0 && projectCmds[0].DeleteSourceBranchOnMerge) } diff --git a/server/events/command/context.go b/server/events/command/context.go index da23e6c1f..03eb76423 100644 --- a/server/events/command/context.go +++ b/server/events/command/context.go @@ -13,10 +13,10 @@ type CommandTrigger int const ( // Commands that are automatically triggered (ie. automatic plans) - Auto CommandTrigger = iota + AutoTrigger CommandTrigger = iota // Commands that are triggered by comments (ie. atlantis plan) - Comment + CommentTrigger ) // Context represents the context of a command that should be executed diff --git a/server/events/command/lock.go b/server/events/command/lock.go new file mode 100644 index 000000000..e95cc38db --- /dev/null +++ b/server/events/command/lock.go @@ -0,0 +1,26 @@ +package command + +import ( + "time" +) + +// LockMetadata contains additional data provided to the lock +type LockMetadata struct { + UnixTime int64 +} + +// Lock represents a global lock for an atlantis command (plan, apply, policy_check). +// It is used to prevent commands from being executed +type Lock struct { + // Time is the time at which the lock was first created. + LockMetadata LockMetadata + CommandName Name +} + +func (l *Lock) LockTime() time.Time { + return time.Unix(l.LockMetadata.UnixTime, 0) +} + +func (l *Lock) IsLocked() bool { + return !l.LockTime().IsZero() +} diff --git a/server/events/command/project/context.go b/server/events/command/project_context.go similarity index 93% rename from server/events/command/project/context.go rename to server/events/command/project_context.go index 073849c67..f7e1762ac 100644 --- a/server/events/command/project/context.go +++ b/server/events/command/project_context.go @@ -1,4 +1,4 @@ -package project +package command import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/config/valid" - "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" "github.com/uber-go/tally" @@ -17,10 +16,10 @@ const ( planfileSlashReplace = "::" ) -// Context defines the context for a plan or apply stage that will +// ProjectContext defines the context for a plan or apply stage that will // be executed for a project. -type Context struct { - CommandName command.Name +type ProjectContext struct { + CommandName Name // ApplyCmd is the command that users should run to apply this plan. If // this is an apply then this will be empty. ApplyCmd string @@ -99,7 +98,7 @@ type Context struct { // ProjectCloneDir creates relative path to clone the repo to. If we are running // plans and apply in parallel we want to have a directory per project. -func (p Context) ProjectCloneDir() string { +func (p ProjectContext) ProjectCloneDir() string { if p.ParallelPlanEnabled || p.ParallelApplyEnabled { return filepath.Join(p.ProjectName, p.Workspace) } @@ -109,12 +108,12 @@ func (p Context) ProjectCloneDir() string { // SetScope sets the scope of the stats object field. Note: we deliberately set this on the value // instead of a pointer since we want scopes to mirror our function stack -func (p Context) SetScope(scope string) { +func (p ProjectContext) SetScope(scope string) { p.Scope = p.Scope.SubScope(scope) //nolint } // GetShowResultFileName returns the filename (not the path) to store the tf show result -func (p Context) GetShowResultFileName() string { +func (p ProjectContext) GetShowResultFileName() string { if p.ProjectName == "" { return fmt.Sprintf("%s.json", p.Workspace) } @@ -123,7 +122,7 @@ func (p Context) GetShowResultFileName() string { } // Gets a unique identifier for the current pull request as a single string -func (p Context) PullInfo() string { +func (p ProjectContext) PullInfo() string { return buildPullInfo(p.BaseRepo.FullName, p.Pull.Num, p.ProjectName, p.RepoRelDir, p.Workspace) } func buildPullInfo(repoName string, pullNum int, projectName string, relDir string, workspace string) string { diff --git a/server/events/command/project/result.go b/server/events/command/project_result.go similarity index 63% rename from server/events/command/project/result.go rename to server/events/command/project_result.go index f1f21c128..3fadd00c8 100644 --- a/server/events/command/project/result.go +++ b/server/events/command/project_result.go @@ -1,26 +1,25 @@ -package project +package command import ( - "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" ) -// Result is the result of executing a plan/policy_check/apply for a specific project. -type Result struct { - Command command.Name +// ProjectResult is the result of executing a plan/policy_check/apply for a specific project. +type ProjectResult struct { + Command Name RepoRelDir string Workspace string Error error Failure string - PlanSuccess *PlanSuccess - PolicyCheckSuccess *PolicyCheckSuccess + PlanSuccess *models.PlanSuccess + PolicyCheckSuccess *models.PolicyCheckSuccess ApplySuccess string VersionSuccess string ProjectName string } // CommitStatus returns the vcs commit status of this project result. -func (p Result) CommitStatus() models.CommitStatus { +func (p ProjectResult) CommitStatus() models.CommitStatus { if p.Error != nil { return models.FailedCommitStatus } @@ -31,24 +30,24 @@ func (p Result) CommitStatus() models.CommitStatus { } // PlanStatus returns the plan status. -func (p Result) PlanStatus() models.ProjectPlanStatus { +func (p ProjectResult) PlanStatus() models.ProjectPlanStatus { switch p.Command { - case command.Plan: + case Plan: if p.Error != nil { return models.ErroredPlanStatus } else if p.Failure != "" { return models.ErroredPlanStatus } return models.PlannedPlanStatus - case command.PolicyCheck, command.ApprovePolicies: + case PolicyCheck, ApprovePolicies: if p.Error != nil { return models.ErroredPolicyCheckStatus } else if p.Failure != "" { return models.ErroredPolicyCheckStatus } return models.PassedPolicyCheckStatus - case command.Apply: + case Apply: if p.Error != nil { return models.ErroredApplyStatus } else if p.Failure != "" { @@ -59,3 +58,8 @@ func (p Result) PlanStatus() models.ProjectPlanStatus { panic("PlanStatus() missing a combination") } + +// IsSuccessful returns true if this project result had no errors. +func (p ProjectResult) IsSuccessful() bool { + return p.PlanSuccess != nil || p.PolicyCheckSuccess != nil || p.ApplySuccess != "" +} diff --git a/server/events/command/result.go b/server/events/command/result.go index 1a533bc65..af264caa6 100644 --- a/server/events/command/result.go +++ b/server/events/command/result.go @@ -1,12 +1,10 @@ package command -import "github.com/runatlantis/atlantis/server/events/command/project" - // Result is the result of running a Command. type Result struct { Error error Failure string - ProjectResults []project.Result + ProjectResults []ProjectResult // PlansDeleted is true if all plans created during this command were // deleted. This happens if automerging is enabled and one project has an // error since automerging requires all plans to succeed. diff --git a/server/events/command/result_test.go b/server/events/command/result_test.go index a220051c9..0e176f260 100644 --- a/server/events/command/result_test.go +++ b/server/events/command/result_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -29,13 +28,13 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "empty results list": { cr: command.Result{ - ProjectResults: []project.Result{}, + ProjectResults: []command.ProjectResult{}, }, exp: false, }, "successful plan": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, }, @@ -45,7 +44,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "successful apply": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { ApplySuccess: "success", }, @@ -55,7 +54,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "single errored project": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { Error: errors.New("err"), }, @@ -65,7 +64,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "single failed project": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { Failure: "failure", }, @@ -75,7 +74,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "two successful projects": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, }, @@ -88,7 +87,7 @@ func TestCommandResult_HasErrors(t *testing.T) { }, "one successful, one failed project": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{}, }, diff --git a/server/events/command_runner.go b/server/events/command_runner.go index 650b019f2..fe3e2deb1 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -161,7 +161,7 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo Pull: pull, HeadRepo: headRepo, PullStatus: status, - Trigger: models.Auto, + Trigger: command.AutoTrigger, TriggerTimestamp: timestamp, } if !c.validateCtxAndComment(ctx) { @@ -228,7 +228,7 @@ func (c *DefaultCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHead Pull: pull, PullStatus: status, HeadRepo: headRepo, - Trigger: models.Comment, + Trigger: command.CommentTrigger, Scope: scope, TriggerTimestamp: timestamp, } diff --git a/server/events/command_runner_internal_test.go b/server/events/command_runner_internal_test.go index 2005a34ad..5027a2510 100644 --- a/server/events/command_runner_internal_test.go +++ b/server/events/command_runner_internal_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -170,6 +169,6 @@ func (m *MockCSU) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, func (m *MockCSU) UpdateCombined(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command command.Name) error { return nil } -func (m *MockCSU) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { +func (m *MockCSU) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error { return nil } diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index f7df9efb5..82c46d06b 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -24,7 +24,6 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/vcs" lyft_vcs "github.com/runatlantis/atlantis/server/events/vcs/lyft" "github.com/runatlantis/atlantis/server/logging" @@ -52,7 +51,7 @@ var azuredevopsGetter *mocks.MockAzureDevopsPullGetter var githubGetter *mocks.MockGithubPullGetter var gitlabGetter *mocks.MockGitlabMergeRequestGetter var ch events.DefaultCommandRunner -var fa events.FeatureAwareCommandRunner +var fa events.ForceApplyCommandRunner var workingDir events.WorkingDir var pendingPlanFinder *mocks.MockPendingPlanFinder var drainer *events.Drainer @@ -188,7 +187,7 @@ func setup(t *testing.T) *vcsmocks.MockClient { command.Plan: planCommandRunner, command.Apply: applyCommandRunner, command.ApprovePolicies: approvePoliciesCommandRunner, - command.UnlockCommand: unlockCommandRunner, + command.Unlock: unlockCommandRunner, command.Version: versionCommandRunner, } @@ -374,7 +373,7 @@ func TestRunCommentCommandUnlock_NoProjects_SilenceEnabled(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(&pull, nil) When(eventParsing.ParseGithubPull(&pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Unlock}, time.Now()) vcsClient.VerifyWasCalled(Never()).CreateComment(matchers.AnyModelsRepo(), AnyInt(), AnyString(), AnyString()) } @@ -401,11 +400,10 @@ func TestFeatureAwareRunCommentCommandRunner_CommentWhenEnabled(t *testing.T) { vcsClient := setup(t) allocator := fmocks.NewMockAllocator() - fa = events.FeatureAwareCommandRunner{ - CommandRunner: &ch, - VCSClient: vcsClient, - Logger: logger, - FeatureAllocator: allocator, + fa = events.ForceApplyCommandRunner{ + CommandRunner: &ch, + VCSClient: vcsClient, + Logger: logger, } modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} @@ -422,7 +420,7 @@ func TestRunCommentCommand_DisableDisableAutoplan(t *testing.T) { defer func() { ch.DisableAutoplan = false }() When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). - ThenReturn([]project.Context{ + ThenReturn([]command.ProjectContext{ { CommandName: command.Plan, }, @@ -498,7 +496,7 @@ func TestRunUnlockCommand_VCSComment(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Unlock}, time.Now()) deleteLockCommand.VerifyWasCalledOnce().DeleteLocksByPull(fixtures.GithubRepo.FullName, fixtures.Pull.Num) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, fixtures.Pull.Num, "All Atlantis locks for this PR have been unlocked and plans discarded", "unlock") @@ -518,7 +516,7 @@ func TestRunUnlockCommandFail_VCSComment(t *testing.T) { When(deleteLockCommand.DeleteLocksByPull(fixtures.GithubRepo.FullName, fixtures.Pull.Num)).ThenReturn(0, errors.New("err")) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.UnlockCommand}, time.Now()) + ch.RunCommentCommand(fixtures.GithubRepo, &fixtures.GithubRepo, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Unlock}, time.Now()) vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, fixtures.Pull.Num, "Failed to delete PR locks", "unlock") } @@ -538,7 +536,7 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())). - ThenReturn([]project.Context{ + ThenReturn([]command.ProjectContext{ { CommandName: command.Plan, }, @@ -552,14 +550,14 @@ func TestRunAutoplanCommand_DeletePlans(t *testing.T) { // The first call, we return a successful result. callCount++ return ReturnValues{ - project.Result{ + command.ProjectResult{ PlanSuccess: &models.PlanSuccess{}, }, } } // The second call, we return a failed result. return ReturnValues{ - project.Result{ + command.ProjectResult{ Error: errors.New("err"), }, } @@ -597,7 +595,7 @@ func TestFailedApprovalCreatesFailedStatusUpdate(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]project.Context{ + When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]command.ProjectContext{ { CommandName: command.ApprovePolicies, }, @@ -644,7 +642,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) When(staleCommandChecker.CommandIsStale(matchers.AnyPtrToModelsCommandContext())).ThenReturn(false) - When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]project.Context{ + When(projectCommandBuilder.BuildApprovePoliciesCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).ThenReturn([]command.ProjectContext{ { CommandName: command.ApprovePolicies, PolicySets: valid.PolicySets{ @@ -658,7 +656,7 @@ func TestApprovedPoliciesUpdateFailedPolicyStatus(t *testing.T) { When(workingDir.GetPullDir(fixtures.GithubRepo, fixtures.Pull)).ThenReturn(tmp, nil) When(projectCommandRunner.ApprovePolicies(matchers.AnyModelsProjectCommandContext())).Then(func(_ []Param) ReturnValues { return ReturnValues{ - project.Result{ + command.ProjectResult{ Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, @@ -700,7 +698,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil) When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil) - _, _ = boltDB.UpdatePullWithResults(modelPull, []project.Result{ + _, _ = boltDB.UpdatePullWithResults(modelPull, []command.ProjectResult{ { Command: command.PolicyCheck, Error: fmt.Errorf("failing policy"), @@ -714,7 +712,7 @@ func TestApplyMergeablityWhenPolicyCheckFails(t *testing.T) { When(projectCommandBuilder.BuildApplyCommands(matchers.AnyPtrToEventsCommandContext(), matchers.AnyPtrToEventsCommentCommand())).Then(func(args []Param) ReturnValues { return ReturnValues{ - []project.Context{ + []command.ProjectContext{ { CommandName: command.Apply, ProjectName: "default", @@ -767,7 +765,7 @@ func TestRunApply_DiscardedProjects(t *testing.T) { applyCommandRunner.DB = boltDB pull := fixtures.Pull pull.BaseRepo = fixtures.GithubRepo - _, err = boltDB.UpdatePullWithResults(pull, []project.Result{ + _, err = boltDB.UpdatePullWithResults(pull, []command.ProjectResult{ { Command: command.Plan, RepoRelDir: ".", diff --git a/server/events/comment_parser.go b/server/events/comment_parser.go index dbd75fcd4..4d23da5ff 100644 --- a/server/events/comment_parser.go +++ b/server/events/comment_parser.go @@ -100,7 +100,7 @@ type CommentParseResult struct { // Valid commands contain: // - The initial "executable" name, 'run' or 'atlantis' or '@GithubUser' // where GithubUser is the API user Atlantis is running as. -// - Then a command, either 'plan', 'apply', 'approve_policies', or 'help'. +// - Then a cmd, either 'plan', 'apply', 'approve_policies', or 'help'. // - Then optional flags, then an optional separator '--' followed by optional // extra flags to be appended to the terraform plan/apply command. // @@ -162,16 +162,16 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen if len(args) == 1 { return CommentParseResult{CommentResponse: e.HelpComment(e.ApplyDisabled)} } - command := args[1] + cmd := args[1] // Help output. - if e.stringInSlice(command, []string{"help", "-h", "--help"}) { + if e.stringInSlice(cmd, []string{"help", "-h", "--help"}) { return CommentParseResult{CommentResponse: e.HelpComment(e.ApplyDisabled)} } // Need to have a plan, apply, approve_policy or unlock at this point. - if !e.stringInSlice(command, []string{command.Plan.String(), command.Apply.String(), command.UnlockCommand.String(), command.ApprovePolicies.String(), command.Version.String()}) { - return CommentParseResult{CommentResponse: fmt.Sprintf("```\nError: unknown command %q.\nRun 'atlantis --help' for usage.\n```", command)} + if !e.stringInSlice(cmd, []string{command.Plan.String(), command.Apply.String(), command.Unlock.String(), command.ApprovePolicies.String(), command.Version.String()}) { + return CommentParseResult{CommentResponse: fmt.Sprintf("```\nError: unknown command %q.\nRun 'atlantis --help' for usage.\n```", cmd)} } var workspace string @@ -182,7 +182,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen var name command.Name // Set up the flag parsing depending on the command. - switch command { + switch cmd { case command.Plan.String(): name = command.Plan flagSet = pflag.NewFlagSet(command.Plan.String(), pflag.ContinueOnError) @@ -206,9 +206,9 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen flagSet = pflag.NewFlagSet(command.ApprovePolicies.String(), pflag.ContinueOnError) flagSet.SetOutput(ioutil.Discard) flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.") - case command.UnlockCommand.String(): - name = command.UnlockCommand - flagSet = pflag.NewFlagSet(command.UnlockCommand.String(), pflag.ContinueOnError) + case command.Unlock.String(): + name = command.Unlock + flagSet = pflag.NewFlagSet(command.Unlock.String(), pflag.ContinueOnError) flagSet.SetOutput(ioutil.Discard) case command.Version.String(): name = command.Version @@ -218,20 +218,20 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen flagSet.StringVarP(&project, projectFlagLong, projectFlagShort, "", fmt.Sprintf("Print the version for this project. Refers to the name of the project configured in %s.", config.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)} + return CommentParseResult{CommentResponse: fmt.Sprintf("Error: unknown command %q – this is a bug", cmd)} } // Now parse the flags. // It's safe to use [2:] because we know there's at least 2 elements in args. err = flagSet.Parse(args[2:]) if err == pflag.ErrHelp { - return CommentParseResult{CommentResponse: fmt.Sprintf("```\nUsage of %s:\n%s\n```", command, flagSet.FlagUsagesWrapped(usagesCols))} + return CommentParseResult{CommentResponse: fmt.Sprintf("```\nUsage of %s:\n%s\n```", cmd, flagSet.FlagUsagesWrapped(usagesCols))} } if err != nil { - if command == command.UnlockCommand.String() { + if cmd == command.Unlock.String() { return CommentParseResult{CommentResponse: UnlockUsage} } - return CommentParseResult{CommentResponse: e.errMarkdown(err.Error(), command, flagSet)} + return CommentParseResult{CommentResponse: e.errMarkdown(err.Error(), cmd, flagSet)} } var unusedArgs []string @@ -241,7 +241,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen unusedArgs = flagSet.Args()[0:flagSet.ArgsLenAtDash()] } if len(unusedArgs) > 0 { - return CommentParseResult{CommentResponse: e.errMarkdown(fmt.Sprintf("unknown argument(s) – %s", strings.Join(unusedArgs, " ")), command, flagSet)} + return CommentParseResult{CommentResponse: e.errMarkdown(fmt.Sprintf("unknown argument(s) – %s", strings.Join(unusedArgs, " ")), cmd, flagSet)} } var extraArgs []string @@ -251,14 +251,14 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen dir, err = e.validateDir(dir) if err != nil { - return CommentParseResult{CommentResponse: e.errMarkdown(err.Error(), command, flagSet)} + return CommentParseResult{CommentResponse: e.errMarkdown(err.Error(), cmd, flagSet)} } // Use the same validation that Terraform uses: https://git.io/vxGhU. Plus // we also don't allow '..'. We don't want the workspace to contain a path // since we create files based on the name. if workspace != url.PathEscape(workspace) || strings.Contains(workspace, "..") { - return CommentParseResult{CommentResponse: e.errMarkdown(fmt.Sprintf("invalid workspace: %q", workspace), command, flagSet)} + return CommentParseResult{CommentResponse: e.errMarkdown(fmt.Sprintf("invalid workspace: %q", workspace), cmd, flagSet)} } // If project is specified, dir or workspace should not be set. Since we @@ -268,7 +268,7 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen // 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) - return CommentParseResult{CommentResponse: e.errMarkdown(err, command, flagSet)} + return CommentParseResult{CommentResponse: e.errMarkdown(err, cmd, flagSet)} } return CommentParseResult{ @@ -362,8 +362,8 @@ func (e *CommentParser) stringInSlice(a string, list []string) bool { return false } -func (e *CommentParser) errMarkdown(errMsg string, command string, flagSet *pflag.FlagSet) string { - return fmt.Sprintf("```\nError: %s.\nUsage of %s:\n%s```", errMsg, command, flagSet.FlagUsagesWrapped(usagesCols)) +func (e *CommentParser) errMarkdown(errMsg string, cmd string, flagSet *pflag.FlagSet) string { + return fmt.Sprintf("```\nError: %s.\nUsage of %s:\n%s```", errMsg, cmd, flagSet.FlagUsagesWrapped(usagesCols)) } func (e *CommentParser) HelpComment(applyDisabled bool) string { diff --git a/server/events/commit_status_updater.go b/server/events/commit_status_updater.go index 0b343f605..edd3ae149 100644 --- a/server/events/commit_status_updater.go +++ b/server/events/commit_status_updater.go @@ -18,7 +18,6 @@ import ( "strings" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -36,7 +35,7 @@ type CommitStatusUpdater interface { UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmdName command.Name, numSuccess int, numTotal int) error // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error } // DefaultCommitStatusUpdater implements CommitStatusUpdater. @@ -67,7 +66,7 @@ func (d *DefaultCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull return d.Client.UpdateStatus(repo, pull, status, src, fmt.Sprintf("%d/%d projects %s successfully.", numSuccess, numTotal, cmdVerb), "") } -func (d *DefaultCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { +func (d *DefaultCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error { projectID := ctx.ProjectName if projectID == "" { projectID = fmt.Sprintf("%s/%s", ctx.RepoRelDir, ctx.Workspace) diff --git a/server/events/commit_status_updater_test.go b/server/events/commit_status_updater_test.go index 6ef8fffaf..db32622c1 100644 --- a/server/events/commit_status_updater_test.go +++ b/server/events/commit_status_updater_test.go @@ -20,7 +20,6 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -177,7 +176,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectSrc(t *testing.T) { client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "atlantis"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(project.Context{ + err := s.UpdateProject(command.ProjectContext{ ProjectName: c.projectName, RepoRelDir: c.repoRelDir, Workspace: c.workspace, @@ -236,7 +235,7 @@ func TestDefaultCommitStatusUpdater_UpdateProject(t *testing.T) { client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "atlantis"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(project.Context{ + err := s.UpdateProject(command.ProjectContext{ RepoRelDir: ".", Workspace: "default", }, @@ -255,7 +254,7 @@ func TestDefaultCommitStatusUpdater_UpdateProjectCustomStatusName(t *testing.T) client := mocks.NewMockClient() titleBuilder := vcs.StatusTitleBuilder{TitlePrefix: "custom"} s := events.DefaultCommitStatusUpdater{Client: client, TitleBuilder: titleBuilder} - err := s.UpdateProject(project.Context{ + err := s.UpdateProject(command.ProjectContext{ RepoRelDir: ".", Workspace: "default", }, diff --git a/server/events/db_updater.go b/server/events/db_updater.go index 73c39e7d2..eaa0712dc 100644 --- a/server/events/db_updater.go +++ b/server/events/db_updater.go @@ -3,7 +3,6 @@ package events import ( "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -11,11 +10,11 @@ type DBUpdater struct { DB *db.BoltDB } -func (c *DBUpdater) updateDB(ctx *command.Context, pull models.PullRequest, results []project.Result) (models.PullStatus, error) { +func (c *DBUpdater) updateDB(ctx *command.Context, pull models.PullRequest, results []command.ProjectResult) (models.PullStatus, error) { // Filter out results that errored due to the directory not existing. We // don't store these in the database because they would never be "apply-able" // and so the pull request would always have errors. - var filtered []project.Result + var filtered []command.ProjectResult for _, r := range results { if _, ok := r.Error.(DirNotExistErr); ok { ctx.Log.Debug("ignoring error result from project at dir %q workspace %q because it is dir not exist error", r.RepoRelDir, r.Workspace) diff --git a/server/events/instrumented_project_command_builder.go b/server/events/instrumented_project_command_builder.go index 4284fcd8c..04ea3193d 100644 --- a/server/events/instrumented_project_command_builder.go +++ b/server/events/instrumented_project_command_builder.go @@ -2,7 +2,6 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/metrics" "github.com/runatlantis/atlantis/server/logging" ) @@ -12,7 +11,7 @@ type InstrumentedProjectCommandBuilder struct { Logger logging.SimpleLogging } -func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { +func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -33,7 +32,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildApplyCommands(ctx *command.Cont return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { +func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() @@ -54,7 +53,7 @@ func (b *InstrumentedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.C return projectCmds, err } -func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { +func (b *InstrumentedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) { scope := ctx.Scope.SubScope("builder") timer := scope.Timer(metrics.ExecutionTimeMetric).Start() diff --git a/server/events/instrumented_project_command_runner.go b/server/events/instrumented_project_command_runner.go index da305eddd..cd8906f4c 100644 --- a/server/events/instrumented_project_command_runner.go +++ b/server/events/instrumented_project_command_runner.go @@ -1,7 +1,7 @@ package events import ( - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/metrics" ) @@ -9,19 +9,19 @@ type InstrumentedProjectCommandRunner struct { ProjectCommandRunner } -func (p *InstrumentedProjectCommandRunner) Plan(ctx project.Context) project.Result { +func (p *InstrumentedProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { return RunAndEmitStats("plan", ctx, p.ProjectCommandRunner.Plan) } -func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { +func (p *InstrumentedProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { return RunAndEmitStats("policy check", ctx, p.ProjectCommandRunner.PolicyCheck) } -func (p *InstrumentedProjectCommandRunner) Apply(ctx project.Context) project.Result { +func (p *InstrumentedProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { return RunAndEmitStats("apply", ctx, p.ProjectCommandRunner.Apply) } -func RunAndEmitStats(commandName string, ctx project.Context, execute func(ctx project.Context) project.Result) project.Result { +func RunAndEmitStats(commandName string, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult) command.ProjectResult { // ensures we are differentiating between project level command and overall command ctx.SetScope("project") diff --git a/server/events/markdown_renderer.go b/server/events/markdown_renderer.go index f1dc88030..15076d6ac 100644 --- a/server/events/markdown_renderer.go +++ b/server/events/markdown_renderer.go @@ -24,7 +24,6 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -125,7 +124,7 @@ func (m *MarkdownRenderer) Render(res command.Result, cmdName command.Name, log return m.renderProjectResults(res.ProjectResults, common, vcsHost, templateOverrides) } -func (m *MarkdownRenderer) renderProjectResults(results []project.Result, common commonData, vcsHost models.VCSHostType, templateOverrides map[string]string) string { +func (m *MarkdownRenderer) renderProjectResults(results []command.ProjectResult, common commonData, vcsHost models.VCSHostType, templateOverrides map[string]string) string { var resultsTmplData []projectResultTmplData numPlanSuccesses := 0 numPolicyCheckSuccesses := 0 diff --git a/server/events/markdown_renderer_test.go b/server/events/markdown_renderer_test.go index 00855a6b3..bfd166b8c 100644 --- a/server/events/markdown_renderer_test.go +++ b/server/events/markdown_renderer_test.go @@ -21,7 +21,6 @@ import ( "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" ) @@ -30,7 +29,7 @@ func TestCustomTemplates(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string TemplateOverrides map[string]string @@ -38,7 +37,7 @@ func TestCustomTemplates(t *testing.T) { { "Plan Override", command.Plan, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Custom Template", map[string]string{"plan": "testdata/custom_template.tmpl"}, @@ -46,7 +45,7 @@ func TestCustomTemplates(t *testing.T) { { "Default Plan", command.Plan, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", map[string]string{"apply": "testdata/custom_template.tmpl"}, @@ -54,7 +53,7 @@ func TestCustomTemplates(t *testing.T) { { "Apply Override", command.Apply, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Custom Template", map[string]string{"apply": "testdata/custom_template.tmpl"}, @@ -62,7 +61,7 @@ func TestCustomTemplates(t *testing.T) { { "Project Plan Successful Custom Template", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path1", @@ -110,7 +109,7 @@ Custom Template { "Only Use Plan Success Override with failed, and errored plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -283,28 +282,28 @@ func TestRenderProjectResults(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string }{ { "no projects", command.Plan, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "approve policies", command.ApprovePolicies, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Approved Policies for 0 projects:\n\n\n\n", }, { "single successful plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -339,7 +338,7 @@ $$$ { "single successful plan with master ahead", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -377,7 +376,7 @@ $$$ { "single successful plan with project name", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -413,7 +412,7 @@ $$$ { "single successful policy check with project name", command.PolicyCheck, - []project.Result{ + []command.ProjectResult{ { PolicyCheckSuccess: &models.PolicyCheckSuccess{ PolicyCheckOutput: "2 tests, 1 passed, 0 warnings, 0 failure, 0 exceptions", @@ -449,7 +448,7 @@ $$$ { "single successful apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { ApplySuccess: "success", Workspace: "workspace", @@ -468,7 +467,7 @@ $$$ { "single successful apply with project name", command.Apply, - []project.Result{ + []command.ProjectResult{ { ApplySuccess: "success", Workspace: "workspace", @@ -488,7 +487,7 @@ $$$ { "multiple successful plans", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -550,7 +549,7 @@ $$$ { "multiple successful policy checks", command.PolicyCheck, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -612,7 +611,7 @@ $$$ { "multiple successful applies", command.Apply, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: "path", Workspace: "workspace", @@ -649,7 +648,7 @@ $$$ { "single errored plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { Error: errors.New("error"), RepoRelDir: "path", @@ -669,7 +668,7 @@ $$$ { "single failed plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: "path", Workspace: "workspace", @@ -686,7 +685,7 @@ $$$ { "successful, failed, and errored plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -748,7 +747,7 @@ $$$ { "successful, failed, and errored policy check", command.PolicyCheck, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -812,7 +811,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -859,7 +858,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -931,14 +930,14 @@ func TestRenderProjectResultsDisableApplyAll(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply all set", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -969,7 +968,7 @@ $$$ { "single successful plan with project name with disable apply all set", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1001,7 +1000,7 @@ $$$ { "multiple successful plans, disable apply all set", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -1084,14 +1083,14 @@ func TestRenderProjectResultsDisableApply(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with disable apply set", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1120,7 +1119,7 @@ $$$ { "single successful plan with project name with disable apply set", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1150,7 +1149,7 @@ $$$ { "multiple successful plans, disable apply set", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -1232,7 +1231,7 @@ func TestRenderProjectResults_DisableFolding(t *testing.T) { } rendered := mr.Render(command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "default", @@ -1316,7 +1315,7 @@ func TestRenderProjectResults_WrappedErr(t *testing.T) { } rendered := mr.Render(command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "default", @@ -1426,10 +1425,10 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { mr := events.MarkdownRenderer{ GitlabSupportsCommonMark: c.GitlabCommonMarkSupport, } - var pr project.Result + var pr command.ProjectResult switch cmd { case command.Plan: - pr = project.Result{ + pr = command.ProjectResult{ RepoRelDir: ".", Workspace: "default", PlanSuccess: &models.PlanSuccess{ @@ -1440,14 +1439,14 @@ func TestRenderProjectResults_WrapSingleProject(t *testing.T) { }, } case command.Apply: - pr = project.Result{ + pr = command.ProjectResult{ RepoRelDir: ".", Workspace: "default", ApplySuccess: c.Output, } } rendered := mr.Render(command.Result{ - ProjectResults: []project.Result{pr}, + ProjectResults: []command.ProjectResult{pr}, }, cmd, "log", false, c.VCSHost, make(map[string]string)) // Check result. @@ -1531,7 +1530,7 @@ func TestRenderProjectResults_MultiProjectApplyWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) rendered := mr.Render(command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -1577,7 +1576,7 @@ func TestRenderProjectResults_MultiProjectPlanWrapped(t *testing.T) { mr := events.MarkdownRenderer{} tfOut := strings.Repeat("line\n", 13) + "Plan: 1 to add, 0 to change, 0 to destroy." rendered := mr.Render(command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -1655,7 +1654,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }{ "one failure": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -1672,7 +1671,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }, "two failures": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -1704,7 +1703,7 @@ func TestRenderProjectResults_PlansDeleted(t *testing.T) { }, "one failure, one success": { cr: command.Result{ - ProjectResults: []project.Result{ + ProjectResults: []command.ProjectResult{ { RepoRelDir: ".", Workspace: "staging", @@ -1760,21 +1759,21 @@ func TestRenderProjectResultsWithRepoLockingDisabled(t *testing.T) { cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string }{ { "no projects", command.Plan, - []project.Result{}, + []command.ProjectResult{}, models.Github, "Ran Plan for 0 projects:\n\n\n\n", }, { "single successful plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1808,7 +1807,7 @@ $$$ { "single successful plan with master ahead", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1845,7 +1844,7 @@ $$$ { "single successful plan with project name", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: "terraform-output", @@ -1880,7 +1879,7 @@ $$$ { "single successful apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { ApplySuccess: "success", Workspace: "workspace", @@ -1899,7 +1898,7 @@ $$$ { "single successful apply with project name", command.Apply, - []project.Result{ + []command.ProjectResult{ { ApplySuccess: "success", Workspace: "workspace", @@ -1919,7 +1918,7 @@ $$$ { "multiple successful plans", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -1979,7 +1978,7 @@ $$$ { "multiple successful applies", command.Apply, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: "path", Workspace: "workspace", @@ -2016,7 +2015,7 @@ $$$ { "single errored plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { Error: errors.New("error"), RepoRelDir: "path", @@ -2036,7 +2035,7 @@ $$$ { "single failed plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { RepoRelDir: "path", Workspace: "workspace", @@ -2053,7 +2052,7 @@ $$$ { "successful, failed, and errored plan", command.Plan, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -2114,7 +2113,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -2161,7 +2160,7 @@ $$$ { "successful, failed, and errored apply", command.Apply, - []project.Result{ + []command.ProjectResult{ { Workspace: "workspace", RepoRelDir: "path", @@ -2340,14 +2339,14 @@ Plan: 1 to add, 1 to change, 1 to destroy. cases := []struct { Description string Command command.Name - ProjectResults []project.Result + ProjectResults []command.ProjectResult VCSHost models.VCSHostType Expected string }{ { "single successful plan with diff markdown formatted", command.Plan, - []project.Result{ + []command.ProjectResult{ { PlanSuccess: &models.PlanSuccess{ TerraformOutput: tfOutput, diff --git a/server/events/mocks/matchers/models_projectcommandcontext.go b/server/events/mocks/matchers/models_projectcommandcontext.go index 93d072cb5..90db05bac 100644 --- a/server/events/mocks/matchers/models_projectcommandcontext.go +++ b/server/events/mocks/matchers/models_projectcommandcontext.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsProjectCommandContext() project.Context { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) - var nullValue project.Context +func AnyModelsProjectCommandContext() command.ProjectContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.ProjectContext))(nil)).Elem())) + var nullValue command.ProjectContext return nullValue } -func EqModelsProjectCommandContext(value project.Context) project.Context { +func EqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func NotEqModelsProjectCommandContext(value project.Context) project.Context { +func NotEqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) command.ProjectContext { pegomock.RegisterMatcher(matcher) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } diff --git a/server/events/mocks/matchers/models_projectresult.go b/server/events/mocks/matchers/models_projectresult.go index 55db043a4..8ceee5c06 100644 --- a/server/events/mocks/matchers/models_projectresult.go +++ b/server/events/mocks/matchers/models_projectresult.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsProjectResult() project.Result { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Result))(nil)).Elem())) - var nullValue project.Result +func AnyModelsProjectResult() command.ProjectResult { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.ProjectResult))(nil)).Elem())) + var nullValue command.ProjectResult return nullValue } -func EqModelsProjectResult(value project.Result) project.Result { +func EqModelsProjectResult(value command.ProjectResult) command.ProjectResult { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue project.Result + var nullValue command.ProjectResult return nullValue } -func NotEqModelsProjectResult(value project.Result) project.Result { +func NotEqModelsProjectResult(value command.ProjectResult) command.ProjectResult { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue project.Result + var nullValue command.ProjectResult return nullValue } -func ModelsProjectResultThat(matcher pegomock.ArgumentMatcher) project.Result { +func ModelsProjectResultThat(matcher pegomock.ArgumentMatcher) command.ProjectResult { pegomock.RegisterMatcher(matcher) - var nullValue project.Result + var nullValue command.ProjectResult return nullValue } diff --git a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go index ea31d6b3a..1e43301e2 100644 --- a/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go +++ b/server/events/mocks/matchers/slice_of_models_projectcommandcontext.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnySliceOfModelsProjectCommandContext() []project.Context { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*([]project.Context))(nil)).Elem())) - var nullValue []project.Context +func AnySliceOfModelsProjectCommandContext() []command.ProjectContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*([]command.ProjectContext))(nil)).Elem())) + var nullValue []command.ProjectContext return nullValue } -func EqSliceOfModelsProjectCommandContext(value []project.Context) []project.Context { +func EqSliceOfModelsProjectCommandContext(value []command.ProjectContext) []command.ProjectContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue []project.Context + var nullValue []command.ProjectContext return nullValue } -func NotEqSliceOfModelsProjectCommandContext(value []project.Context) []project.Context { +func NotEqSliceOfModelsProjectCommandContext(value []command.ProjectContext) []command.ProjectContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue []project.Context + var nullValue []command.ProjectContext return nullValue } -func SliceOfModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) []project.Context { +func SliceOfModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) []command.ProjectContext { pegomock.RegisterMatcher(matcher) - var nullValue []project.Context + var nullValue []command.ProjectContext return nullValue } diff --git a/server/events/mocks/mock_apply_handler.go b/server/events/mocks/mock_apply_handler.go index 8c64583a0..3bb8b2b01 100644 --- a/server/events/mocks/mock_apply_handler.go +++ b/server/events/mocks/mock_apply_handler.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockApplyRequirement struct { @@ -26,7 +26,7 @@ func NewMockApplyRequirement(options ...pegomock.Option) *MockApplyRequirement { func (mock *MockApplyRequirement) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockApplyRequirement) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockApplyRequirement) ValidateProject(_param0 string, _param1 project.Context) (string, error) { +func (mock *MockApplyRequirement) ValidateProject(_param0 string, _param1 command.ProjectContext) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockApplyRequirement().") } @@ -82,7 +82,7 @@ type VerifierMockApplyRequirement struct { timeout time.Duration } -func (verifier *VerifierMockApplyRequirement) ValidateProject(_param0 string, _param1 project.Context) *MockApplyRequirement_ValidateProject_OngoingVerification { +func (verifier *VerifierMockApplyRequirement) ValidateProject(_param0 string, _param1 command.ProjectContext) *MockApplyRequirement_ValidateProject_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidateProject", params, verifier.timeout) return &MockApplyRequirement_ValidateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,21 +93,21 @@ type MockApplyRequirement_ValidateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetCapturedArguments() (string, project.Context) { +func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetCapturedArguments() (string, command.ProjectContext) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []project.Context) { +func (c *MockApplyRequirement_ValidateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(string) } - _param1 = make([]project.Context, len(c.methodInvocations)) + _param1 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(project.Context) + _param1[u] = param.(command.ProjectContext) } } return diff --git a/server/events/mocks/mock_commit_status_updater.go b/server/events/mocks/mock_commit_status_updater.go index 561338798..081ed61c6 100644 --- a/server/events/mocks/mock_commit_status_updater.go +++ b/server/events/mocks/mock_commit_status_updater.go @@ -9,7 +9,6 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -58,7 +57,7 @@ func (mock *MockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull return ret0 } -func (mock *MockCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error { +func (mock *MockCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCommitStatusUpdater().") } @@ -149,8 +148,8 @@ func (c *MockCommitStatusUpdater_UpdateCombined_OngoingVerification) GetAllCaptu return } -func (verifier *VerifierMockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, command models.CommandName, numSuccess int, numTotal int) *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification { - params := []pegomock.Param{repo, pull, status, command, numSuccess, numTotal} +func (verifier *VerifierMockCommitStatusUpdater) UpdateCombinedCount(repo models.Repo, pull models.PullRequest, status models.CommitStatus, cmd command.Name, numSuccess int, numTotal int) *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification { + params := []pegomock.Param{repo, pull, status, cmd, numSuccess, numTotal} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateCombinedCount", params, verifier.timeout) return &MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } @@ -165,7 +164,7 @@ func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetCap return repo[len(repo)-1], pull[len(pull)-1], status[len(status)-1], command[len(command)-1], numSuccess[len(numSuccess)-1], numTotal[len(numTotal)-1] } -func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest, _param2 []models.CommitStatus, _param3 []models.CommandName, _param4 []int, _param5 []int) { +func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAllCapturedArguments() (_param0 []models.Repo, _param1 []models.PullRequest, _param2 []models.CommitStatus, _param3 []command.Name, _param4 []int, _param5 []int) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.Repo, len(c.methodInvocations)) @@ -196,7 +195,7 @@ func (c *MockCommitStatusUpdater_UpdateCombinedCount_OngoingVerification) GetAll return } -func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) *MockCommitStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{ctx, cmdName, status, url} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockCommitStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -207,17 +206,17 @@ type MockCommitStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus, string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string) { ctx, cmdName, status, url := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmdName[len(cmdName)-1], status[len(status)-1], url[len(url)-1] } -func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockCommitStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_custom_step_runner.go b/server/events/mocks/mock_custom_step_runner.go index c3ca4756c..649066066 100644 --- a/server/events/mocks/mock_custom_step_runner.go +++ b/server/events/mocks/mock_custom_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockCustomStepRunner struct { @@ -26,7 +26,7 @@ func NewMockCustomStepRunner(options ...pegomock.Option) *MockCustomStepRunner { func (mock *MockCustomStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockCustomStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockCustomStepRunner) Run(ctx project.Context, cmd string, path string, envs map[string]string) (string, error) { +func (mock *MockCustomStepRunner) Run(ctx command.ProjectContext, cmd string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockCustomStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockCustomStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockCustomStepRunner) Run(ctx project.Context, cmd string, path string, envs map[string]string) *MockCustomStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockCustomStepRunner) Run(ctx command.ProjectContext, cmd string, path string, envs map[string]string) *MockCustomStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, cmd, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockCustomStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockCustomStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockCustomStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, string, map[string]string) { +func (c *MockCustomStepRunner_Run_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string, string, map[string]string) { ctx, cmd, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmd[len(cmd)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockCustomStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []string, _param3 []map[string]string) { +func (c *MockCustomStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_env_step_runner.go b/server/events/mocks/mock_env_step_runner.go index fd97c5319..02772ff94 100644 --- a/server/events/mocks/mock_env_step_runner.go +++ b/server/events/mocks/mock_env_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockEnvStepRunner struct { @@ -26,7 +26,7 @@ func NewMockEnvStepRunner(options ...pegomock.Option) *MockEnvStepRunner { func (mock *MockEnvStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockEnvStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockEnvStepRunner) Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) (string, error) { +func (mock *MockEnvStepRunner) Run(ctx command.ProjectContext, cmd string, value string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockEnvStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockEnvStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockEnvStepRunner) Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) *MockEnvStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockEnvStepRunner) Run(ctx command.ProjectContext, cmd string, value string, path string, envs map[string]string) *MockEnvStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, cmd, value, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockEnvStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockEnvStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockEnvStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, string, string, string, map[string]string) { +func (c *MockEnvStepRunner_Run_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string, string, string, map[string]string) { ctx, cmd, value, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], cmd[len(cmd)-1], value[len(value)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockEnvStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []string, _param3 []string, _param4 []map[string]string) { +func (c *MockEnvStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []string, _param3 []string, _param4 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_job_message_sender.go b/server/events/mocks/mock_job_message_sender.go index 14b5c07c2..c8620913c 100644 --- a/server/events/mocks/mock_job_message_sender.go +++ b/server/events/mocks/mock_job_message_sender.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockJobMessageSender struct { @@ -26,7 +26,7 @@ func NewMockJobMessageSender(options ...pegomock.Option) *MockJobMessageSender { func (mock *MockJobMessageSender) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobMessageSender) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobMessageSender) Send(_param0 project.Context, _param1 string, _param2 bool) { +func (mock *MockJobMessageSender) Send(_param0 command.ProjectContext, _param1 string, _param2 bool) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobMessageSender().") } @@ -71,7 +71,7 @@ type VerifierMockJobMessageSender struct { timeout time.Duration } -func (verifier *VerifierMockJobMessageSender) Send(_param0 project.Context, _param1 string, _param2 bool) *MockJobMessageSender_Send_OngoingVerification { +func (verifier *VerifierMockJobMessageSender) Send(_param0 command.ProjectContext, _param1 string, _param2 bool) *MockJobMessageSender_Send_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) return &MockJobMessageSender_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -82,17 +82,17 @@ type MockJobMessageSender_Send_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobMessageSender_Send_OngoingVerification) GetCapturedArguments() (project.Context, string, bool) { +func (c *MockJobMessageSender_Send_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string, bool) { _param0, _param1, _param2 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] } -func (c *MockJobMessageSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string, _param2 []bool) { +func (c *MockJobMessageSender_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string, _param2 []bool) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_job_url_setter.go b/server/events/mocks/mock_job_url_setter.go index 89e291404..eff992d57 100644 --- a/server/events/mocks/mock_job_url_setter.go +++ b/server/events/mocks/mock_job_url_setter.go @@ -9,7 +9,6 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -28,7 +27,7 @@ func NewMockJobURLSetter(options ...pegomock.Option) *MockJobURLSetter { func (mock *MockJobURLSetter) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobURLSetter) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus) error { +func (mock *MockJobURLSetter) SetJobURLWithStatus(_param0 command.ProjectContext, _param1 command.Name, _param2 models.CommitStatus) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobURLSetter().") } @@ -80,7 +79,7 @@ type VerifierMockJobURLSetter struct { timeout time.Duration } -func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { +func (verifier *VerifierMockJobURLSetter) SetJobURLWithStatus(_param0 command.ProjectContext, _param1 command.Name, _param2 models.CommitStatus) *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SetJobURLWithStatus", params, verifier.timeout) return &MockJobURLSetter_SetJobURLWithStatus_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -91,17 +90,17 @@ type MockJobURLSetter_SetJobURLWithStatus_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus) { _param0, _param1, _param2 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] } -func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus) { +func (c *MockJobURLSetter_SetJobURLWithStatus_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/mocks/mock_log_stream_url_generator.go b/server/events/mocks/mock_log_stream_url_generator.go index a903f0acb..ee95820b9 100644 --- a/server/events/mocks/mock_log_stream_url_generator.go +++ b/server/events/mocks/mock_log_stream_url_generator.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -27,7 +27,7 @@ func NewMockJobsUrlGenerator(options ...pegomock.Option) *MockJobsUrlGenerator { func (mock *MockJobsUrlGenerator) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockJobsUrlGenerator) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p project.Context) string { +func (mock *MockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p command.ProjectContext) string { if mock == nil { panic("mock must not be nil. Use myMock := NewMockJobsUrlGenerator().") } @@ -79,7 +79,7 @@ type VerifierMockJobsUrlGenerator struct { timeout time.Duration } -func (verifier *VerifierMockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p project.Context) *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification { +func (verifier *VerifierMockJobsUrlGenerator) GenerateProjectJobsUrl(pull models.PullRequest, p command.ProjectContext) *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification { params := []pegomock.Param{pull, p} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateProjectJobsUrl", params, verifier.timeout) return &MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -90,21 +90,21 @@ type MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetCapturedArguments() (models.PullRequest, project.Context) { +func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetCapturedArguments() (models.PullRequest, command.ProjectContext) { pull, p := c.GetAllCapturedArguments() return pull[len(pull)-1], p[len(p)-1] } -func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest, _param1 []project.Context) { +func (c *MockJobsUrlGenerator_GenerateProjectJobsUrl_OngoingVerification) GetAllCapturedArguments() (_param0 []models.PullRequest, _param1 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]models.PullRequest, len(c.methodInvocations)) for u, param := range params[0] { _param0[u] = param.(models.PullRequest) } - _param1 = make([]project.Context, len(c.methodInvocations)) + _param1 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[1] { - _param1[u] = param.(project.Context) + _param1[u] = param.(command.ProjectContext) } } return diff --git a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go index a73f4cfeb..9c3cb3316 100644 --- a/server/events/mocks/mock_pre_workflows_hooks_command_runner.go +++ b/server/events/mocks/mock_pre_workflows_hooks_command_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - models "github.com/runatlantis/atlantis/server/events/models" + command "github.com/runatlantis/atlantis/server/events/command" ) type MockPreWorkflowHooksCommandRunner struct { @@ -28,7 +28,7 @@ func (mock *MockPreWorkflowHooksCommandRunner) SetFailHandler(fh pegomock.FailHa } func (mock *MockPreWorkflowHooksCommandRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *models.CommandContext) error { +func (mock *MockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *command.Context) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockPreWorkflowHooksCommandRunner().") } @@ -80,7 +80,7 @@ type VerifierMockPreWorkflowHooksCommandRunner struct { timeout time.Duration } -func (verifier *VerifierMockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *models.CommandContext) *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification { +func (verifier *VerifierMockPreWorkflowHooksCommandRunner) RunPreHooks(ctx *command.Context) *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RunPreHooks", params, verifier.timeout) return &MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -91,17 +91,17 @@ type MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetCapturedArguments() *models.CommandContext { +func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetCapturedArguments() *command.Context { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetAllCapturedArguments() (_param0 []*models.CommandContext) { +func (c *MockPreWorkflowHooksCommandRunner_RunPreHooks_OngoingVerification) GetAllCapturedArguments() (_param0 []*command.Context) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]*models.CommandContext, len(c.methodInvocations)) + _param0 = make([]*command.Context, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(*models.CommandContext) + _param0[u] = param.(*command.Context) } } return diff --git a/server/events/mocks/mock_project_command_builder.go b/server/events/mocks/mock_project_command_builder.go index 87e5cc80c..1b3482359 100644 --- a/server/events/mocks/mock_project_command_builder.go +++ b/server/events/mocks/mock_project_command_builder.go @@ -10,7 +10,6 @@ import ( pegomock "github.com/petergtz/pegomock" events "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" ) type MockProjectCommandBuilder struct { @@ -28,17 +27,17 @@ func NewMockProjectCommandBuilder(options ...pegomock.Option) *MockProjectComman func (mock *MockProjectCommandBuilder) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandBuilder) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { +func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []project.Context + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildAutoplanCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []command.ProjectContext var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]project.Context) + ret0 = result[0].([]command.ProjectContext) } if result[1] != nil { ret1 = result[1].(error) @@ -47,17 +46,17 @@ func (mock *MockProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Contex return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { +func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []project.Context + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildPlanCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []command.ProjectContext var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]project.Context) + ret0 = result[0].([]command.ProjectContext) } if result[1] != nil { ret1 = result[1].(error) @@ -66,17 +65,17 @@ func (mock *MockProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, c return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { +func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []project.Context + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApplyCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []command.ProjectContext var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]project.Context) + ret0 = result[0].([]command.ProjectContext) } if result[1] != nil { ret1 = result[1].(error) @@ -85,17 +84,17 @@ func (mock *MockProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { +func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []project.Context + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildApprovePoliciesCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []command.ProjectContext var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]project.Context) + ret0 = result[0].([]command.ProjectContext) } if result[1] != nil { ret1 = result[1].(error) @@ -104,17 +103,17 @@ func (mock *MockProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command return ret0, ret1 } -func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]project.Context, error) { +func (mock *MockProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, comment *events.CommentCommand) ([]command.ProjectContext, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandBuilder().") } params := []pegomock.Param{ctx, comment} - result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", params, []reflect.Type{reflect.TypeOf((*[]project.Context)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []project.Context + result := pegomock.GetGenericMockFrom(mock).Invoke("BuildVersionCommands", params, []reflect.Type{reflect.TypeOf((*[]command.ProjectContext)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []command.ProjectContext var ret1 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].([]project.Context) + ret0 = result[0].([]command.ProjectContext) } if result[1] != nil { ret1 = result[1].(error) diff --git a/server/events/mocks/mock_project_command_runner.go b/server/events/mocks/mock_project_command_runner.go index 682e2051a..9f27f89a3 100644 --- a/server/events/mocks/mock_project_command_runner.go +++ b/server/events/mocks/mock_project_command_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockProjectCommandRunner struct { @@ -26,76 +26,76 @@ func NewMockProjectCommandRunner(options ...pegomock.Option) *MockProjectCommand func (mock *MockProjectCommandRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectCommandRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectCommandRunner) Plan(ctx project.Context) project.Result { +func (mock *MockProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) - var ret0 project.Result + result := pegomock.GetGenericMockFrom(mock).Invoke("Plan", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var ret0 command.ProjectResult if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(project.Result) + ret0 = result[0].(command.ProjectResult) } } return ret0 } -func (mock *MockProjectCommandRunner) Apply(ctx project.Context) project.Result { +func (mock *MockProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) - var ret0 project.Result + result := pegomock.GetGenericMockFrom(mock).Invoke("Apply", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var ret0 command.ProjectResult if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(project.Result) + ret0 = result[0].(command.ProjectResult) } } return ret0 } -func (mock *MockProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { +func (mock *MockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) - var ret0 project.Result + result := pegomock.GetGenericMockFrom(mock).Invoke("PolicyCheck", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var ret0 command.ProjectResult if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(project.Result) + ret0 = result[0].(command.ProjectResult) } } return ret0 } -func (mock *MockProjectCommandRunner) ApprovePolicies(ctx project.Context) project.Result { +func (mock *MockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) - var ret0 project.Result + result := pegomock.GetGenericMockFrom(mock).Invoke("ApprovePolicies", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var ret0 command.ProjectResult if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(project.Result) + ret0 = result[0].(command.ProjectResult) } } return ret0 } -func (mock *MockProjectCommandRunner) Version(ctx project.Context) project.Result { +func (mock *MockProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectResult { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandRunner().") } params := []pegomock.Param{ctx} - result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*project.Result)(nil)).Elem()}) - var ret0 project.Result + result := pegomock.GetGenericMockFrom(mock).Invoke("Version", params, []reflect.Type{reflect.TypeOf((*command.ProjectResult)(nil)).Elem()}) + var ret0 command.ProjectResult if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(project.Result) + ret0 = result[0].(command.ProjectResult) } } return ret0 @@ -138,7 +138,7 @@ type VerifierMockProjectCommandRunner struct { timeout time.Duration } -func (verifier *VerifierMockProjectCommandRunner) Plan(ctx project.Context) *MockProjectCommandRunner_Plan_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Plan(ctx command.ProjectContext) *MockProjectCommandRunner_Plan_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Plan", params, verifier.timeout) return &MockProjectCommandRunner_Plan_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -149,23 +149,23 @@ type MockProjectCommandRunner_Plan_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetCapturedArguments() command.ProjectContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectCommandRunner_Plan_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return } -func (verifier *VerifierMockProjectCommandRunner) Apply(ctx project.Context) *MockProjectCommandRunner_Apply_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Apply(ctx command.ProjectContext) *MockProjectCommandRunner_Apply_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Apply", params, verifier.timeout) return &MockProjectCommandRunner_Apply_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -176,23 +176,23 @@ type MockProjectCommandRunner_Apply_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetCapturedArguments() command.ProjectContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectCommandRunner_Apply_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return } -func (verifier *VerifierMockProjectCommandRunner) PolicyCheck(ctx project.Context) *MockProjectCommandRunner_PolicyCheck_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) *MockProjectCommandRunner_PolicyCheck_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PolicyCheck", params, verifier.timeout) return &MockProjectCommandRunner_PolicyCheck_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -203,23 +203,23 @@ type MockProjectCommandRunner_PolicyCheck_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetCapturedArguments() command.ProjectContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectCommandRunner_PolicyCheck_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return } -func (verifier *VerifierMockProjectCommandRunner) ApprovePolicies(ctx project.Context) *MockProjectCommandRunner_ApprovePolicies_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) *MockProjectCommandRunner_ApprovePolicies_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ApprovePolicies", params, verifier.timeout) return &MockProjectCommandRunner_ApprovePolicies_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -230,23 +230,23 @@ type MockProjectCommandRunner_ApprovePolicies_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetCapturedArguments() command.ProjectContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectCommandRunner_ApprovePolicies_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return } -func (verifier *VerifierMockProjectCommandRunner) Version(ctx project.Context) *MockProjectCommandRunner_Version_OngoingVerification { +func (verifier *VerifierMockProjectCommandRunner) Version(ctx command.ProjectContext) *MockProjectCommandRunner_Version_OngoingVerification { params := []pegomock.Param{ctx} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) return &MockProjectCommandRunner_Version_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -257,17 +257,17 @@ type MockProjectCommandRunner_Version_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandRunner_Version_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectCommandRunner_Version_OngoingVerification) GetCapturedArguments() command.ProjectContext { ctx := c.GetAllCapturedArguments() return ctx[len(ctx)-1] } -func (c *MockProjectCommandRunner_Version_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectCommandRunner_Version_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return diff --git a/server/events/mocks/mock_step_runner.go b/server/events/mocks/mock_step_runner.go index fcdac101c..ff40642bb 100644 --- a/server/events/mocks/mock_step_runner.go +++ b/server/events/mocks/mock_step_runner.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockStepRunner struct { @@ -26,7 +26,7 @@ func NewMockStepRunner(options ...pegomock.Option) *MockStepRunner { func (mock *MockStepRunner) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockStepRunner) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (mock *MockStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockStepRunner().") } @@ -82,7 +82,7 @@ type VerifierMockStepRunner struct { timeout time.Duration } -func (verifier *VerifierMockStepRunner) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) *MockStepRunner_Run_OngoingVerification { +func (verifier *VerifierMockStepRunner) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) *MockStepRunner_Run_OngoingVerification { params := []pegomock.Param{ctx, extraArgs, path, envs} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Run", params, verifier.timeout) return &MockStepRunner_Run_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockStepRunner_Run_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockStepRunner_Run_OngoingVerification) GetCapturedArguments() (project.Context, []string, string, map[string]string) { +func (c *MockStepRunner_Run_OngoingVerification) GetCapturedArguments() (command.ProjectContext, []string, string, map[string]string) { ctx, extraArgs, path, envs := c.GetAllCapturedArguments() return ctx[len(ctx)-1], extraArgs[len(extraArgs)-1], path[len(path)-1], envs[len(envs)-1] } -func (c *MockStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 [][]string, _param2 []string, _param3 []map[string]string) { +func (c *MockStepRunner_Run_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 [][]string, _param2 []string, _param3 []map[string]string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([][]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/events/models/models.go b/server/events/models/models.go index 9626db093..afaaab466 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -24,7 +24,6 @@ import ( "strings" "time" - "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" "github.com/pkg/errors" @@ -225,27 +224,6 @@ type User struct { Username string } -// LockMetadata contains additional data provided to the lock -type LockMetadata struct { - UnixTime int64 -} - -// CommandLock represents a global lock for an atlantis command (plan, apply, policy_check). -// It is used to prevent commands from being executed -type CommandLock struct { - // Time is the time at which the lock was first created. - LockMetadata LockMetadata - CommandName command.Name -} - -func (l *CommandLock) LockTime() time.Time { - return time.Unix(l.LockMetadata.UnixTime, 0) -} - -func (l *CommandLock) IsLocked() bool { - return !l.LockTime().IsZero() -} - // ProjectLock represents a lock on a project. type ProjectLock struct { // Project is the project that is being locked. diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index 248f3a566..7ea0e0304 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -18,7 +18,7 @@ import ( "fmt" "testing" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" . "github.com/runatlantis/atlantis/testing" @@ -359,35 +359,35 @@ func TestAzureDevopsSplitRepoFullName(t *testing.T) { func TestProjectResult_IsSuccessful(t *testing.T) { cases := map[string]struct { - pr project.Result + pr command.ProjectResult exp bool }{ "plan success": { - project.Result{ + command.ProjectResult{ PlanSuccess: &models.PlanSuccess{}, }, true, }, "policy_check success": { - project.Result{ + command.ProjectResult{ PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, true, }, "apply success": { - project.Result{ + command.ProjectResult{ ApplySuccess: "success", }, true, }, "failure": { - project.Result{ + command.ProjectResult{ Failure: "failure", }, false, }, "error": { - project.Result{ + command.ProjectResult{ Error: errors.New("error"), }, false, @@ -403,74 +403,74 @@ func TestProjectResult_IsSuccessful(t *testing.T) { func TestProjectResult_PlanStatus(t *testing.T) { cases := []struct { - p project.Result + p command.ProjectResult expStatus models.ProjectPlanStatus }{ { - p: project.Result{ + p: command.ProjectResult{ Command: command.Plan, Error: errors.New("err"), }, expStatus: models.ErroredPlanStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.Plan, Failure: "failure", }, expStatus: models.ErroredPlanStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.Plan, PlanSuccess: &models.PlanSuccess{}, }, expStatus: models.PlannedPlanStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.Apply, Error: errors.New("err"), }, expStatus: models.ErroredApplyStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.Apply, Failure: "failure", }, expStatus: models.ErroredApplyStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.Apply, ApplySuccess: "success", }, expStatus: models.AppliedPlanStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.PolicyCheck, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.PolicyCheck, Failure: "failure", }, expStatus: models.ErroredPolicyCheckStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.ApprovePolicies, PolicyCheckSuccess: &models.PolicyCheckSuccess{}, }, expStatus: models.PassedPolicyCheckStatus, }, { - p: project.Result{ + p: command.ProjectResult{ Command: command.ApprovePolicies, Failure: "failure", }, @@ -487,11 +487,11 @@ func TestProjectResult_PlanStatus(t *testing.T) { func TestPlanSuccess_Summary(t *testing.T) { cases := []struct { - p project.Result + p command.ProjectResult expResult string }{ { - p: project.Result{ + p: command.ProjectResult{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` An execution plan has been generated and is shown below. @@ -509,7 +509,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", }, { - p: project.Result{ + p: command.ProjectResult{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` An execution plan has been generated and is shown below. @@ -521,7 +521,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "No changes. Infrastructure is up-to-date.", }, { - p: project.Result{ + p: command.ProjectResult{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` Note: Objects have changed outside of Terraform @@ -535,7 +535,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "\n**Note: Objects have changed outside of Terraform**\nNo changes. Your infrastructure matches the configuration.", }, { - p: project.Result{ + p: command.ProjectResult{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: ` Note: Objects have changed outside of Terraform @@ -558,7 +558,7 @@ func TestPlanSuccess_Summary(t *testing.T) { expResult: "\n**Note: Objects have changed outside of Terraform**\nPlan: 0 to add, 0 to change, 1 to destroy.", }, { - p: project.Result{ + p: command.ProjectResult{ PlanSuccess: &models.PlanSuccess{ TerraformOutput: `No match, expect empty`, }, @@ -629,7 +629,7 @@ func TestPolicyCheckCommand_String(t *testing.T) { } func TestUnlockCommand_String(t *testing.T) { - uc := command.UnlockCommand + uc := command.Unlock Equals(t, "unlock", uc.String()) } diff --git a/server/events/plan_command_runner.go b/server/events/plan_command_runner.go index 5b43f4943..58ee51a43 100644 --- a/server/events/plan_command_runner.go +++ b/server/events/plan_command_runner.go @@ -2,7 +2,6 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -219,7 +218,7 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) { } func (p *PlanCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { - if ctx.Trigger == models.Auto { + if ctx.Trigger == command.AutoTrigger { p.runAutoplan(ctx) } else { p.run(ctx, cmd) @@ -266,10 +265,10 @@ func (p *PlanCommandRunner) deletePlans(ctx *command.Context) { func (p *PlanCommandRunner) partitionProjectCmds( ctx *command.Context, - cmds []project.Context, + cmds []command.ProjectContext, ) ( - projectCmds []project.Context, - policyCheckCmds []project.Context, + projectCmds []command.ProjectContext, + policyCheckCmds []command.ProjectContext, ) { for _, cmd := range cmds { switch cmd.CommandName { @@ -284,6 +283,6 @@ func (p *PlanCommandRunner) partitionProjectCmds( return } -func (p *PlanCommandRunner) isParallelEnabled(projectCmds []project.Context) bool { +func (p *PlanCommandRunner) isParallelEnabled(projectCmds []command.ProjectContext) bool { return len(projectCmds) > 0 && projectCmds[0].ParallelPlanEnabled } diff --git a/server/events/policy_check_command_runner.go b/server/events/policy_check_command_runner.go index 6662c469f..f82470b92 100644 --- a/server/events/policy_check_command_runner.go +++ b/server/events/policy_check_command_runner.go @@ -2,7 +2,6 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -35,7 +34,7 @@ type PolicyCheckCommandRunner struct { silenceVCSStatusNoProjects bool } -func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []project.Context) { +func (p *PolicyCheckCommandRunner) Run(ctx *command.Context, cmds []command.ProjectContext) { if len(cmds) == 0 { ctx.Log.Info("no projects to run policy_check in") if !p.silenceVCSStatusNoProjects { @@ -90,6 +89,6 @@ func (p *PolicyCheckCommandRunner) updateCommitStatus(ctx *command.Context, pull } } -func (p *PolicyCheckCommandRunner) isParallelEnabled(cmds []project.Context) bool { +func (p *PolicyCheckCommandRunner) isParallelEnabled(cmds []command.ProjectContext) bool { return len(cmds) > 0 && cmds[0].ParallelPolicyCheckEnabled } diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index cbda6582c..358c3ffd2 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -11,7 +11,6 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/vcs" ) @@ -119,30 +118,30 @@ func NewProjectCommandBuilderWithLimit( type ProjectPlanCommandBuilder interface { // BuildAutoplanCommands builds project commands that will run plan on // the projects determined to be modified. - BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) + BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) // BuildPlanCommands builds project plan commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) + BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) } type ProjectApplyCommandBuilder interface { // BuildApplyCommands builds project Apply commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) + BuildApplyCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) } type ProjectApprovePoliciesCommandBuilder interface { // BuildApprovePoliciesCommands builds project PolicyCheck commands for this ctx and comment. - BuildApprovePoliciesCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) + BuildApprovePoliciesCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) } type ProjectVersionCommandBuilder interface { // BuildVersionCommands builds project Version commands for this ctx and comment. If // comment doesn't specify one project then there may be multiple commands // to be run. - BuildVersionCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) + BuildVersionCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_command_builder.go ProjectCommandBuilder @@ -174,12 +173,12 @@ type DefaultProjectCommandBuilder struct { } // See ProjectCommandBuilder.BuildAutoplanCommands. -func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) { projCtxs, err := p.buildPlanAllCommands(ctx, nil, false, false) if err != nil { return nil, err } - var autoplanEnabled []project.Context + var autoplanEnabled []command.ProjectContext for _, projCtx := range projCtxs { if !projCtx.AutoplanEnabled { ctx.Log.Debug("ignoring project at dir %q, workspace: %q because autoplan is disabled", projCtx.RepoRelDir, projCtx.Workspace) @@ -191,7 +190,7 @@ func (p *DefaultProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Contex } // See ProjectCommandBuilder.BuildPlanCommands. -func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { if !cmd.IsForSpecificProject() { return p.buildPlanAllCommands(ctx, cmd.Flags, cmd.Verbose, cmd.ForceApply) } @@ -200,7 +199,7 @@ func (p *DefaultProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, c } // See ProjectCommandBuilder.BuildApplyCommands. -func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -208,11 +207,11 @@ func (p *DefaultProjectCommandBuilder) BuildApplyCommands(ctx *command.Context, return pac, err } -func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) BuildApprovePoliciesCommands(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { return p.buildAllProjectCommands(ctx, cmd) } -func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { if !cmd.IsForSpecificProject() { return p.buildAllProjectCommands(ctx, cmd) } @@ -222,7 +221,7 @@ func (p *DefaultProjectCommandBuilder) BuildVersionCommands(ctx *command.Context // buildPlanAllCommands builds plan contexts for all projects we determine were // modified in this ctx. -func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context, commentFlags []string, verbose bool, forceApply bool) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context, commentFlags []string, verbose bool, forceApply bool) ([]command.ProjectContext, error) { // We'll need the list of modified files. modifiedFiles, err := p.VCSClient.GetModifiedFiles(ctx.Pull.BaseRepo, ctx.Pull) if err != nil { @@ -249,7 +248,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context ctx.Log.Info("%d projects are changed on MR %q based on their when_modified config", len(matchingProjects), ctx.Pull.Num) if len(matchingProjects) == 0 { ctx.Log.Info("skipping repo clone since no project was modified") - return []project.Context{}, nil + return []command.ProjectContext{}, nil } // NOTE: We discard this work here and end up doing it again after // cloning to ensure all the return values are set properly with @@ -279,7 +278,7 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context return nil, errors.Wrapf(err, "looking for %s file in %q", config.AtlantisYAMLFilename, repoDir) } - var projCtxs []project.Context + var projCtxs []command.ProjectContext if hasRepoCfg { // If there's a repo cfg then we'll use it to figure out which projects @@ -354,13 +353,13 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context // buildProjectPlanCommand builds a plan context for a single project. // cmd must be for only one project. -func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) buildProjectPlanCommand(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var pcc []project.Context + var pcc []command.ProjectContext ctx.Log.Debug("building plan command") unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { @@ -453,7 +452,7 @@ func (p *DefaultProjectCommandBuilder) getCfg(ctx *command.Context, projectName // buildAllProjectCommands builds contexts for a command for every project that has // pending plans in this ctx. -func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Context, commentCmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Context, commentCmd *CommentCommand) ([]command.ProjectContext, error) { // Lock all dirs in this pull request (instead of a single dir) because we // don't know how many dirs we'll need to run the command in. unlockFn, err := p.WorkingDirLocker.TryLockPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num) @@ -479,7 +478,7 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Cont return nil, err } - var cmds []project.Context + var cmds []command.ProjectContext for _, plan := range plans { commentCmds, err := p.buildProjectCommandCtx(ctx, commentCmd.CommandName(), plan.ProjectName, commentCmd.Flags, defaultRepoDir, plan.RepoRelDir, plan.Workspace, commentCmd.Verbose, commentCmd.ForceApply) if err != nil { @@ -492,13 +491,13 @@ func (p *DefaultProjectCommandBuilder) buildAllProjectCommands(ctx *command.Cont // buildProjectApplyCommand builds an apply command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var projCtx []project.Context + var projCtx []command.ProjectContext unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { return projCtx, err @@ -534,13 +533,13 @@ func (p *DefaultProjectCommandBuilder) buildProjectApplyCommand(ctx *command.Con // buildProjectVersionCommand builds a version command for the single project // identified by cmd. -func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.Context, cmd *CommentCommand) ([]project.Context, error) { +func (p *DefaultProjectCommandBuilder) buildProjectVersionCommand(ctx *command.Context, cmd *CommentCommand) ([]command.ProjectContext, error) { workspace := DefaultWorkspace if cmd.Workspace != "" { workspace = cmd.Workspace } - var projCtx []project.Context + var projCtx []command.ProjectContext unlockFn, err := p.WorkingDirLocker.TryLock(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num, workspace) if err != nil { return projCtx, err @@ -584,13 +583,13 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte repoRelDir string, workspace string, verbose bool, - forceApply bool) ([]project.Context, error) { + forceApply bool) ([]command.ProjectContext, error) { matchingProjects, repoCfgPtr, err := p.getCfg(ctx, projectName, repoRelDir, workspace, repoDir) if err != nil { - return []project.Context{}, err + return []command.ProjectContext{}, err } - var projCtxs []project.Context + var projCtxs []command.ProjectContext var projCfg valid.MergedProjectCfg automerge := DefaultAutomergeEnabled parallelApply := DefaultParallelApplyEnabled @@ -652,7 +651,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte } if err := p.validateWorkspaceAllowed(repoCfgPtr, repoRelDir, workspace); err != nil { - return []project.Context{}, err + return []command.ProjectContext{}, err } return projCtxs, nil diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index dd4e0f941..bcadeade2 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -11,7 +11,6 @@ import ( "github.com/runatlantis/atlantis/server/core/config" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/models" vcsmocks "github.com/runatlantis/atlantis/server/events/vcs/mocks" @@ -40,7 +39,7 @@ func TestBuildProjectCmdCtx(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx project.Context + expCtx command.ProjectContext expPlanSteps []string expApplySteps []string }{ @@ -61,7 +60,7 @@ workflows: steps: - apply`, repoCfg: "", - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -113,7 +112,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -167,7 +166,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -229,7 +228,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -378,7 +377,7 @@ workflows: steps: - apply `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -436,7 +435,7 @@ projects: terraform_version: v10.0 workflow: custom `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -497,7 +496,7 @@ workflows: apply: steps: [] `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -542,7 +541,7 @@ projects: - dir: project1 workspace: myworkspace `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -695,7 +694,7 @@ func TestBuildProjectCmdCtx_WithRegExpCmdEnabled(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx project.Context + expCtx command.ProjectContext expPlanSteps []string expApplySteps []string }{ @@ -742,7 +741,7 @@ projects: when_modified: [../modules/**/*.tf] terraform_version: v10.0 `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -p myproject_1", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -892,7 +891,7 @@ func TestBuildProjectCmdCtx_WithPolicCheckEnabled(t *testing.T) { globalCfg string repoCfg string expErr string - expCtx project.Context + expCtx command.ProjectContext expPolicyCheckSteps []string }{ // Test that if we've set global defaults and no project config @@ -903,7 +902,7 @@ repos: - id: /.*/ `, repoCfg: "", - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, @@ -960,7 +959,7 @@ workflows: steps: - policy_check `, - expCtx: project.Context{ + expCtx: command.ProjectContext{ ApplyCmd: "atlantis apply -d project1 -w myworkspace", BaseRepo: baseRepo, EscapedCommentArgs: []string{`\f\l\a\g`}, diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index de72b7841..38da128df 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -12,7 +12,6 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/matchers" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/models" @@ -432,7 +431,7 @@ projects: logger, ) - var actCtxs []project.Context + var actCtxs []command.ProjectContext var err error if cmdName == command.Plan { actCtxs, err = builder.BuildPlanCommands(&command.Context{ @@ -842,7 +841,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { logger, ) - var actCtxs []project.Context + var actCtxs []command.ProjectContext var err error actCtxs, err = builder.BuildPlanCommands(&command.Context{ Log: logger, @@ -1092,7 +1091,7 @@ projects: logger, ) - var actCtxs []project.Context + var actCtxs []command.ProjectContext var err error actCtxs, err = builder.BuildAutoplanCommands(&command.Context{ HeadRepo: models.Repo{}, diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index c8a66dc40..ce2e6c892 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-config-inspect/tfconfig" "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/uber-go/tally" ) @@ -52,7 +51,7 @@ type ProjectCommandContextBuilder interface { commentFlags []string, repoDir string, contextFlags *ContextFlags, - ) []project.Context + ) []command.ProjectContext } // CommandScopedStatsProjectCommandContextBuilder ensures that project command context contains a scoped stats @@ -71,14 +70,14 @@ func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []project.Context) { +) (projectCmds []command.ProjectContext) { cb.ProjectCounter.Inc(1) cmds := cb.ProjectCommandContextBuilder.BuildProjectContext( ctx, cmdName, prjCfg, commentFlags, repoDir, contextFlags, ) - projectCmds = []project.Context{} + projectCmds = []command.ProjectContext{} for _, cmd := range cmds { @@ -103,7 +102,7 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []project.Context) { +) (projectCmds []command.ProjectContext) { ctx.Log.Debug("Building project command context for %s", cmdName) var steps []valid.Step @@ -157,7 +156,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( commentFlags []string, repoDir string, contextFlags *ContextFlags, -) (projectCmds []project.Context) { +) (projectCmds []command.ProjectContext) { ctx.Log.Debug("PolicyChecks are enabled") // If TerraformVersion not defined in config file look for a @@ -212,7 +211,7 @@ func newProjectCommandContext(ctx *command.Context, contextFlags *ContextFlags, scope tally.Scope, pullStatus models.PullReqStatus, -) project.Context { +) command.ProjectContext { var projectPlanStatus models.ProjectPlanStatus @@ -232,7 +231,7 @@ func newProjectCommandContext(ctx *command.Context, } } - return project.Context{ + return command.ProjectContext{ CommandName: cmd, ApplyCmd: applyCmd, BaseRepo: ctx.Pull.BaseRepo, diff --git a/server/events/project_command_pool_executor.go b/server/events/project_command_pool_executor.go index c55605df1..75fa38214 100644 --- a/server/events/project_command_pool_executor.go +++ b/server/events/project_command_pool_executor.go @@ -5,17 +5,16 @@ import ( "github.com/remeh/sizedwaitgroup" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" ) -type prjCmdRunnerFunc func(ctx project.Context) project.Result +type prjCmdRunnerFunc func(ctx command.ProjectContext) command.ProjectResult func runProjectCmdsParallel( - cmds []project.Context, + cmds []command.ProjectContext, runnerFunc prjCmdRunnerFunc, poolSize int, ) command.Result { - var results []project.Result + var results []command.ProjectResult mux := &sync.Mutex{} wg := sizedwaitgroup.New(poolSize) @@ -40,10 +39,10 @@ func runProjectCmdsParallel( } func runProjectCmds( - cmds []project.Context, + cmds []command.ProjectContext, runnerFunc prjCmdRunnerFunc, ) command.Result { - var results []project.Result + var results []command.ProjectResult for _, pCmd := range cmds { res := runnerFunc(pCmd) diff --git a/server/events/project_command_runner.go b/server/events/project_command_runner.go index ec47a96be..34ba448bd 100644 --- a/server/events/project_command_runner.go +++ b/server/events/project_command_runner.go @@ -23,7 +23,6 @@ import ( "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/webhooks" "github.com/runatlantis/atlantis/server/logging" @@ -56,7 +55,7 @@ type LockURLGenerator interface { // `terraform plan`. type StepRunner interface { // Run runs the step. - Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) + Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_custom_step_runner.go CustomStepRunner @@ -64,14 +63,14 @@ type StepRunner interface { // CustomStepRunner runs custom run steps. type CustomStepRunner interface { // Run cmd in path. - Run(ctx project.Context, cmd string, path string, envs map[string]string) (string, error) + Run(ctx command.ProjectContext, cmd string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_env_step_runner.go EnvStepRunner // EnvStepRunner runs env steps. type EnvStepRunner interface { - Run(ctx project.Context, cmd string, value string, path string, envs map[string]string) (string, error) + Run(ctx command.ProjectContext, cmd string, value string, path string, envs map[string]string) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_webhooks_sender.go WebhooksSender @@ -86,27 +85,27 @@ type WebhooksSender interface { type ProjectPlanCommandRunner interface { // Plan runs terraform plan for the project described by ctx. - Plan(ctx project.Context) project.Result + Plan(ctx command.ProjectContext) command.ProjectResult } type ProjectApplyCommandRunner interface { // Apply runs terraform apply for the project described by ctx. - Apply(ctx project.Context) project.Result + Apply(ctx command.ProjectContext) command.ProjectResult } type ProjectPolicyCheckCommandRunner interface { // PolicyCheck runs OPA defined policies for the project desribed by ctx. - PolicyCheck(ctx project.Context) project.Result + PolicyCheck(ctx command.ProjectContext) command.ProjectResult } type ProjectApprovePoliciesCommandRunner interface { // Approves any failing OPA policies. - ApprovePolicies(ctx project.Context) project.Result + ApprovePolicies(ctx command.ProjectContext) command.ProjectResult } type ProjectVersionCommandRunner interface { // Version runs terraform version for the project described by ctx. - Version(ctx project.Context) project.Result + Version(ctx command.ProjectContext) command.ProjectResult } // ProjectCommandRunner runs project commands. A project command is a command @@ -124,7 +123,7 @@ type ProjectCommandRunner interface { type JobURLSetter interface { // SetJobURLWithStatus sets the commit status for the project represented by // ctx and updates the status with and url to a job. - SetJobURLWithStatus(ctx project.Context, cmdName command.Name, status models.CommitStatus) error + SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus) error } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_job_closer.go JobCloser @@ -142,19 +141,19 @@ type ProjectOutputWrapper struct { JobCloser JobCloser } -func (p *ProjectOutputWrapper) Plan(ctx project.Context) project.Result { +func (p *ProjectOutputWrapper) Plan(ctx command.ProjectContext) command.ProjectResult { result := p.updateProjectPRStatus(command.Plan, ctx, p.ProjectCommandRunner.Plan) p.JobCloser.CloseJob(ctx.JobID) return result } -func (p *ProjectOutputWrapper) Apply(ctx project.Context) project.Result { +func (p *ProjectOutputWrapper) Apply(ctx command.ProjectContext) command.ProjectResult { result := p.updateProjectPRStatus(command.Apply, ctx, p.ProjectCommandRunner.Apply) p.JobCloser.CloseJob(ctx.JobID) return result } -func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx project.Context, execute func(ctx project.Context) project.Result) project.Result { +func (p *ProjectOutputWrapper) updateProjectPRStatus(commandName command.Name, ctx command.ProjectContext, execute func(ctx command.ProjectContext) command.ProjectResult) command.ProjectResult { // Create a PR status to track project's plan status. The status will // include a link to view the progress of atlantis plan command in real // time @@ -185,7 +184,7 @@ type FeatureAwareProjectCommandRunner struct { FeatureAllocator feature.Allocator } -func (f *FeatureAwareProjectCommandRunner) Apply(ctx project.Context) project.Result { +func (f *FeatureAwareProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { return f.ProjectCommandRunner.Apply(ctx) } @@ -209,9 +208,9 @@ type DefaultProjectCommandRunner struct { //create object and test } // Plan runs terraform plan for the project described by ctx. -func (p *DefaultProjectCommandRunner) Plan(ctx project.Context) project.Result { +func (p *DefaultProjectCommandRunner) Plan(ctx command.ProjectContext) command.ProjectResult { planSuccess, failure, err := p.doPlan(ctx) - return project.Result{ + return command.ProjectResult{ Command: command.Plan, PlanSuccess: planSuccess, Error: err, @@ -223,9 +222,9 @@ func (p *DefaultProjectCommandRunner) Plan(ctx project.Context) project.Result { } // PolicyCheck evaluates policies defined with Rego for the project described by ctx. -func (p *DefaultProjectCommandRunner) PolicyCheck(ctx project.Context) project.Result { +func (p *DefaultProjectCommandRunner) PolicyCheck(ctx command.ProjectContext) command.ProjectResult { policySuccess, failure, err := p.doPolicyCheck(ctx) - return project.Result{ + return command.ProjectResult{ Command: command.PolicyCheck, PolicyCheckSuccess: policySuccess, Error: err, @@ -237,9 +236,9 @@ func (p *DefaultProjectCommandRunner) PolicyCheck(ctx project.Context) project.R } // Apply runs terraform apply for the project described by ctx. -func (p *DefaultProjectCommandRunner) Apply(ctx project.Context) project.Result { +func (p *DefaultProjectCommandRunner) Apply(ctx command.ProjectContext) command.ProjectResult { applyOut, failure, err := p.doApply(ctx) - return project.Result{ + return command.ProjectResult{ Command: command.Apply, Failure: failure, Error: err, @@ -250,9 +249,9 @@ func (p *DefaultProjectCommandRunner) Apply(ctx project.Context) project.Result } } -func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx project.Context) project.Result { +func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx command.ProjectContext) command.ProjectResult { approvedOut, failure, err := p.doApprovePolicies(ctx) - return project.Result{ + return command.ProjectResult{ Command: command.PolicyCheck, Failure: failure, Error: err, @@ -263,9 +262,9 @@ func (p *DefaultProjectCommandRunner) ApprovePolicies(ctx project.Context) proje } } -func (p *DefaultProjectCommandRunner) Version(ctx project.Context) project.Result { +func (p *DefaultProjectCommandRunner) Version(ctx command.ProjectContext) command.ProjectResult { versionOut, failure, err := p.doVersion(ctx) - return project.Result{ + return command.ProjectResult{ Command: command.Version, Failure: failure, Error: err, @@ -276,7 +275,7 @@ func (p *DefaultProjectCommandRunner) Version(ctx project.Context) project.Resul } } -func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx project.Context) (*models.PolicyCheckSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx command.ProjectContext) (*models.PolicyCheckSuccess, string, error) { // TODO: Make this a bit smarter // without checking some sort of state that the policy check has indeed passed this is likely to cause issues @@ -286,7 +285,7 @@ func (p *DefaultProjectCommandRunner) doApprovePolicies(ctx project.Context) (*m }, "", nil } -func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx project.Context) (*models.PolicyCheckSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx command.ProjectContext) (*models.PolicyCheckSuccess, string, error) { // Acquire Atlantis lock for this repo/dir/workspace. // This should already be acquired from the prior plan operation. // if for some reason an unlock happens between the plan and policy check step @@ -357,7 +356,7 @@ func (p *DefaultProjectCommandRunner) doPolicyCheck(ctx project.Context) (*model }, "", nil } -func (p *DefaultProjectCommandRunner) doPlan(ctx project.Context) (*models.PlanSuccess, string, error) { +func (p *DefaultProjectCommandRunner) doPlan(ctx command.ProjectContext) (*models.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.Pull.BaseRepo.FullName, ctx.RepoRelDir)) if err != nil { @@ -406,7 +405,7 @@ func (p *DefaultProjectCommandRunner) doPlan(ctx project.Context) (*models.PlanS }, "", nil } -func (p *DefaultProjectCommandRunner) doApply(ctx project.Context) (applyOut string, failure string, err error) { +func (p *DefaultProjectCommandRunner) doApply(ctx command.ProjectContext) (applyOut string, failure string, err error) { repoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, ctx.Workspace) if err != nil { if os.IsNotExist(err) { @@ -450,7 +449,7 @@ func (p *DefaultProjectCommandRunner) doApply(ctx project.Context) (applyOut str return strings.Join(outputs, "\n"), "", nil } -func (p *DefaultProjectCommandRunner) doVersion(ctx project.Context) (versionOut string, failure string, err error) { +func (p *DefaultProjectCommandRunner) doVersion(ctx command.ProjectContext) (versionOut string, failure string, err error) { repoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, ctx.Workspace) if err != nil { if os.IsNotExist(err) { @@ -478,7 +477,7 @@ func (p *DefaultProjectCommandRunner) doVersion(ctx project.Context) (versionOut return strings.Join(outputs, "\n"), "", nil } -func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx project.Context, absPath string) ([]string, error) { +func (p *DefaultProjectCommandRunner) runSteps(steps []valid.Step, ctx command.ProjectContext, absPath string) ([]string, error) { var outputs []string envs := make(map[string]string) diff --git a/server/events/project_command_runner_test.go b/server/events/project_command_runner_test.go index 0f12719e8..91c16a614 100644 --- a/server/events/project_command_runner_test.go +++ b/server/events/project_command_runner_test.go @@ -26,7 +26,6 @@ import ( tmocks "github.com/runatlantis/atlantis/server/core/terraform/mocks" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" eventmocks "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" @@ -84,7 +83,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) { expEnvs := map[string]string{ "name": "value", } - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -135,7 +134,7 @@ func TestDefaultProjectCommandRunner_Plan(t *testing.T) { func TestProjectOutputWrapper(t *testing.T) { RegisterMockTestingT(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -187,7 +186,7 @@ func TestProjectOutputWrapper(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - var prjResult project.Result + var prjResult command.ProjectResult var expCommitStatus models.CommitStatus mockJobURLSetter := eventmocks.NewMockJobURLSetter() @@ -201,18 +200,18 @@ func TestProjectOutputWrapper(t *testing.T) { } if c.Success { - prjResult = project.Result{ + prjResult = command.ProjectResult{ PlanSuccess: &models.PlanSuccess{}, ApplySuccess: "exists", } expCommitStatus = models.SuccessCommitStatus } else if c.Failure { - prjResult = project.Result{ + prjResult = command.ProjectResult{ Failure: "failure", } expCommitStatus = models.FailedCommitStatus } else if c.Error { - prjResult = project.Result{ + prjResult = command.ProjectResult{ Error: errors.New("error"), } expCommitStatus = models.FailedCommitStatus @@ -248,7 +247,7 @@ func TestDefaultProjectCommandRunner_ApplyNotCloned(t *testing.T) { runner := &events.DefaultProjectCommandRunner{ WorkingDir: mockWorkingDir, } - ctx := project.Context{} + ctx := command.ProjectContext{} When(mockWorkingDir.GetWorkingDir(ctx.BaseRepo, ctx.Pull, ctx.Workspace)).ThenReturn("", os.ErrNotExist) res := runner.Apply(ctx) @@ -268,7 +267,7 @@ func TestDefaultProjectCommandRunner_ApplyNotApproved(t *testing.T) { }, Webhooks: mockSender, } - ctx := project.Context{ + ctx := command.ProjectContext{ ApplyRequirements: []string{"approved"}, PullReqStatus: models.PullReqStatus{ ApprovalStatus: models.ApprovalStatus{ @@ -296,7 +295,7 @@ func TestDefaultProjectCommandRunner_ForceOverridesApplyReqs(t *testing.T) { }, Webhooks: mockSender, } - ctx := project.Context{ + ctx := command.ProjectContext{ PullReqStatus: models.PullReqStatus{ ApprovalStatus: models.ApprovalStatus{ IsApproved: false, @@ -328,7 +327,7 @@ func TestFeatureAwareProjectCommandRunner_ForceOverrideWhenEnabled(t *testing.T) featureAwareRunner := &events.FeatureAwareProjectCommandRunner{ ProjectCommandRunner: runner, } - ctx := project.Context{ + ctx := command.ProjectContext{ ApplyRequirements: []string{"approved"}, ForceApply: true, PullReqStatus: models.PullReqStatus{ @@ -357,7 +356,7 @@ func TestDefaultProjectCommandRunner_ApplyNotMergeable(t *testing.T) { WorkingDir: mockWorkingDir, }, } - ctx := project.Context{ + ctx := command.ProjectContext{ PullReqStatus: models.PullReqStatus{ Mergeable: false, }, @@ -382,7 +381,7 @@ func TestDefaultProjectCommandRunner_ApplyDiverged(t *testing.T) { WorkingDir: mockWorkingDir, }, } - ctx := project.Context{ + ctx := command.ProjectContext{ ApplyRequirements: []string{"undiverged"}, } tmp, cleanup := TempDir(t) @@ -508,7 +507,7 @@ func TestDefaultProjectCommandRunner_Apply(t *testing.T) { AnyString(), )).ThenReturn(repoDir, nil) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Steps: c.steps, Workspace: "default", @@ -580,7 +579,7 @@ func TestDefaultProjectCommandRunner_ApplyRunStepFailure(t *testing.T) { AnyString(), )).ThenReturn(repoDir, nil) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { @@ -649,7 +648,7 @@ func TestDefaultProjectCommandRunner_RunEnvSteps(t *testing.T) { LockKey: "lock-key", }, nil) - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logging.NewNoopLogger(t), Steps: []valid.Step{ { diff --git a/server/events/pull_closed_executor_test.go b/server/events/pull_closed_executor_test.go index cae9e57c7..c231091dc 100644 --- a/server/events/pull_closed_executor_test.go +++ b/server/events/pull_closed_executor_test.go @@ -27,7 +27,7 @@ import ( . "github.com/petergtz/pegomock" lockmocks "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -202,7 +202,7 @@ func TestCleanUpLogStreaming(t *testing.T) { prjCmdOutput := make(chan *jobs.ProjectCmdOutputLine) storageBackend := jobmocks.NewMockStorageBackend() prjCmdOutHandler := jobs.NewAsyncProjectCommandOutputHandler(prjCmdOutput, logger, jobs.NewJobStore(storageBackend)) - ctx := project.Context{ + ctx := command.ProjectContext{ BaseRepo: fixtures.GithubRepo, Pull: fixtures.Pull, ProjectName: *fixtures.Project.Name, @@ -238,7 +238,7 @@ func TestCleanUpLogStreaming(t *testing.T) { panic(errors.Wrap(err, "could not create bucket")) } db, _ := db.NewWithDB(boltDB, lockBucket, configBucket) - result := []project.Result{ + result := []command.ProjectResult{ { RepoRelDir: fixtures.GithubRepo.FullName, Workspace: "default", diff --git a/server/events/pull_updater.go b/server/events/pull_updater.go index 34b68ada4..d526bcbd6 100644 --- a/server/events/pull_updater.go +++ b/server/events/pull_updater.go @@ -13,7 +13,7 @@ type PullUpdater struct { GlobalCfg valid.GlobalCfg } -func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res command.Result) { +func (c *PullUpdater) updatePull(ctx *command.Context, cmd PullCommand, res command.Result) { // Log if we got any errors or failures. if res.Error != nil { ctx.Log.Err(res.Error.Error()) @@ -25,7 +25,7 @@ func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res // clutter in a pull/merge request. This will not delete the comment, since the // comment trail may be useful in auditing or backtracing problems. if c.HidePrevPlanComments { - if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, command.Name().TitleString()); err != nil { + if err := c.VCSClient.HidePrevCommandComments(ctx.Pull.BaseRepo, ctx.Pull.Num, cmd.CommandName().TitleString()); err != nil { ctx.Log.Err("unable to hide old comments: %s", err) } } @@ -36,8 +36,8 @@ func (c *PullUpdater) updatePull(ctx *command.Context, command PullCommand, res templateOverrides = repoCfg.TemplateOverrides } - comment := c.MarkdownRenderer.Render(res, command.Name(), ctx.Log.GetHistory(), command.IsVerbose(), ctx.Pull.BaseRepo.VCSHost.Type, templateOverrides) - if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, comment, command.Name().String()); err != nil { + comment := c.MarkdownRenderer.Render(res, cmd.CommandName(), ctx.Log.GetHistory(), cmd.IsVerbose(), ctx.Pull.BaseRepo.VCSHost.Type, templateOverrides) + if err := c.VCSClient.CreateComment(ctx.Pull.BaseRepo, ctx.Pull.Num, comment, cmd.CommandName().String()); err != nil { ctx.Log.Err("unable to comment: %s", err) } } diff --git a/server/events/size_limited_project_command_builder.go b/server/events/size_limited_project_command_builder.go index af96c6f07..575de7c52 100644 --- a/server/events/size_limited_project_command_builder.go +++ b/server/events/size_limited_project_command_builder.go @@ -5,7 +5,6 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" ) type SizeLimitedProjectCommandBuilder struct { @@ -13,7 +12,7 @@ type SizeLimitedProjectCommandBuilder struct { ProjectCommandBuilder } -func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]project.Context, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Context) ([]command.ProjectContext, error) { projects, err := b.ProjectCommandBuilder.BuildAutoplanCommands(ctx) if err != nil { @@ -23,7 +22,7 @@ func (b *SizeLimitedProjectCommandBuilder) BuildAutoplanCommands(ctx *command.Co return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]project.Context, error) { +func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Context, comment *CommentCommand) ([]command.ProjectContext, error) { projects, err := b.ProjectCommandBuilder.BuildPlanCommands(ctx, comment) if err != nil { @@ -33,9 +32,9 @@ func (b *SizeLimitedProjectCommandBuilder) BuildPlanCommands(ctx *command.Contex return projects, b.CheckAgainstLimit(projects) } -func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []project.Context) error { +func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []command.ProjectContext) error { - var planCommands []project.Context + var planCommands []command.ProjectContext for _, project := range projects { diff --git a/server/events/size_limited_project_command_builder_test.go b/server/events/size_limited_project_command_builder_test.go index 77073498e..be7462ae5 100644 --- a/server/events/size_limited_project_command_builder_test.go +++ b/server/events/size_limited_project_command_builder_test.go @@ -6,7 +6,6 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/mocks" . "github.com/runatlantis/atlantis/testing" ) @@ -18,22 +17,22 @@ func TestSizeLimitedProjectCommandBuilder_autoplan(t *testing.T) { ctx := &command.Context{} - project1 := project.Context{ + project1 := command.ProjectContext{ ProjectName: "test1", CommandName: command.Plan, } - project2 := project.Context{ + project2 := command.ProjectContext{ ProjectName: "test2", CommandName: command.Plan, } - project3 := project.Context{ + project3 := command.ProjectContext{ ProjectName: "test1", CommandName: command.PolicyCheck, } - expectedResult := []project.Context{project1, project2} + expectedResult := []command.ProjectContext{project1, project2} t.Run("Limit Defined and Breached", func(t *testing.T) { subject := &events.SizeLimitedProjectCommandBuilder{ @@ -88,7 +87,7 @@ Please break this pull request into smaller batches and try again.`, err) ProjectCommandBuilder: delegate, } - resultWithPolicyCheckCommand := []project.Context{project1, project2, project3} + resultWithPolicyCheckCommand := []command.ProjectContext{project1, project2, project3} When(delegate.BuildAutoplanCommands(ctx)).ThenReturn(resultWithPolicyCheckCommand, nil) @@ -109,17 +108,17 @@ func TestSizeLimitedProjectCommandBuilder_planComment(t *testing.T) { comment := &events.CommentCommand{} - project1 := project.Context{ + project1 := command.ProjectContext{ ProjectName: "test1", CommandName: command.Plan, } - project2 := project.Context{ + project2 := command.ProjectContext{ ProjectName: "test2", CommandName: command.Plan, } - expectedResult := []project.Context{project1, project2} + expectedResult := []command.ProjectContext{project1, project2} t.Run("Limit Defined and Breached", func(t *testing.T) { subject := &events.SizeLimitedProjectCommandBuilder{ diff --git a/server/events/unlock_command_runner.go b/server/events/unlock_command_runner.go index bf8e6aca7..1a7407397 100644 --- a/server/events/unlock_command_runner.go +++ b/server/events/unlock_command_runner.go @@ -44,7 +44,7 @@ func (u *UnlockCommandRunner) Run( return } - if commentErr := u.vcsClient.CreateComment(baseRepo, pullNum, vcsMessage, command.UnlockCommand.String()); commentErr != nil { + if commentErr := u.vcsClient.CreateComment(baseRepo, pullNum, vcsMessage, command.Unlock.String()); commentErr != nil { ctx.Log.Err("unable to comment: %s", commentErr) } } diff --git a/server/events/version_command_runner.go b/server/events/version_command_runner.go index 20c973b13..101ba2857 100644 --- a/server/events/version_command_runner.go +++ b/server/events/version_command_runner.go @@ -2,7 +2,6 @@ package events import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" ) func NewVersionCommandRunner( @@ -33,7 +32,7 @@ type VersionCommandRunner struct { func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { var err error - var projectCmds []project.Context + var projectCmds []command.ProjectContext projectCmds, err = v.prjCmdBuilder.BuildVersionCommands(ctx, cmd) if err != nil { ctx.Log.Warn("Error %s", err) @@ -56,6 +55,6 @@ func (v *VersionCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) { v.pullUpdater.updatePull(ctx, cmd, result) } -func (v *VersionCommandRunner) isParallelEnabled(cmds []project.Context) bool { +func (v *VersionCommandRunner) isParallelEnabled(cmds []command.ProjectContext) bool { return len(cmds) > 0 && cmds[0].ParallelPolicyCheckEnabled } diff --git a/server/jobs/job_url_setter.go b/server/jobs/job_url_setter.go index 2eba7ff66..02af4c661 100644 --- a/server/jobs/job_url_setter.go +++ b/server/jobs/job_url_setter.go @@ -2,7 +2,6 @@ package jobs import ( "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" "github.com/runatlantis/atlantis/server/events/models" ) @@ -10,7 +9,7 @@ import ( // ProjectJobURLGenerator generates urls to view project's progress. type ProjectJobURLGenerator interface { - GenerateProjectJobURL(p project.Context) (string, error) + GenerateProjectJobURL(p command.ProjectContext) (string, error) } //go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_project_status_updater.go ProjectStatusUpdater @@ -18,7 +17,7 @@ type ProjectJobURLGenerator interface { type ProjectStatusUpdater interface { // UpdateProject sets the commit status for the project represented by // ctx. - UpdateProject(ctx project.Context, cmdName command.Name, status models.CommitStatus, url string) error + UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string) error } type JobURLSetter struct { @@ -33,7 +32,7 @@ func NewJobURLSetter(projectJobURLGenerator ProjectJobURLGenerator, projectStatu } } -func (j *JobURLSetter) SetJobURLWithStatus(ctx project.Context, cmdName command.Name, status models.CommitStatus) error { +func (j *JobURLSetter) SetJobURLWithStatus(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus) error { url, err := j.projectJobURLGenerator.GenerateProjectJobURL(ctx) if err != nil { diff --git a/server/jobs/mocks/matchers/models_projectcommandcontext.go b/server/jobs/mocks/matchers/models_projectcommandcontext.go index 93d072cb5..90db05bac 100644 --- a/server/jobs/mocks/matchers/models_projectcommandcontext.go +++ b/server/jobs/mocks/matchers/models_projectcommandcontext.go @@ -5,29 +5,29 @@ import ( "reflect" "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) -func AnyModelsProjectCommandContext() project.Context { - pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(project.Context))(nil)).Elem())) - var nullValue project.Context +func AnyModelsProjectCommandContext() command.ProjectContext { + pegomock.RegisterMatcher(pegomock.NewAnyMatcher(reflect.TypeOf((*(command.ProjectContext))(nil)).Elem())) + var nullValue command.ProjectContext return nullValue } -func EqModelsProjectCommandContext(value project.Context) project.Context { +func EqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.EqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func NotEqModelsProjectCommandContext(value project.Context) project.Context { +func NotEqModelsProjectCommandContext(value command.ProjectContext) command.ProjectContext { pegomock.RegisterMatcher(&pegomock.NotEqMatcher{Value: value}) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } -func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) project.Context { +func ModelsProjectCommandContextThat(matcher pegomock.ArgumentMatcher) command.ProjectContext { pegomock.RegisterMatcher(matcher) - var nullValue project.Context + var nullValue command.ProjectContext return nullValue } diff --git a/server/jobs/mocks/mock_project_command_output_handler.go b/server/jobs/mocks/mock_project_command_output_handler.go index 9be526169..6bf0491d7 100644 --- a/server/jobs/mocks/mock_project_command_output_handler.go +++ b/server/jobs/mocks/mock_project_command_output_handler.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" jobs "github.com/runatlantis/atlantis/server/jobs" ) @@ -59,7 +59,7 @@ func (mock *MockProjectCommandOutputHandler) Register(_param0 string, _param1 ch pegomock.GetGenericMockFrom(mock).Invoke("Register", params, []reflect.Type{}) } -func (mock *MockProjectCommandOutputHandler) Send(_param0 project.Context, _param1 string) { +func (mock *MockProjectCommandOutputHandler) Send(_param0 command.ProjectContext, _param1 string) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectCommandOutputHandler().") } @@ -206,7 +206,7 @@ func (c *MockProjectCommandOutputHandler_Register_OngoingVerification) GetAllCap return } -func (verifier *VerifierMockProjectCommandOutputHandler) Send(_param0 project.Context, _param1 string) *MockProjectCommandOutputHandler_Send_OngoingVerification { +func (verifier *VerifierMockProjectCommandOutputHandler) Send(_param0 command.ProjectContext, _param1 string) *MockProjectCommandOutputHandler_Send_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Send", params, verifier.timeout) return &MockProjectCommandOutputHandler_Send_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -217,17 +217,17 @@ type MockProjectCommandOutputHandler_Send_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetCapturedArguments() (project.Context, string) { +func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetCapturedArguments() (command.ProjectContext, string) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []string) { +func (c *MockProjectCommandOutputHandler_Send_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]string, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/jobs/mocks/mock_project_job_url_generator.go b/server/jobs/mocks/mock_project_job_url_generator.go index 073b3da00..88d7e530f 100644 --- a/server/jobs/mocks/mock_project_job_url_generator.go +++ b/server/jobs/mocks/mock_project_job_url_generator.go @@ -8,7 +8,7 @@ import ( "time" pegomock "github.com/petergtz/pegomock" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) type MockProjectJobURLGenerator struct { @@ -26,7 +26,7 @@ func NewMockProjectJobURLGenerator(options ...pegomock.Option) *MockProjectJobUR func (mock *MockProjectJobURLGenerator) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectJobURLGenerator) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectJobURLGenerator) GenerateProjectJobURL(_param0 project.Context) (string, error) { +func (mock *MockProjectJobURLGenerator) GenerateProjectJobURL(_param0 command.ProjectContext) (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectJobURLGenerator().") } @@ -82,7 +82,7 @@ type VerifierMockProjectJobURLGenerator struct { timeout time.Duration } -func (verifier *VerifierMockProjectJobURLGenerator) GenerateProjectJobURL(_param0 project.Context) *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification { +func (verifier *VerifierMockProjectJobURLGenerator) GenerateProjectJobURL(_param0 command.ProjectContext) *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification { params := []pegomock.Param{_param0} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GenerateProjectJobURL", params, verifier.timeout) return &MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -93,17 +93,17 @@ type MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification struct methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetCapturedArguments() project.Context { +func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetCapturedArguments() command.ProjectContext { _param0 := c.GetAllCapturedArguments() return _param0[len(_param0)-1] } -func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context) { +func (c *MockProjectJobURLGenerator_GenerateProjectJobURL_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } } return diff --git a/server/jobs/mocks/mock_project_status_updater.go b/server/jobs/mocks/mock_project_status_updater.go index 7167ebe15..2284b26a3 100644 --- a/server/jobs/mocks/mock_project_status_updater.go +++ b/server/jobs/mocks/mock_project_status_updater.go @@ -9,7 +9,6 @@ import ( pegomock "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/events/command" - "github.com/runatlantis/atlantis/server/events/command/project" models "github.com/runatlantis/atlantis/server/events/models" ) @@ -28,7 +27,7 @@ func NewMockProjectStatusUpdater(options ...pegomock.Option) *MockProjectStatusU func (mock *MockProjectStatusUpdater) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh } func (mock *MockProjectStatusUpdater) FailHandler() pegomock.FailHandler { return mock.fail } -func (mock *MockProjectStatusUpdater) UpdateProject(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus, _param3 string) error { +func (mock *MockProjectStatusUpdater) UpdateProject(_param0 command.ProjectContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockProjectStatusUpdater().") } @@ -80,7 +79,7 @@ type VerifierMockProjectStatusUpdater struct { timeout time.Duration } -func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 project.Context, _param1 command.Name, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { +func (verifier *VerifierMockProjectStatusUpdater) UpdateProject(_param0 command.ProjectContext, _param1 command.Name, _param2 models.CommitStatus, _param3 string) *MockProjectStatusUpdater_UpdateProject_OngoingVerification { params := []pegomock.Param{_param0, _param1, _param2, _param3} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout) return &MockProjectStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} @@ -91,17 +90,17 @@ type MockProjectStatusUpdater_UpdateProject_OngoingVerification struct { methodInvocations []pegomock.MethodInvocation } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (project.Context, command.Name, models.CommitStatus, string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArguments() (command.ProjectContext, command.Name, models.CommitStatus, string) { _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] } -func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []project.Context, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { +func (c *MockProjectStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { - _param0 = make([]project.Context, len(c.methodInvocations)) + _param0 = make([]command.ProjectContext, len(c.methodInvocations)) for u, param := range params[0] { - _param0[u] = param.(project.Context) + _param0[u] = param.(command.ProjectContext) } _param1 = make([]command.Name, len(c.methodInvocations)) for u, param := range params[1] { diff --git a/server/jobs/project_command_output_handler.go b/server/jobs/project_command_output_handler.go index 22d03405d..823a31483 100644 --- a/server/jobs/project_command_output_handler.go +++ b/server/jobs/project_command_output_handler.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" ) @@ -35,7 +35,7 @@ type ProjectCmdOutputLine struct { type ProjectCommandOutputHandler interface { // Send will enqueue the msg and wait for Handle() to receive the message. - Send(ctx project.Context, msg string) + Send(ctx command.ProjectContext, msg string) // Listens for msg from channel Handle() @@ -82,7 +82,7 @@ func NewAsyncProjectCommandOutputHandler( } } -func (p *AsyncProjectCommandOutputHandler) Send(ctx project.Context, msg string) { +func (p *AsyncProjectCommandOutputHandler) Send(ctx command.ProjectContext, msg string) { p.projectCmdOutput <- &ProjectCmdOutputLine{ JobID: ctx.JobID, JobInfo: JobInfo{ @@ -191,7 +191,7 @@ func (p *AsyncProjectCommandOutputHandler) GetJobIdMapForPull(pullInfo PullInfo) // NoopProjectOutputHandler is a mock that doesn't do anything type NoopProjectOutputHandler struct{} -func (p *NoopProjectOutputHandler) Send(ctx project.Context, msg string) { +func (p *NoopProjectOutputHandler) Send(ctx command.ProjectContext, msg string) { } func (p *NoopProjectOutputHandler) Handle() { diff --git a/server/jobs/project_command_output_handler_test.go b/server/jobs/project_command_output_handler_test.go index c61114b5c..ccf02f1c4 100644 --- a/server/jobs/project_command_output_handler_test.go +++ b/server/jobs/project_command_output_handler_test.go @@ -8,7 +8,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/stretchr/testify/assert" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/jobs" "github.com/runatlantis/atlantis/server/jobs/mocks" @@ -17,9 +17,9 @@ import ( . "github.com/runatlantis/atlantis/testing" ) -func createTestProjectCmdContext(t *testing.T) project.Context { +func createTestProjectCmdContext(t *testing.T) command.ProjectContext { logger := logging.NewNoopLogger(t) - return project.Context{ + return command.ProjectContext{ BaseRepo: models.Repo{ Name: "test-repo", Owner: "test-org", diff --git a/server/lyft/decorators/audit_project_commands_wrapper.go b/server/lyft/decorators/audit_project_commands_wrapper.go index 313748197..ade7c2495 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper.go +++ b/server/lyft/decorators/audit_project_commands_wrapper.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/lyft/aws/sns" ) @@ -38,7 +38,7 @@ type AuditProjectCommandWrapper struct { events.ProjectCommandRunner } -func (p *AuditProjectCommandWrapper) Apply(ctx project.Context) project.Result { +func (p *AuditProjectCommandWrapper) Apply(ctx command.ProjectContext) command.ProjectResult { id := uuid.New() startTime := strconv.FormatInt(time.Now().Unix(), 10) @@ -59,7 +59,7 @@ func (p *AuditProjectCommandWrapper) Apply(ctx project.Context) project.Result { if err := p.emit(ctx, AtlantisJobStateRunning, atlantisJobEvent); err != nil { // return an error if we are not able to write to sns - return project.Result{ + return command.ProjectResult{ Error: errors.Wrap(err, "emitting atlantis job event"), } } @@ -82,7 +82,7 @@ func (p *AuditProjectCommandWrapper) Apply(ctx project.Context) project.Result { } func (p *AuditProjectCommandWrapper) emit( - ctx project.Context, + ctx command.ProjectContext, state AtlantisJobState, atlantisJobEvent *AtlantisJobEvent, ) error { diff --git a/server/lyft/decorators/audit_project_commands_wrapper_test.go b/server/lyft/decorators/audit_project_commands_wrapper_test.go index dfde97bbe..0b4397c0a 100644 --- a/server/lyft/decorators/audit_project_commands_wrapper_test.go +++ b/server/lyft/decorators/audit_project_commands_wrapper_test.go @@ -9,7 +9,7 @@ import ( . "github.com/petergtz/pegomock" "github.com/runatlantis/atlantis/server/core/config/valid" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/mocks" "github.com/runatlantis/atlantis/server/events/mocks/matchers" "github.com/runatlantis/atlantis/server/events/models" @@ -51,7 +51,7 @@ func TestAuditProjectCommandsWrapper(t *testing.T) { ProjectCommandRunner: projectCmdRunnerMock, } - prjRslt := project.Result{} + prjRslt := command.ProjectResult{} if c.Error { prjRslt.Error = errors.New("oh-no") @@ -65,7 +65,7 @@ func TestAuditProjectCommandsWrapper(t *testing.T) { scope, _, _ := metrics.NewLoggingScope(logger, "atlantis") - ctx := project.Context{ + ctx := command.ProjectContext{ Scope: scope, Log: logger, Steps: []valid.Step{}, diff --git a/server/lyft/decorators/destroy_plan_step_runner_wrapper.go b/server/lyft/decorators/destroy_plan_step_runner_wrapper.go index a628875d7..952f8962a 100644 --- a/server/lyft/decorators/destroy_plan_step_runner_wrapper.go +++ b/server/lyft/decorators/destroy_plan_step_runner_wrapper.go @@ -2,7 +2,7 @@ package decorators import ( "github.com/runatlantis/atlantis/server/events" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) const Deprecated = "deprecated" @@ -12,7 +12,7 @@ type DestroyPlanStepRunnerWrapper struct { events.StepRunner } -func (d *DestroyPlanStepRunnerWrapper) Run(ctx project.Context, extraArgs []string, path string, envs map[string]string) (string, error) { +func (d *DestroyPlanStepRunnerWrapper) Run(ctx command.ProjectContext, extraArgs []string, path string, envs map[string]string) (string, error) { // DestroyPlan tag is true when the Terraform client should construct a destroy plan given a repo config. if ctx.Tags[Deprecated] == Destroy { extraArgs = append(extraArgs, Destroy) diff --git a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go index 972ba5f8a..716c3179b 100644 --- a/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go +++ b/server/lyft/decorators/destroy_plan_step_runner_wrapper_test.go @@ -10,7 +10,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime" "github.com/runatlantis/atlantis/server/core/terraform/mocks" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/logging" "github.com/runatlantis/atlantis/server/lyft/decorators" @@ -101,7 +101,7 @@ func TestRun_DestroyPlan(t *testing.T) { stepRunner := decorators.DestroyPlanStepRunnerWrapper{ StepRunner: &planStepRunner, } - ctx := project.Context{ + ctx := command.ProjectContext{ Log: logger, Workspace: "workspace", RepoRelDir: ".", diff --git a/server/router.go b/server/router.go index 538f11572..ce480e256 100644 --- a/server/router.go +++ b/server/router.go @@ -6,7 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" ) // Router can be used to retrieve Atlantis URLs. It acts as an intermediary @@ -39,7 +39,7 @@ func (r *Router) GenerateLockURL(lockID string) string { return r.AtlantisURL.String() + lockURL.String() } -func (r *Router) GenerateProjectJobURL(ctx project.Context) (string, error) { +func (r *Router) GenerateProjectJobURL(ctx command.ProjectContext) (string, error) { if ctx.JobID == "" { return "", fmt.Errorf("no job id in ctx") } diff --git a/server/router_test.go b/server/router_test.go index 371c42fc2..4b683e07c 100644 --- a/server/router_test.go +++ b/server/router_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/uuid" "github.com/gorilla/mux" "github.com/runatlantis/atlantis/server" - "github.com/runatlantis/atlantis/server/events/command/project" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" . "github.com/runatlantis/atlantis/testing" "github.com/stretchr/testify/assert" @@ -83,7 +83,7 @@ func setupJobsRouter(t *testing.T) *server.Router { func TestGenerateProjectJobURL_ShouldGenerateURLWhenJobIDSpecified(t *testing.T) { router := setupJobsRouter(t) jobID := uuid.New().String() - ctx := project.Context{ + ctx := command.ProjectContext{ JobID: jobID, } expectedURL := fmt.Sprintf("http://localhost:4141/jobs/%s", jobID) @@ -95,7 +95,7 @@ func TestGenerateProjectJobURL_ShouldGenerateURLWhenJobIDSpecified(t *testing.T) func TestGenerateProjectJobURL_ShouldReturnErrorWhenJobIDNotSpecified(t *testing.T) { router := setupJobsRouter(t) - ctx := project.Context{ + ctx := command.ProjectContext{ Pull: models.PullRequest{ BaseRepo: models.Repo{ Owner: "test-owner", diff --git a/server/server.go b/server/server.go index e2d147c74..51ad43005 100644 --- a/server/server.go +++ b/server/server.go @@ -57,6 +57,7 @@ import ( "github.com/runatlantis/atlantis/server/core/runtime/policy" "github.com/runatlantis/atlantis/server/core/terraform" "github.com/runatlantis/atlantis/server/events" + "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/events/vcs/bitbucketcloud" @@ -712,7 +713,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { command.Plan: planCommandRunner, command.Apply: applyCommandRunner, command.ApprovePolicies: approvePoliciesCommandRunner, - command.UnlockCommand: unlockCommandRunner, + command.Unlock: unlockCommandRunner, command.Version: versionCommandRunner, } cmdStatsScope := statsScope.SubScope("cmd") @@ -740,11 +741,10 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { StaleCommandChecker: staleCommandChecker, } - featureAwareCommandRunner := &events.FeatureAwareCommandRunner{ - CommandRunner: commandRunner, - FeatureAllocator: featureAllocator, - VCSClient: vcsClient, - Logger: logger, + forceApplyCommandRunner := &events.ForceApplyCommandRunner{ + CommandRunner: commandRunner, + VCSClient: vcsClient, + Logger: logger, } repoAllowlist, err := events.NewRepoAllowlistChecker(userConfig.RepoAllowlist) @@ -785,7 +785,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { } eventsController := &events_controllers.VCSEventsController{ - CommandRunner: featureAwareCommandRunner, + CommandRunner: forceApplyCommandRunner, PullCleaner: pullClosedExecutor, Parser: eventParser, CommentParser: commentParser, From 346b5301ddce39abf0d5e1490efdc02d0244d9ef Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Fri, 25 Feb 2022 12:34:43 -0800 Subject: [PATCH 6/7] revert unrelated code --- server/events/command_runner.go | 10 ++++++---- server/events/command_runner_test.go | 11 ++++++----- server/server.go | 11 ++++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/server/events/command_runner.go b/server/events/command_runner.go index fe3e2deb1..743a9d4f5 100644 --- a/server/events/command_runner.go +++ b/server/events/command_runner.go @@ -27,6 +27,7 @@ import ( "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/logging" + "github.com/runatlantis/atlantis/server/lyft/feature" "github.com/runatlantis/atlantis/server/recovery" "github.com/uber-go/tally" gitlab "github.com/xanzy/go-gitlab" @@ -390,13 +391,14 @@ func (c *DefaultCommandRunner) logPanics(baseRepo models.Repo, pullNum int, logg var automergeComment = `Automatically merging because all plans have been successfully applied.` -type ForceApplyCommandRunner struct { +type FeatureAwareCommandRunner struct { CommandRunner - Logger logging.SimpleLogging - VCSClient vcs.Client + FeatureAllocator feature.Allocator + Logger logging.SimpleLogging + VCSClient vcs.Client } -func (f *ForceApplyCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, cmd *CommentCommand, timestamp time.Time) { +func (f *FeatureAwareCommandRunner) RunCommentCommand(baseRepo models.Repo, maybeHeadRepo *models.Repo, maybePull *models.PullRequest, user models.User, pullNum int, cmd *CommentCommand, timestamp time.Time) { if cmd.ForceApply { warningMessage := "⚠️ WARNING ⚠️\n\n You have bypassed all apply requirements for this PR 🚀 . This can have unpredictable consequences 🙏🏽 and should only be used in an emergency 🆘 .\n\n 𝐓𝐡𝐢𝐬 𝐚𝐜𝐭𝐢𝐨𝐧 𝐰𝐢𝐥𝐥 𝐛𝐞 𝐚𝐮𝐝𝐢𝐭𝐞𝐝.\n" if commentErr := f.VCSClient.CreateComment(baseRepo, pullNum, warningMessage, ""); commentErr != nil { diff --git a/server/events/command_runner_test.go b/server/events/command_runner_test.go index 82c46d06b..b67e15599 100644 --- a/server/events/command_runner_test.go +++ b/server/events/command_runner_test.go @@ -51,7 +51,7 @@ var azuredevopsGetter *mocks.MockAzureDevopsPullGetter var githubGetter *mocks.MockGithubPullGetter var gitlabGetter *mocks.MockGitlabMergeRequestGetter var ch events.DefaultCommandRunner -var fa events.ForceApplyCommandRunner +var fa events.FeatureAwareCommandRunner var workingDir events.WorkingDir var pendingPlanFinder *mocks.MockPendingPlanFinder var drainer *events.Drainer @@ -400,10 +400,11 @@ func TestFeatureAwareRunCommentCommandRunner_CommentWhenEnabled(t *testing.T) { vcsClient := setup(t) allocator := fmocks.NewMockAllocator() - fa = events.ForceApplyCommandRunner{ - CommandRunner: &ch, - VCSClient: vcsClient, - Logger: logger, + fa = events.FeatureAwareCommandRunner{ + CommandRunner: &ch, + FeatureAllocator: fa.FeatureAllocator, + VCSClient: vcsClient, + Logger: logger, } modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num} diff --git a/server/server.go b/server/server.go index 51ad43005..fc612cb45 100644 --- a/server/server.go +++ b/server/server.go @@ -741,10 +741,11 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { StaleCommandChecker: staleCommandChecker, } - forceApplyCommandRunner := &events.ForceApplyCommandRunner{ - CommandRunner: commandRunner, - VCSClient: vcsClient, - Logger: logger, + featureAwareCommandRunner := &events.FeatureAwareCommandRunner{ + CommandRunner: commandRunner, + FeatureAllocator: featureAllocator, + VCSClient: vcsClient, + Logger: logger, } repoAllowlist, err := events.NewRepoAllowlistChecker(userConfig.RepoAllowlist) @@ -785,7 +786,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { } eventsController := &events_controllers.VCSEventsController{ - CommandRunner: forceApplyCommandRunner, + CommandRunner: featureAwareCommandRunner, PullCleaner: pullClosedExecutor, Parser: eventParser, CommentParser: commentParser, From eb78b4a4d6fcb91ae684076e083be80b5b51d019 Mon Sep 17 00:00:00 2001 From: Sarvar Muminov Date: Fri, 25 Feb 2022 18:05:51 -0800 Subject: [PATCH 7/7] move tests --- server/events/command/name_test.go | 32 +++ server/events/command/project_result_test.go | 227 +++++++++++++++++ server/events/models/models_test.go | 244 ------------------- 3 files changed, 259 insertions(+), 244 deletions(-) create mode 100644 server/events/command/name_test.go create mode 100644 server/events/command/project_result_test.go diff --git a/server/events/command/name_test.go b/server/events/command/name_test.go new file mode 100644 index 000000000..6f766000c --- /dev/null +++ b/server/events/command/name_test.go @@ -0,0 +1,32 @@ +package command_test + +import ( + "testing" + + "github.com/runatlantis/atlantis/server/events/command" + . "github.com/runatlantis/atlantis/testing" +) + +func TestApplyCommand_String(t *testing.T) { + uc := command.Apply + + Equals(t, "apply", uc.String()) +} + +func TestPlanCommand_String(t *testing.T) { + uc := command.Plan + + Equals(t, "plan", uc.String()) +} + +func TestPolicyCheckCommand_String(t *testing.T) { + uc := command.PolicyCheck + + Equals(t, "policy_check", uc.String()) +} + +func TestUnlockCommand_String(t *testing.T) { + uc := command.Unlock + + Equals(t, "unlock", uc.String()) +} diff --git a/server/events/command/project_result_test.go b/server/events/command/project_result_test.go new file mode 100644 index 000000000..cd1e7bb67 --- /dev/null +++ b/server/events/command/project_result_test.go @@ -0,0 +1,227 @@ +package command_test + +import ( + "errors" + "testing" + + "github.com/runatlantis/atlantis/server/events/command" + "github.com/runatlantis/atlantis/server/events/models" + . "github.com/runatlantis/atlantis/testing" +) + +func TestProjectResult_IsSuccessful(t *testing.T) { + cases := map[string]struct { + pr command.ProjectResult + exp bool + }{ + "plan success": { + command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{}, + }, + true, + }, + "policy_check success": { + command.ProjectResult{ + PolicyCheckSuccess: &models.PolicyCheckSuccess{}, + }, + true, + }, + "apply success": { + command.ProjectResult{ + ApplySuccess: "success", + }, + true, + }, + "failure": { + command.ProjectResult{ + Failure: "failure", + }, + false, + }, + "error": { + command.ProjectResult{ + Error: errors.New("error"), + }, + false, + }, + } + + for name, c := range cases { + t.Run(name, func(t *testing.T) { + Equals(t, c.exp, c.pr.IsSuccessful()) + }) + } +} + +func TestProjectResult_PlanStatus(t *testing.T) { + cases := []struct { + p command.ProjectResult + expStatus models.ProjectPlanStatus + }{ + { + p: command.ProjectResult{ + Command: command.Plan, + Error: errors.New("err"), + }, + expStatus: models.ErroredPlanStatus, + }, + { + p: command.ProjectResult{ + Command: command.Plan, + Failure: "failure", + }, + expStatus: models.ErroredPlanStatus, + }, + { + p: command.ProjectResult{ + Command: command.Plan, + PlanSuccess: &models.PlanSuccess{}, + }, + expStatus: models.PlannedPlanStatus, + }, + { + p: command.ProjectResult{ + Command: command.Apply, + Error: errors.New("err"), + }, + expStatus: models.ErroredApplyStatus, + }, + { + p: command.ProjectResult{ + Command: command.Apply, + Failure: "failure", + }, + expStatus: models.ErroredApplyStatus, + }, + { + p: command.ProjectResult{ + Command: command.Apply, + ApplySuccess: "success", + }, + expStatus: models.AppliedPlanStatus, + }, + { + p: command.ProjectResult{ + Command: command.PolicyCheck, + PolicyCheckSuccess: &models.PolicyCheckSuccess{}, + }, + expStatus: models.PassedPolicyCheckStatus, + }, + { + p: command.ProjectResult{ + Command: command.PolicyCheck, + Failure: "failure", + }, + expStatus: models.ErroredPolicyCheckStatus, + }, + { + p: command.ProjectResult{ + Command: command.ApprovePolicies, + PolicyCheckSuccess: &models.PolicyCheckSuccess{}, + }, + expStatus: models.PassedPolicyCheckStatus, + }, + { + p: command.ProjectResult{ + Command: command.ApprovePolicies, + Failure: "failure", + }, + expStatus: models.ErroredPolicyCheckStatus, + }, + } + + for _, c := range cases { + t.Run(c.expStatus.String(), func(t *testing.T) { + Equals(t, c.expStatus, c.p.PlanStatus()) + }) + } +} + +func TestPlanSuccess_Summary(t *testing.T) { + cases := []struct { + p command.ProjectResult + expResult string + }{ + { + p: command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + An execution plan has been generated and is shown below. + Resource actions are indicated with the following symbols: + - destroy + + Terraform will perform the following actions: + + - null_resource.hi[1] + + + Plan: 0 to add, 0 to change, 1 to destroy.`, + }, + }, + expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", + }, + { + p: command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + An execution plan has been generated and is shown below. + Resource actions are indicated with the following symbols: + + No changes. Infrastructure is up-to-date.`, + }, + }, + expResult: "No changes. Infrastructure is up-to-date.", + }, + { + p: command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + Note: Objects have changed outside of Terraform + + Terraform detected the following changes made outside of Terraform since the + last "terraform apply": + + No changes. Your infrastructure matches the configuration.`, + }, + }, + expResult: "\n**Note: Objects have changed outside of Terraform**\nNo changes. Your infrastructure matches the configuration.", + }, + { + p: command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: ` + Note: Objects have changed outside of Terraform + + Terraform detected the following changes made outside of Terraform since the + last "terraform apply": + + An execution plan has been generated and is shown below. + Resource actions are indicated with the following symbols: + - destroy + + Terraform will perform the following actions: + + - null_resource.hi[1] + + + Plan: 0 to add, 0 to change, 1 to destroy.`, + }, + }, + expResult: "\n**Note: Objects have changed outside of Terraform**\nPlan: 0 to add, 0 to change, 1 to destroy.", + }, + { + p: command.ProjectResult{ + PlanSuccess: &models.PlanSuccess{ + TerraformOutput: `No match, expect empty`, + }, + }, + expResult: "", + }, + } + + for _, c := range cases { + t.Run(c.expResult, func(t *testing.T) { + Equals(t, c.expResult, c.p.PlanSuccess.Summary()) + }) + } +} diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index 7ea0e0304..7aea621b2 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -14,11 +14,9 @@ package models_test import ( - "errors" "fmt" "testing" - "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/events/vcs" . "github.com/runatlantis/atlantis/testing" @@ -356,224 +354,6 @@ func TestAzureDevopsSplitRepoFullName(t *testing.T) { }) } } - -func TestProjectResult_IsSuccessful(t *testing.T) { - cases := map[string]struct { - pr command.ProjectResult - exp bool - }{ - "plan success": { - command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{}, - }, - true, - }, - "policy_check success": { - command.ProjectResult{ - PolicyCheckSuccess: &models.PolicyCheckSuccess{}, - }, - true, - }, - "apply success": { - command.ProjectResult{ - ApplySuccess: "success", - }, - true, - }, - "failure": { - command.ProjectResult{ - Failure: "failure", - }, - false, - }, - "error": { - command.ProjectResult{ - Error: errors.New("error"), - }, - false, - }, - } - - for name, c := range cases { - t.Run(name, func(t *testing.T) { - Equals(t, c.exp, c.pr.IsSuccessful()) - }) - } -} - -func TestProjectResult_PlanStatus(t *testing.T) { - cases := []struct { - p command.ProjectResult - expStatus models.ProjectPlanStatus - }{ - { - p: command.ProjectResult{ - Command: command.Plan, - Error: errors.New("err"), - }, - expStatus: models.ErroredPlanStatus, - }, - { - p: command.ProjectResult{ - Command: command.Plan, - Failure: "failure", - }, - expStatus: models.ErroredPlanStatus, - }, - { - p: command.ProjectResult{ - Command: command.Plan, - PlanSuccess: &models.PlanSuccess{}, - }, - expStatus: models.PlannedPlanStatus, - }, - { - p: command.ProjectResult{ - Command: command.Apply, - Error: errors.New("err"), - }, - expStatus: models.ErroredApplyStatus, - }, - { - p: command.ProjectResult{ - Command: command.Apply, - Failure: "failure", - }, - expStatus: models.ErroredApplyStatus, - }, - { - p: command.ProjectResult{ - Command: command.Apply, - ApplySuccess: "success", - }, - expStatus: models.AppliedPlanStatus, - }, - { - p: command.ProjectResult{ - Command: command.PolicyCheck, - PolicyCheckSuccess: &models.PolicyCheckSuccess{}, - }, - expStatus: models.PassedPolicyCheckStatus, - }, - { - p: command.ProjectResult{ - Command: command.PolicyCheck, - Failure: "failure", - }, - expStatus: models.ErroredPolicyCheckStatus, - }, - { - p: command.ProjectResult{ - Command: command.ApprovePolicies, - PolicyCheckSuccess: &models.PolicyCheckSuccess{}, - }, - expStatus: models.PassedPolicyCheckStatus, - }, - { - p: command.ProjectResult{ - Command: command.ApprovePolicies, - Failure: "failure", - }, - expStatus: models.ErroredPolicyCheckStatus, - }, - } - - for _, c := range cases { - t.Run(c.expStatus.String(), func(t *testing.T) { - Equals(t, c.expStatus, c.p.PlanStatus()) - }) - } -} - -func TestPlanSuccess_Summary(t *testing.T) { - cases := []struct { - p command.ProjectResult - expResult string - }{ - { - p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` - An execution plan has been generated and is shown below. - Resource actions are indicated with the following symbols: - - destroy - - Terraform will perform the following actions: - - - null_resource.hi[1] - - - Plan: 0 to add, 0 to change, 1 to destroy.`, - }, - }, - expResult: "Plan: 0 to add, 0 to change, 1 to destroy.", - }, - { - p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` - An execution plan has been generated and is shown below. - Resource actions are indicated with the following symbols: - - No changes. Infrastructure is up-to-date.`, - }, - }, - expResult: "No changes. Infrastructure is up-to-date.", - }, - { - p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` - Note: Objects have changed outside of Terraform - - Terraform detected the following changes made outside of Terraform since the - last "terraform apply": - - No changes. Your infrastructure matches the configuration.`, - }, - }, - expResult: "\n**Note: Objects have changed outside of Terraform**\nNo changes. Your infrastructure matches the configuration.", - }, - { - p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: ` - Note: Objects have changed outside of Terraform - - Terraform detected the following changes made outside of Terraform since the - last "terraform apply": - - An execution plan has been generated and is shown below. - Resource actions are indicated with the following symbols: - - destroy - - Terraform will perform the following actions: - - - null_resource.hi[1] - - - Plan: 0 to add, 0 to change, 1 to destroy.`, - }, - }, - expResult: "\n**Note: Objects have changed outside of Terraform**\nPlan: 0 to add, 0 to change, 1 to destroy.", - }, - { - p: command.ProjectResult{ - PlanSuccess: &models.PlanSuccess{ - TerraformOutput: `No match, expect empty`, - }, - }, - expResult: "", - }, - } - - for _, c := range cases { - t.Run(c.expResult, func(t *testing.T) { - Equals(t, c.expResult, c.p.PlanSuccess.Summary()) - }) - } -} - func TestPullStatus_StatusCount(t *testing.T) { ps := models.PullStatus{ Projects: []models.ProjectStatus{ @@ -609,27 +389,3 @@ func TestPullStatus_StatusCount(t *testing.T) { Equals(t, 1, ps.StatusCount(models.ErroredPolicyCheckStatus)) Equals(t, 1, ps.StatusCount(models.PassedPolicyCheckStatus)) } - -func TestApplyCommand_String(t *testing.T) { - uc := command.Apply - - Equals(t, "apply", uc.String()) -} - -func TestPlanCommand_String(t *testing.T) { - uc := command.Plan - - Equals(t, "plan", uc.String()) -} - -func TestPolicyCheckCommand_String(t *testing.T) { - uc := command.PolicyCheck - - Equals(t, "policy_check", uc.String()) -} - -func TestUnlockCommand_String(t *testing.T) { - uc := command.Unlock - - Equals(t, "unlock", uc.String()) -}