diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-07-24 05:45:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-24 04:45:33 +0100 |
commit | 9cf0352f149b70091515d33614dca28db3113a98 (patch) | |
tree | bd09b3a2e1ab254c31bc6ef5dd76cff5fd95bf49 /routers | |
parent | 91f1c285a10f32f7738dc408d22d3031c4af8500 (diff) | |
download | gitea-9cf0352f149b70091515d33614dca28db3113a98.tar.gz gitea-9cf0352f149b70091515d33614dca28db3113a98.zip |
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.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/compare.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 5c46882f3d..8ed794b45c 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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") |