Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved CommandContext and CommandResult to command package #193

Merged
merged 7 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 *command.Context) ([]command.ProjectContext, error)
}
```

Expand Down
13 changes: 7 additions & 6 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1050,12 +1051,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.Unlock: unlockCommandRunner,
command.Version: versionCommandRunner,
}
staleCommandChecker := mocks.NewMockStaleCommandChecker()
commandRunner := &events.DefaultCommandRunner{
Expand Down
15 changes: 8 additions & 7 deletions server/controllers/events/events_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/controllers/events/mocks/matchers/slice_of_byte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/controllers/events/mocks/mock_vcs_post_handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions server/controllers/locks_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -302,9 +303,9 @@ 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, []command.ProjectResult{
{
Command: models.PlanCommand,
Command: command.Plan,
RepoRelDir: projectPath,
Workspace: workspaceName,
PlanSuccess: &models.PlanSuccess{
Expand Down
3 changes: 2 additions & 1 deletion server/controllers/templates/mocks/matchers/io_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/controllers/templates/mocks/mock_template_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r RepoCfg) ValidatePRWorkflows(workflows map[string]Workflow, allowedWorkf
return err
}
}

if len(allowedWorkflows) == 0 {
return nil
}
Expand Down
19 changes: 10 additions & 9 deletions server/core/db/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -173,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 models.CommandName, 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(),
},
}
Expand Down Expand Up @@ -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)

Expand All @@ -224,8 +225,8 @@ 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) {
cmdLock := models.CommandLock{}
func (b *BoltDB) CheckCommandLock(cmdName command.Name) (*command.Lock, error) {
cmdLock := command.Lock{}

found := false

Expand Down Expand Up @@ -312,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 []models.ProjectResult) (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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -482,7 +483,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 command.ProjectResult) models.ProjectStatus {
return models.ProjectStatus{
Workspace: p.Workspace,
RepoRelDir: p.RepoRelDir,
Expand Down
Loading