Skip to content

Commit 1e09302

Browse files
committed
feat: expandDefaultMergeMessage
1 parent 3054f08 commit 1e09302

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

services/pull/merge.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ func GetDefaultMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr
107107
vars["ClosingIssues"] = ""
108108
}
109109
}
110-
111-
templateDetail := ""
112-
if splits := strings.SplitN(templateContent, "\n", 2); len(splits) == 2 {
113-
templateContent = splits[0]
114-
templateDetail = splits[1]
115-
}
116-
mapping := func(s string) string { return vars[s] }
117-
return os.Expand(templateContent, mapping), os.Expand(templateDetail, mapping), nil
110+
message, detail := expandDefaultMergeMessage(templateContent, vars)
111+
return message, detail, nil
118112
}
119113
}
120114

@@ -134,6 +128,17 @@ func GetDefaultMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr
134128
return fmt.Sprintf("Merge pull request '%s' (%s%d) from %s:%s into %s", pr.Issue.Title, issueReference, pr.Issue.Index, pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseBranch), "", nil
135129
}
136130

131+
func expandDefaultMergeMessage(template string, vars map[string]string) (string, string) {
132+
message := strings.TrimSpace(template)
133+
detail := ""
134+
if splits := strings.SplitN(message, "\n", 2); len(splits) == 2 {
135+
message = splits[0]
136+
detail = strings.TrimSpace(detail)
137+
}
138+
mapping := func(s string) string { return vars[s] }
139+
return os.Expand(message, mapping), os.Expand(detail, mapping)
140+
}
141+
137142
// Merge merges pull request to base repository.
138143
// Caller should check PR is ready to be merged (review and status checks)
139144
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error {

0 commit comments

Comments
 (0)