feat: Flag to disable custom [Atlantis] commit messages on PR merge (#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>
This commit is contained in:
Oliver
2023-03-24 21:07:19 -05:00
committed by GitHub
parent fd86540fef
commit f35f4d6775
4 changed files with 28 additions and 6 deletions

View File

@@ -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,

View File

@@ -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.

View File

@@ -18,7 +18,6 @@ import (
"testing"
"github.com/runatlantis/atlantis/server/events/vcs/common"
. "github.com/runatlantis/atlantis/testing"
)
@@ -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)
}
})
}
}

View File

@@ -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 {