Skip to content

Commit

Permalink
feat: Flag to disable custom [Atlantis] commit messages on PR merge (
Browse files Browse the repository at this point in the history
…runatlantis#3120)

* Modify the automere commit message to include the PR number [DEVOPS-674]

* Update server/events/vcs/common/common.go

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>

* added test for PR message func [DEVOPS-674]

---------

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
  • Loading branch information
2 people authored and ijames-gc committed Feb 13, 2024
1 parent 9df0bf9 commit a19703f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/events/vcs/azuredevops_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (g *AzureDevopsClient) MergePull(pull models.PullRequest, pullOptions model
BypassPolicy: new(bool),
BypassReason: azuredevops.String(""),
DeleteSourceBranch: &pullOptions.DeleteSourceBranchOnMerge,
MergeCommitMessage: azuredevops.String(common.AutomergeCommitMsg),
MergeCommitMessage: azuredevops.String(common.AutomergeCommitMsg(pull.Num)),
MergeStrategy: &mcm,
SquashMerge: new(bool),
TransitionWorkItems: twi,
Expand Down
8 changes: 5 additions & 3 deletions server/events/vcs/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
package common

import (
"fmt"
"math"
)

// AutomergeCommitMsg is the commit message Atlantis will use when automatically
// merging pull requests.
const AutomergeCommitMsg = "[Atlantis] Automatically merging after successful apply"
// AutomergeCommitMsg returns the commit message to use when automerging.
func AutomergeCommitMsg(pullNum int) string {
return fmt.Sprintf("[Atlantis] Automatically merging after successful apply: PR #%d", pullNum)
}

// SplitComment splits comment into a slice of comments that are under maxSize.
// It appends sepEnd to all comments that have a following comment.
Expand Down
22 changes: 21 additions & 1 deletion server/events/vcs/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"

"github.com/runatlantis/atlantis/server/events/vcs/common"

. "github.com/runatlantis/atlantis/testing"
)

Expand Down Expand Up @@ -61,3 +60,24 @@ func TestSplitComment_FourComments(t *testing.T) {
sepStart + comment[expMax*2:expMax*3] + sepEnd,
sepStart + comment[expMax*3:]}, split)
}

func TestAutomergeCommitMsg(t *testing.T) {
tests := []struct {
name string
pullNum int
want string
}{
{
name: "Atlantis PR commit message should include PR number",
pullNum: 123,
want: "[Atlantis] Automatically merging after successful apply: PR #123",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := common.AutomergeCommitMsg(tt.pullNum); got != tt.want {
t.Errorf("AutomergeCommitMsg() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (g *GitlabClient) WaitForSuccessPipeline(ctx context.Context, pull models.P

// MergePull merges the merge request.
func (g *GitlabClient) MergePull(pull models.PullRequest, pullOptions models.PullRequestOptions) error {
commitMsg := common.AutomergeCommitMsg
commitMsg := common.AutomergeCommitMsg(pull.Num)

mr, err := g.GetMergeRequest(pull.BaseRepo.FullName, pull.Num)
if err != nil {
Expand Down

0 comments on commit a19703f

Please sign in to comment.