Skip to content

Commit cd37563

Browse files
authored
Merge pull request #1159 from runatlantis/disable-autoplan
Disable autoplan global flag
2 parents 0a67abb + 1b374fa commit cd37563

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

cmd/server.go

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
DataDirFlag = "data-dir"
5454
DefaultTFVersionFlag = "default-tf-version"
5555
DisableApplyAllFlag = "disable-apply-all"
56+
DisableAutoplanFlag = "disable-autoplan"
5657
DisableMarkdownFoldingFlag = "disable-markdown-folding"
5758
GHHostnameFlag = "gh-hostname"
5859
GHTokenFlag = "gh-token"
@@ -275,6 +276,10 @@ var boolFlags = map[string]boolFlag{
275276
description: "Disable \"atlantis apply\" command so a specific project/workspace/directory has to be specified for applies.",
276277
defaultValue: false,
277278
},
279+
DisableAutoplanFlag: {
280+
description: "Disable atlantis auto planning feature",
281+
defaultValue: false,
282+
},
278283
AllowDraftPRs: {
279284
description: "Enable autoplan for Github Draft Pull Requests",
280285
defaultValue: false,

cmd/server_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var testFlags = map[string]interface{}{
9595
TFETokenFlag: "my-token",
9696
VCSStatusName: "my-status",
9797
WriteGitCredsFlag: true,
98+
DisableAutoplanFlag: true,
9899
}
99100

100101
func TestExecute_Defaults(t *testing.T) {

runatlantis.io/docs/server-configuration.md

+6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ Values are chosen in this order:
208208
Disable \"atlantis apply\" command so a specific project/workspace/directory has to
209209
be specified for applies.
210210

211+
* ### `--disable-autoplan`
212+
```bash
213+
atlantis server --disable-autoplan
214+
```
215+
Disable atlantis auto planning
216+
211217
* ### `--gh-hostname`
212218
```bash
213219
atlantis server --gh-hostname="my.github.enterprise.com"

server/events/command_runner.go

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type DefaultCommandRunner struct {
7676
GitlabMergeRequestGetter GitlabMergeRequestGetter
7777
CommitStatusUpdater CommitStatusUpdater
7878
DisableApplyAll bool
79+
DisableAutoplan bool
7980
EventParser EventParsing
8081
MarkdownRenderer *MarkdownRenderer
8182
Logger logging.SimpleLogging
@@ -130,6 +131,9 @@ func (c *DefaultCommandRunner) RunAutoplanCommand(baseRepo models.Repo, headRepo
130131
if !c.validateCtxAndComment(ctx) {
131132
return
132133
}
134+
if c.DisableAutoplan {
135+
return
136+
}
133137

134138
projectCmds, err := c.ProjectCommandBuilder.BuildAutoplanCommands(ctx)
135139
if err != nil {

server/events/command_runner_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ func TestRunCommentCommand_DisableApplyAllDisabled(t *testing.T) {
196196
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.", "apply")
197197
}
198198

199+
func TestRunCommentCommand_DisableDisableAutoplan(t *testing.T) {
200+
t.Log("if \"DisableAutoplan is true\" are disabled and we are silencing return and do not comment with error")
201+
setup(t)
202+
ch.DisableAutoplan = true
203+
defer func() { ch.DisableAutoplan = false }()
204+
205+
When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())).
206+
ThenReturn([]models.ProjectCommandContext{
207+
{},
208+
{},
209+
}, nil)
210+
211+
ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User)
212+
projectCommandBuilder.VerifyWasCalled(Never()).BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())
213+
}
214+
199215
func TestRunCommentCommand_ClosedPull(t *testing.T) {
200216
t.Log("if a command is run on a closed pull request atlantis should" +
201217
" comment saying that this is not allowed")

server/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
369369
SilenceForkPRErrorsFlag: config.SilenceForkPRErrorsFlag,
370370
SilenceVCSStatusNoPlans: userConfig.SilenceVCSStatusNoPlans,
371371
DisableApplyAll: userConfig.DisableApplyAll,
372+
DisableAutoplan: userConfig.DisableAutoplan,
372373
ProjectCommandBuilder: &events.DefaultProjectCommandBuilder{
373374
ParserValidator: validator,
374375
ProjectFinder: &events.DefaultProjectFinder{},

server/user_config.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type UserConfig struct {
2323
CheckoutStrategy string `mapstructure:"checkout-strategy"`
2424
DataDir string `mapstructure:"data-dir"`
2525
DisableApplyAll bool `mapstructure:"disable-apply-all"`
26+
DisableAutoplan bool `mapstructure:"disable-autoplan"`
2627
DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"`
2728
GithubHostname string `mapstructure:"gh-hostname"`
2829
GithubToken string `mapstructure:"gh-token"`

0 commit comments

Comments
 (0)