Skip to content

Commit 325dda2

Browse files
authored
Merge branch 'main' into github-mergeability-fix
2 parents ebb3e19 + e6e7c91 commit 325dda2

17 files changed

+294
-117
lines changed

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- name: 'Checkout code'
23-
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424
with:
2525
persist-credentials: false
2626
show-progress: false

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG GOLANG_TAG=1.23.0-alpine@sha256:d0b31558e6b3e4cc59f6011d79905835108c919143eb
77
# renovate: datasource=github-releases depName=hashicorp/terraform versioning=hashicorp
88
ARG DEFAULT_TERRAFORM_VERSION=1.9.8
99
# renovate: datasource=github-releases depName=opentofu/opentofu versioning=hashicorp
10-
ARG DEFAULT_OPENTOFU_VERSION=1.8.3
10+
ARG DEFAULT_OPENTOFU_VERSION=1.8.4
1111
# renovate: datasource=github-releases depName=open-policy-agent/conftest
1212
ARG DEFAULT_CONFTEST_VERSION=0.56.0
1313

runatlantis.io/docs/automerging.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ Automerging can be enabled either by:
2929
If automerge is enabled, you can disable it for a single `atlantis apply`
3030
command with the `--auto-merge-disabled` option.
3131

32+
## How to set the merge method for automerge
33+
34+
If automerge is enabled, you can use the `--auto-merge-method` option
35+
for the `atlantis apply` command to specify which merge method use.
36+
37+
```shell
38+
atlantis apply --auto-merge-method <method>
39+
```
40+
41+
The `method` must be one of:
42+
43+
- merge
44+
- rebase
45+
- squash
46+
47+
This is currently only implemented for the GitHub VCS.
48+
3249
## Requirements
3350

3451
### All Plans Must Succeed

runatlantis.io/docs/using-atlantis.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ atlantis apply -w staging
149149
* `-p project` Apply the plan for this project. Refers to the name of the project configured in the repo's [`atlantis.yaml` file](repo-level-atlantis-yaml.md). Cannot be used at same time as `-d` or `-w`.
150150
* `-w workspace` Apply the plan for this [Terraform workspace](https://developer.hashicorp.com/terraform/language/state/workspaces). Ignore this if Terraform workspaces are unused.
151151
* `--auto-merge-disabled` Disable [automerge](automerging.md) for this apply command.
152+
* `--auto-merge-method method` Specify which [merge method](automerging.md#how-to-set-merge-method-for-automerge) use for the apply command if [automerge](automerging.md) is enabled. Implemented only for GitHub.
152153
* `--verbose` Append Atlantis log to comment.
153154

154155
### Additional Terraform flags

server/core/config/valid/global_cfg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type MergedProjectCfg struct {
104104
Name string
105105
AutoplanEnabled bool
106106
AutoMergeDisabled bool
107+
AutoMergeMethod string
107108
TerraformVersion *version.Version
108109
RepoCfgVersion int
109110
PolicySets PolicySets

server/events/apply_command_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) {
181181
a.updateCommitStatus(ctx, pullStatus)
182182

183183
if a.autoMerger.automergeEnabled(projectCmds) && !cmd.AutoMergeDisabled {
184-
a.autoMerger.automerge(ctx, pullStatus, a.autoMerger.deleteSourceBranchOnMergeEnabled(projectCmds))
184+
a.autoMerger.automerge(ctx, pullStatus, a.autoMerger.deleteSourceBranchOnMergeEnabled(projectCmds), cmd.AutoMergeMethod)
185185
}
186186
}
187187

server/events/automerger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AutoMerger struct {
1313
GlobalAutomerge bool
1414
}
1515

16-
func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool) {
16+
func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatus, deleteSourceBranchOnMerge bool, mergeMethod string) {
1717
// We only automerge if all projects have been successfully applied.
1818
for _, p := range pullStatus.Projects {
1919
if p.Status != models.AppliedPlanStatus {
@@ -32,6 +32,7 @@ func (c *AutoMerger) automerge(ctx *command.Context, pullStatus models.PullStatu
3232
ctx.Log.Info("automerging pull request")
3333
var pullOptions models.PullRequestOptions
3434
pullOptions.DeleteSourceBranchOnMerge = deleteSourceBranchOnMerge
35+
pullOptions.MergeMethod = mergeMethod
3536
err := c.VCSClient.MergePull(ctx.Log, ctx.Pull, pullOptions)
3637

3738
if err != nil {

server/events/comment_parser.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const (
4141
policySetFlagShort = ""
4242
autoMergeDisabledFlagLong = "auto-merge-disabled"
4343
autoMergeDisabledFlagShort = ""
44+
autoMergeMethodFlagLong = "auto-merge-method"
45+
autoMergeMethodFlagShort = ""
4446
verboseFlagLong = "verbose"
4547
verboseFlagShort = ""
4648
clearPolicyApprovalFlagLong = "clear-policy-approval"
@@ -70,7 +72,7 @@ type CommentBuilder interface {
7072
// BuildPlanComment builds a plan comment for the specified args.
7173
BuildPlanComment(repoRelDir string, workspace string, project string, commentArgs []string) string
7274
// BuildApplyComment builds an apply comment for the specified args.
73-
BuildApplyComment(repoRelDir string, workspace string, project string, autoMergeDisabled bool) string
75+
BuildApplyComment(repoRelDir string, workspace string, project string, autoMergeDisabled bool, autoMergeMethod string) string
7476
// BuildApprovePoliciesComment builds an approve_policies comment for the specified args.
7577
BuildApprovePoliciesComment(repoRelDir string, workspace string, project string) string
7678
}
@@ -226,7 +228,9 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
226228
var project string
227229
var policySet string
228230
var clearPolicyApproval bool
229-
var verbose, autoMergeDisabled bool
231+
var verbose bool
232+
var autoMergeDisabled bool
233+
var autoMergeMethod string
230234
var flagSet *pflag.FlagSet
231235
var name command.Name
232236

@@ -248,6 +252,7 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
248252
flagSet.StringVarP(&dir, dirFlagLong, dirFlagShort, "", "Apply the plan for this directory, relative to root of repo, ex. 'child/dir'.")
249253
flagSet.StringVarP(&project, projectFlagLong, projectFlagShort, "", "Apply the plan for this project. Refers to the name of the project configured in a repo config file. Cannot be used at same time as workspace or dir flags.")
250254
flagSet.BoolVarP(&autoMergeDisabled, autoMergeDisabledFlagLong, autoMergeDisabledFlagShort, false, "Disable automerge after apply.")
255+
flagSet.StringVarP(&autoMergeMethod, autoMergeMethodFlagLong, autoMergeMethodFlagShort, "", "Specifies the merge method for the VCS if automerge is enabled. (Currently only implemented for GitHub)")
251256
flagSet.BoolVarP(&verbose, verboseFlagLong, verboseFlagShort, false, "Append Atlantis log to comment.")
252257
case command.ApprovePolicies.String():
253258
name = command.ApprovePolicies
@@ -317,8 +322,20 @@ func (e *CommentParser) Parse(rawComment string, vcsHost models.VCSHostType) Com
317322
return CommentParseResult{CommentResponse: e.errMarkdown(err, cmd, flagSet)}
318323
}
319324

325+
if autoMergeMethod != "" {
326+
if autoMergeDisabled {
327+
err := fmt.Sprintf("cannot use --%s at the same time as --%s", autoMergeMethodFlagLong, autoMergeDisabledFlagLong)
328+
return CommentParseResult{CommentResponse: e.errMarkdown(err, cmd, flagSet)}
329+
}
330+
331+
if vcsHost != models.Github {
332+
err := fmt.Sprintf("--%s is not currently implemented for %s", autoMergeMethodFlagLong, vcsHost.String())
333+
return CommentParseResult{CommentResponse: e.errMarkdown(err, cmd, flagSet)}
334+
}
335+
}
336+
320337
return CommentParseResult{
321-
Command: NewCommentCommand(dir, extraArgs, name, subName, verbose, autoMergeDisabled, workspace, project, policySet, clearPolicyApproval),
338+
Command: NewCommentCommand(dir, extraArgs, name, subName, verbose, autoMergeDisabled, autoMergeMethod, workspace, project, policySet, clearPolicyApproval),
322339
}
323340
}
324341

@@ -387,7 +404,7 @@ func (e *CommentParser) parseArgs(name command.Name, args []string, flagSet *pfl
387404

388405
// BuildPlanComment builds a plan comment for the specified args.
389406
func (e *CommentParser) BuildPlanComment(repoRelDir string, workspace string, project string, commentArgs []string) string {
390-
flags := e.buildFlags(repoRelDir, workspace, project, false)
407+
flags := e.buildFlags(repoRelDir, workspace, project, false, "")
391408
commentFlags := ""
392409
if len(commentArgs) > 0 {
393410
var flagsWithoutQuotes []string
@@ -402,18 +419,18 @@ func (e *CommentParser) BuildPlanComment(repoRelDir string, workspace string, pr
402419
}
403420

404421
// BuildApplyComment builds an apply comment for the specified args.
405-
func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, project string, autoMergeDisabled bool) string {
406-
flags := e.buildFlags(repoRelDir, workspace, project, autoMergeDisabled)
422+
func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, project string, autoMergeDisabled bool, autoMergeMethod string) string {
423+
flags := e.buildFlags(repoRelDir, workspace, project, autoMergeDisabled, autoMergeMethod)
407424
return fmt.Sprintf("%s %s%s", e.ExecutableName, command.Apply.String(), flags)
408425
}
409426

410427
// BuildApprovePoliciesComment builds an apply comment for the specified args.
411428
func (e *CommentParser) BuildApprovePoliciesComment(repoRelDir string, workspace string, project string) string {
412-
flags := e.buildFlags(repoRelDir, workspace, project, false)
429+
flags := e.buildFlags(repoRelDir, workspace, project, false, "")
413430
return fmt.Sprintf("%s %s%s", e.ExecutableName, command.ApprovePolicies.String(), flags)
414431
}
415432

416-
func (e *CommentParser) buildFlags(repoRelDir string, workspace string, project string, autoMergeDisabled bool) string {
433+
func (e *CommentParser) buildFlags(repoRelDir string, workspace string, project string, autoMergeDisabled bool, autoMergeMethod string) string {
417434
// Add quotes if dir has spaces.
418435
if strings.Contains(repoRelDir, " ") {
419436
repoRelDir = fmt.Sprintf("%q", repoRelDir)
@@ -441,6 +458,9 @@ func (e *CommentParser) buildFlags(repoRelDir string, workspace string, project
441458
if autoMergeDisabled {
442459
flags = fmt.Sprintf("%s --%s", flags, autoMergeDisabledFlagLong)
443460
}
461+
if autoMergeMethod != "" {
462+
flags = fmt.Sprintf("%s --%s %s", flags, autoMergeMethodFlagLong, autoMergeMethod)
463+
}
444464
return flags
445465
}
446466

server/events/comment_parser_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ func TestBuildPlanApplyVersionComment(t *testing.T) {
729729
workspace string
730730
project string
731731
autoMergeDisabled bool
732+
autoMergeMethod string
732733
commentArgs []string
733734
expPlanFlags string
734735
expApplyFlags string
@@ -824,6 +825,16 @@ func TestBuildPlanApplyVersionComment(t *testing.T) {
824825
expApplyFlags: "-d dir -w workspace --auto-merge-disabled",
825826
expVersionFlags: "-d dir -w workspace",
826827
},
828+
{
829+
repoRelDir: "dir",
830+
workspace: "workspace",
831+
project: "",
832+
autoMergeMethod: "squash",
833+
commentArgs: []string{`"arg1"`, `"arg2"`, `arg3`},
834+
expPlanFlags: "-d dir -w workspace -- arg1 arg2 arg3",
835+
expApplyFlags: "-d dir -w workspace --auto-merge-method squash",
836+
expVersionFlags: "-d dir -w workspace",
837+
},
827838
}
828839

829840
for _, c := range cases {
@@ -834,7 +845,7 @@ func TestBuildPlanApplyVersionComment(t *testing.T) {
834845
actComment := commentParser.BuildPlanComment(c.repoRelDir, c.workspace, c.project, c.commentArgs)
835846
Equals(t, fmt.Sprintf("atlantis plan %s", c.expPlanFlags), actComment)
836847
case command.Apply:
837-
actComment := commentParser.BuildApplyComment(c.repoRelDir, c.workspace, c.project, c.autoMergeDisabled)
848+
actComment := commentParser.BuildApplyComment(c.repoRelDir, c.workspace, c.project, c.autoMergeDisabled, c.autoMergeMethod)
838849
Equals(t, fmt.Sprintf("atlantis apply %s", c.expApplyFlags), actComment)
839850
}
840851
}
@@ -1020,14 +1031,18 @@ var PlanUsage = `Usage of plan:
10201031
`
10211032

10221033
var ApplyUsage = `Usage of apply:
1023-
--auto-merge-disabled Disable automerge after apply.
1024-
-d, --dir string Apply the plan for this directory, relative to root of
1025-
repo, ex. 'child/dir'.
1026-
-p, --project string Apply the plan for this project. Refers to the name of
1027-
the project configured in a repo config file. Cannot
1028-
be used at same time as workspace or dir flags.
1029-
--verbose Append Atlantis log to comment.
1030-
-w, --workspace string Apply the plan for this Terraform workspace.
1034+
--auto-merge-disabled Disable automerge after apply.
1035+
--auto-merge-method string Specifies the merge method for the VCS if
1036+
automerge is enabled. (Currently only implemented
1037+
for GitHub)
1038+
-d, --dir string Apply the plan for this directory, relative to
1039+
root of repo, ex. 'child/dir'.
1040+
-p, --project string Apply the plan for this project. Refers to the
1041+
name of the project configured in a repo config
1042+
file. Cannot be used at same time as workspace or
1043+
dir flags.
1044+
--verbose Append Atlantis log to comment.
1045+
-w, --workspace string Apply the plan for this Terraform workspace.
10311046
`
10321047

10331048
var ApprovePolicyUsage = `Usage of approve_policies:

server/events/event_parser.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ type CommentCommand struct {
128128
SubName string
129129
// AutoMergeDisabled is true if the command should not automerge after apply.
130130
AutoMergeDisabled bool
131+
// AutoMergeMethod specified the merge method for the VCS if automerge enabled.
132+
AutoMergeMethod string
131133
// Verbose is true if the command should output verbosely.
132134
Verbose bool
133135
// Workspace is the name of the Terraform workspace to run the command in.
@@ -177,11 +179,11 @@ func (c CommentCommand) IsAutoplan() bool {
177179

178180
// String returns a string representation of the command.
179181
func (c CommentCommand) String() string {
180-
return fmt.Sprintf("command=%q verbose=%t dir=%q workspace=%q project=%q policyset=%q, clear-policy-approval=%t, flags=%q", c.Name.String(), c.Verbose, c.RepoRelDir, c.Workspace, c.ProjectName, c.PolicySet, c.ClearPolicyApproval, strings.Join(c.Flags, ","))
182+
return fmt.Sprintf("command=%q, verbose=%t, dir=%q, workspace=%q, project=%q, policyset=%q, auto-merge-disabled=%t, auto-merge-method=%s, clear-policy-approval=%t, flags=%q", c.Name.String(), c.Verbose, c.RepoRelDir, c.Workspace, c.ProjectName, c.PolicySet, c.AutoMergeDisabled, c.AutoMergeMethod, c.ClearPolicyApproval, strings.Join(c.Flags, ","))
181183
}
182184

183185
// NewCommentCommand constructs a CommentCommand, setting all missing fields to defaults.
184-
func NewCommentCommand(repoRelDir string, flags []string, name command.Name, subName string, verbose, autoMergeDisabled bool, workspace string, project string, policySet string, clearPolicyApproval bool) *CommentCommand {
186+
func NewCommentCommand(repoRelDir string, flags []string, name command.Name, subName string, verbose, autoMergeDisabled bool, autoMergeMethod string, workspace string, project string, policySet string, clearPolicyApproval bool) *CommentCommand {
185187
// If repoRelDir was empty we want to keep it that way to indicate that it
186188
// wasn't specified in the comment.
187189
if repoRelDir != "" {
@@ -198,6 +200,7 @@ func NewCommentCommand(repoRelDir string, flags []string, name command.Name, sub
198200
Verbose: verbose,
199201
Workspace: workspace,
200202
AutoMergeDisabled: autoMergeDisabled,
203+
AutoMergeMethod: autoMergeMethod,
201204
ProjectName: project,
202205
PolicySet: policySet,
203206
ClearPolicyApproval: clearPolicyApproval,

0 commit comments

Comments
 (0)