]> source.dussan.org Git - gitea.git/commitdiff
Prepend commit message to template content (#20429)
authorGusted <williamzijl7@hotmail.com>
Sun, 24 Jul 2022 03:45:33 +0000 (05:45 +0200)
committerGitHub <noreply@github.com>
Sun, 24 Jul 2022 03:45:33 +0000 (04:45 +0100)
- 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.

routers/web/repo/compare.go

index 5c46882f3d2642d3a739a9578fae76f2fbcbd077..8ed794b45c7dc4cebdd91cbdc0286a5af3e9bf53 100644 (file)
@@ -786,6 +786,19 @@ func CompareDiff(ctx *context.Context) {
        ctx.Data["IsDiffCompare"] = true
        ctx.Data["RequireTribute"] = true
        setTemplateIfExists(ctx, pullRequestTemplateKey, nil, pullRequestTemplateCandidates)
+
+       // If a template content is set, prepend the "content". In this case that's only
+       // applicable if you have one commit to compare and that commit has a message.
+       // In that case the commit message will be prepend to the template body.
+       if templateContent, ok := ctx.Data[pullRequestTemplateKey].(string); ok && templateContent != "" {
+               if content, ok := ctx.Data["content"].(string); ok && content != "" {
+                       // Re-use the same key as that's priortized over the "content" key.
+                       // Add two new lines between the content to ensure there's always at least
+                       // one empty line between them.
+                       ctx.Data[pullRequestTemplateKey] = content + "\n\n" + templateContent
+               }
+       }
+
        ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
        upload.AddUploadContext(ctx, "comment")