From 4cbc865d835eb49722d22f8ac5019ccc17582a16 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Fri, 17 Dec 2021 22:29:09 +0100 Subject: [PATCH] Add option to define refs in issue templates (#17842) Adds a markdown header option `ref` that allows you to set the ref the issue should belong. --- .../doc/usage/issue-pull-request-templates.en-us.md | 3 ++- modules/structs/issue.go | 1 + routers/web/repo/issue.go | 3 +++ templates/repo/issue/branch_selector_field.tmpl | 8 ++++---- templates/swagger/v1_json.tmpl | 4 ++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/content/doc/usage/issue-pull-request-templates.en-us.md b/docs/content/doc/usage/issue-pull-request-templates.en-us.md index 44291635c9..218b8a3642 100644 --- a/docs/content/doc/usage/issue-pull-request-templates.en-us.md +++ b/docs/content/doc/usage/issue-pull-request-templates.en-us.md @@ -69,6 +69,7 @@ Inside the directory can be multiple issue templates with the form name: "Template Name" about: "This template is for testing!" title: "[TEST] " +ref: "main" labels: - bug @@ -82,4 +83,4 @@ This is the template! In the above example, when a user is presented with the list of issues they can submit, this would show as `Template Name` with the description `This template is for testing!`. When submitting an issue with the above example, the issue title would be pre-populated with `[TEST] ` while the issue body would be pre-populated with `This is the template!`. The issue would also be assigned two labels, -`bug` and `help needed`. +`bug` and `help needed`, and the issue will have a reference to `main`. diff --git a/modules/structs/issue.go b/modules/structs/issue.go index a4a5baa90f..c72487fe4d 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -127,6 +127,7 @@ type IssueTemplate struct { Title string `json:"title" yaml:"title"` About string `json:"about" yaml:"about"` Labels []string `json:"labels" yaml:"labels"` + Ref string `json:"ref" yaml:"ref"` Content string `json:"content" yaml:"-"` FileName string `json:"file_name" yaml:"-"` } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index fe015145bd..17c72c13fe 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -776,6 +776,8 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs [ } ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0 ctx.Data["label_ids"] = strings.Join(labelIDs, ",") + ctx.Data["Reference"] = meta.Ref + ctx.Data["RefEndName"] = git.RefEndName(meta.Ref) return } } @@ -1635,6 +1637,7 @@ func ViewIssue(ctx *context.Context) { ctx.Data["Participants"] = participants ctx.Data["NumParticipants"] = len(participants) ctx.Data["Issue"] = issue + ctx.Data["Reference"] = issue.Ref ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + url.QueryEscape(ctx.Data["Link"].(string)) ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) diff --git a/templates/repo/issue/branch_selector_field.tmpl b/templates/repo/issue/branch_selector_field.tmpl index cb7d37fb90..9c3e62ea59 100644 --- a/templates/repo/issue/branch_selector_field.tmpl +++ b/templates/repo/issue/branch_selector_field.tmpl @@ -1,5 +1,5 @@ {{if and (not .Issue.IsPull) (not .PageIsComparePull)}} - +
{{$.CsrfTokenHtml}} @@ -7,7 +7,7 @@