Skip to content

Commit 7275a0d

Browse files
pkaramoljamengual
authored andcommitted
Using constants for checkout strategies (runatlantis#3384)
Co-authored-by: PePe Amengual <[email protected]>
1 parent 6b6c794 commit 7275a0d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

cmd/server.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ import (
3333
"github.com/runatlantis/atlantis/server/logging"
3434
)
3535

36+
// checkout strategies
37+
const (
38+
CheckoutStrategyBranch = "branch"
39+
CheckoutStrategyMerge = "merge"
40+
)
41+
3642
// To add a new flag you must:
3743
// 1. Add a const with the flag name (in alphabetic order).
3844
// 2. Add a new field to server.UserConfig and set the mapstructure tag equal to the flag name.
@@ -141,7 +147,7 @@ const (
141147
DefaultADHostname = "dev.azure.com"
142148
DefaultAutoplanFileList = "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl"
143149
DefaultAllowCommands = "version,plan,apply,unlock,approve_policies"
144-
DefaultCheckoutStrategy = "branch"
150+
DefaultCheckoutStrategy = CheckoutStrategyBranch
145151
DefaultCheckoutDepth = 0
146152
DefaultBitbucketBaseURL = bitbucketcloud.BaseURL
147153
DefaultDataDir = "~/.atlantis"
@@ -545,7 +551,7 @@ var boolFlags = map[string]boolFlag{
545551
}
546552
var intFlags = map[string]intFlag{
547553
CheckoutDepthFlag: {
548-
description: fmt.Sprintf("Used only if --%s=merge.", CheckoutStrategyFlag) +
554+
description: fmt.Sprintf("Used only if --%s=%s.", CheckoutStrategyFlag, CheckoutStrategyMerge) +
549555
" How many commits to include in each of base and feature branches when cloning repository." +
550556
" If merge base is further behind than this number of commits from any of branches heads, full fetch will be performed.",
551557
defaultValue: DefaultCheckoutDepth,
@@ -852,8 +858,9 @@ func (s *ServerCmd) validate(userConfig server.UserConfig) error {
852858
}
853859

854860
checkoutStrategy := userConfig.CheckoutStrategy
855-
if checkoutStrategy != "branch" && checkoutStrategy != "merge" {
856-
return errors.New("invalid checkout strategy: not one of branch or merge")
861+
if checkoutStrategy != CheckoutStrategyBranch && checkoutStrategy != CheckoutStrategyMerge {
862+
return fmt.Errorf("invalid checkout strategy: not one of %s or %s",
863+
CheckoutStrategyBranch, CheckoutStrategyMerge)
857864
}
858865

859866
if (userConfig.SSLKeyFile == "") != (userConfig.SSLCertFile == "") {

cmd/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var testFlags = map[string]interface{}{
6666
BitbucketTokenFlag: "bitbucket-token",
6767
BitbucketUserFlag: "bitbucket-user",
6868
BitbucketWebhookSecretFlag: "bitbucket-secret",
69-
CheckoutStrategyFlag: "merge",
69+
CheckoutStrategyFlag: CheckoutStrategyMerge,
7070
DataDirFlag: "/path",
7171
DefaultTFVersionFlag: "v0.11.0",
7272
DisableApplyAllFlag: true,

0 commit comments

Comments
 (0)