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

Adding support to disable autoplan from server config #1071

Closed
Closed
Changes from 2 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
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ const (
DataDirFlag = "data-dir"
DefaultTFVersionFlag = "default-tf-version"
DisableApplyAllFlag = "disable-apply-all"
DisableAutoPlanFlag = "disable-auto-plan"
DisableMarkdownFoldingFlag = "disable-markdown-folding"
GHHostnameFlag = "gh-hostname"
GHTokenFlag = "gh-token"
@@ -254,6 +255,10 @@ var boolFlags = map[string]boolFlag{
description: "Disable \"atlantis apply\" command so a specific project/workspace/directory has to be specified for applies.",
defaultValue: false,
},
DisableAutoPlanFlag: {
description: "Disable atlantis auto planning feature",
defaultValue: false,
},
AllowDraftPRs: {
description: "Enable autoplan for Github Draft Pull Requests",
defaultValue: false,
7 changes: 7 additions & 0 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
@@ -206,6 +206,13 @@ Values are chosen in this order:
Disable \"atlantis apply\" command so a specific project/workspace/directory has to
be specified for applies.

* ### `--disable-auto-plan`
```bash
atlantis server --disable-auto-plan
```
Disable atlantis auto planning


* ### `--gh-hostname`
```bash
atlantis server --gh-hostname="my.github.enterprise.com"
4 changes: 4 additions & 0 deletions server/events/command_runner.go
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ type DefaultCommandRunner struct {
GitlabMergeRequestGetter GitlabMergeRequestGetter
CommitStatusUpdater CommitStatusUpdater
DisableApplyAll bool
DisableAutoPlan bool
EventParser EventParsing
MarkdownRenderer *MarkdownRenderer
Logger logging.SimpleLogging
@@ -129,6 +130,9 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo
if !c.validateCtxAndComment(ctx) {
return
}
if c.DisableAutoPlan {
return
}

projectCmds, err := c.ProjectCommandBuilder.BuildAutoplanCommands(ctx)
if err != nil {
16 changes: 16 additions & 0 deletions server/events/command_runner_test.go
Original file line number Diff line number Diff line change
@@ -185,6 +185,22 @@ func TestRunCommentCommand_DisableApplyAllDisabled(t *testing.T) {
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 <dir>`, `-w <workspace>` or `-p <project name>` flags.")
}

func TestRunCommentCommand_DisableDisableAutoPlan(t *testing.T) {
t.Log("if \"DisableAutoPlan is true\" are disabled and we are silencing return and do not comment with error")
setup(t)
ch.DisableAutoPlan = true
defer func() { ch.DisableAutoPlan = false }()

When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())).
ThenReturn([]models.ProjectCommandContext{
{},
{},
}, nil)

ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User)
projectCommandBuilder.VerifyWasCalled(Never()).BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())
}

func TestRunCommentCommand_ClosedPull(t *testing.T) {
t.Log("if a command is run on a closed pull request atlantis should" +
" comment saying that this is not allowed")
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -331,6 +331,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
SilenceForkPRErrorsFlag: config.SilenceForkPRErrorsFlag,
SilenceVCSStatusNoPlans: userConfig.SilenceVCSStatusNoPlans,
DisableApplyAll: userConfig.DisableApplyAll,
DisableAutoPlan: userConfig.DisableAutoPlan,
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
ParserValidator: validator,
ProjectFinder: &events.DefaultProjectFinder{},
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ type UserConfig struct {
CheckoutStrategy string `mapstructure:"checkout-strategy"`
DataDir string `mapstructure:"data-dir"`
DisableApplyAll bool `mapstructure:"disable-apply-all"`
DisableAutoPlan bool `mapstructure:"disable-auto-plan"`
DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"`
GithubHostname string `mapstructure:"gh-hostname"`
GithubToken string `mapstructure:"gh-token"`