Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commit message modes after go-github changes #193

Merged
merged 1 commit into from Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 17 additions & 21 deletions bulldozer/merge.go
Expand Up @@ -311,7 +311,16 @@ func isValidMergeMethod(input MergeMethod) bool {
}

func calculateCommitMessage(ctx context.Context, pullCtx pull.Context, option SquashOptions) (string, error) {
commitMessage := ""
// As of go-github v30, using the empty string as the commit message
// selects the default GitHub behavior for the merge mode. To actually
// clear the message, we use a non-empty string that GitHub will still
// interpret as empty.
const (
defaultMessage = ""
emptyMessage = " "
)

commitMessage := defaultMessage
switch option.Body {
case PullRequestBody:
if option.MessageDelimiter != "" {
Expand All @@ -322,19 +331,19 @@ func calculateCommitMessage(ctx context.Context, pullCtx pull.Context, option Sq
return "", errors.Wrap(err, "failed to compile message delimiter regex")
}

if m := matcher.FindStringSubmatch(pullCtx.Body()); len(m) == 4 {
if m := matcher.FindStringSubmatch(pullCtx.Body()); len(m) == 4 && m[2] != "" {
commitMessage = m[2]
} else {
commitMessage = emptyMessage
}
} else {
commitMessage = pullCtx.Body()
}
case SummarizeCommits:
summarizedMessages, err := summarizeCommitMessages(ctx, pullCtx)
if err != nil {
return "", errors.Wrap(err, "failed to summarize pull request commit messages")
}
commitMessage = summarizedMessages
case EmptyBody:
commitMessage = emptyMessage
case SummarizeCommits:
// Summarizing commits is the default behavior for squash merges
commitMessage = defaultMessage
}

return commitMessage, nil
Expand All @@ -360,16 +369,3 @@ func calculateCommitTitle(ctx context.Context, pullCtx pull.Context, option Squa
}
return title, nil
}

func summarizeCommitMessages(ctx context.Context, pullCtx pull.Context) (string, error) {
commits, err := pullCtx.Commits(ctx)
if err != nil {
return "", err
}

var builder strings.Builder
for _, c := range commits {
fmt.Fprintf(&builder, "* %s\n", c.Message)
}
return builder.String(), nil
}
6 changes: 3 additions & 3 deletions bulldozer/merge_test.go
Expand Up @@ -117,12 +117,12 @@ func TestCalculateCommitMessage(t *testing.T) {
"emptyBody": {
PullContext: defaultPullContext,
Strategy: EmptyBody,
Output: "",
Output: " ",
},
"summarizeCommits": {
PullContext: defaultPullContext,
Strategy: SummarizeCommits,
Output: "* The first commit message!\n* The second commit message!\n* The third commit message!\n",
Output: "",
},
"pullRequestBody": {
PullContext: defaultPullContext,
Expand All @@ -141,7 +141,7 @@ func TestCalculateCommitMessage(t *testing.T) {
PullContext: defaultPullContext,
Strategy: PullRequestBody,
Delimiter: "~~",
Output: "",
Output: " ",
},
}

Expand Down