Skip to content

Commit 9cf0352

Browse files
author
Gusted
authored
Prepend commit message to template content (#20429)
- When a repository has a pull request template, it will always override the current content. With this PR it will prepend content to the template content when appropriate. This is similar how GitHub(and GitLab I presume) does it and it saves developers time to not go open their commit and copy paste their will written commit message.
1 parent 91f1c28 commit 9cf0352

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

routers/web/repo/compare.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,19 @@ func CompareDiff(ctx *context.Context) {
786786
ctx.Data["IsDiffCompare"] = true
787787
ctx.Data["RequireTribute"] = true
788788
setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
789+
790+
// If a template content is set, prepend the "content". In this case that's only
791+
// applicable if you have one commit to compare and that commit has a message.
792+
// In that case the commit message will be prepend to the template body.
793+
if templateContent, ok := ctx.Data[pullRequestTemplateKey].(string); ok && templateContent != "" {
794+
if content, ok := ctx.Data["content"].(string); ok && content != "" {
795+
// Re-use the same key as that's priortized over the "content" key.
796+
// Add two new lines between the content to ensure there's always at least
797+
// one empty line between them.
798+
ctx.Data[pullRequestTemplateKey] = content + "\n\n" + templateContent
799+
}
800+
}
801+
789802
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
790803
upload.AddUploadContext(ctx, "comment")
791804

0 commit comments

Comments
 (0)