aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2023-01-30 15:39:07 +0100
committerGitHub <noreply@github.com>2023-01-30 22:39:07 +0800
commitb5b3e0714e624cea3ce4d5368aa1266f7639d0eb (patch)
tree413415158599bb88ffe238af021b1176db126a98
parent1b53a9e91401c931065949981d02e06bbcd745ef (diff)
downloadgitea-b5b3e0714e624cea3ce4d5368aa1266f7639d0eb.tar.gz
gitea-b5b3e0714e624cea3ce4d5368aa1266f7639d0eb.zip
Pull request yaml template support for including commit body in a field (#22629)
When using a markdown template the commit body is prepended to text in the description. This adds the same functionality for yaml templates, adding the commit message in a field with id "body". Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r--routers/web/repo/compare.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 8d45f8d674..35f923d561 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -30,6 +30,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
+ api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
@@ -789,16 +790,29 @@ func CompareDiff(ctx *context.Context) {
ctx.Flash.Warning(renderErrorOfTemplates(ctx, templateErrs), true)
}
- // 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 != "" {
+ if content, ok := ctx.Data["content"].(string); ok && content != "" {
+ // 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 != "" {
// 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
}
+
+ // When using form fields, also add content to field with id "body".
+ if fields, ok := ctx.Data["Fields"].([]*api.IssueFormField); ok {
+ for _, field := range fields {
+ if field.ID == "body" {
+ if fieldValue, ok := field.Attributes["value"].(string); ok && fieldValue != "" {
+ field.Attributes["value"] = content + "\n\n" + fieldValue
+ } else {
+ field.Attributes["value"] = content
+ }
+ }
+ }
+ }
}
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled