Skip to content

Commit 4cbc865

Browse files
authored
Add option to define refs in issue templates (go-gitea#17842)
Adds a markdown header option `ref` that allows you to set the ref the issue should belong.
1 parent 4bbbf35 commit 4cbc865

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

docs/content/doc/usage/issue-pull-request-templates.en-us.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Inside the directory can be multiple issue templates with the form
6969
name: "Template Name"
7070
about: "This template is for testing!"
7171
title: "[TEST] "
72+
ref: "main"
7273
labels:
7374

7475
- bug
@@ -82,4 +83,4 @@ This is the template!
8283
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
8384
`This template is for testing!`. When submitting an issue with the above example, the issue title would be pre-populated with
8485
`[TEST] ` while the issue body would be pre-populated with `This is the template!`. The issue would also be assigned two labels,
85-
`bug` and `help needed`.
86+
`bug` and `help needed`, and the issue will have a reference to `main`.

modules/structs/issue.go

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ type IssueTemplate struct {
127127
Title string `json:"title" yaml:"title"`
128128
About string `json:"about" yaml:"about"`
129129
Labels []string `json:"labels" yaml:"labels"`
130+
Ref string `json:"ref" yaml:"ref"`
130131
Content string `json:"content" yaml:"-"`
131132
FileName string `json:"file_name" yaml:"-"`
132133
}

routers/web/repo/issue.go

+3
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs [
776776
}
777777
ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0
778778
ctx.Data["label_ids"] = strings.Join(labelIDs, ",")
779+
ctx.Data["Reference"] = meta.Ref
780+
ctx.Data["RefEndName"] = git.RefEndName(meta.Ref)
779781
return
780782
}
781783
}
@@ -1635,6 +1637,7 @@ func ViewIssue(ctx *context.Context) {
16351637
ctx.Data["Participants"] = participants
16361638
ctx.Data["NumParticipants"] = len(participants)
16371639
ctx.Data["Issue"] = issue
1640+
ctx.Data["Reference"] = issue.Ref
16381641
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + url.QueryEscape(ctx.Data["Link"].(string))
16391642
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
16401643
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)

templates/repo/issue/branch_selector_field.tmpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{if and (not .Issue.IsPull) (not .PageIsComparePull)}}
2-
<input id="ref_selector" name="ref" type="hidden" value="{{.Issue.Ref}}">
2+
<input id="ref_selector" name="ref" type="hidden" value="{{.Reference}}">
33
<input id="editing_mode" name="edit_mode" type="hidden" value="{{(or .IsIssueWriter .HasIssuesOrPullsWritePermission)}}">
44
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form">
55
{{$.CsrfTokenHtml}}
66
</form>
77

88
<div class="ui {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}} floating filter select-branch dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
99
<div class="ui basic small button">
10-
<span class="text branch-name">{{if .Issue.Ref}}{{$.RefEndName}}{{else}}{{.i18n.Tr "repo.issues.no_ref"}}{{end}}</span>
10+
<span class="text branch-name">{{if .Reference}}{{$.RefEndName}}{{else}}{{.i18n.Tr "repo.issues.no_ref"}}{{end}}</span>
1111
{{if .HasIssuesOrPullsWritePermission}}{{svg "octicon-triangle-down" 14 "dropdown icon"}}{{end}}
1212
</div>
1313
<div class="menu">
@@ -32,15 +32,15 @@
3232
</div>
3333
</div>
3434
<div id="branch-list" class="scrolling menu reference-list-menu {{if not .Issue}}new-issue{{end}}">
35-
{{if .Issue.Ref}}
35+
{{if .Reference}}
3636
<div class="item text small" data-id="" data-id-selector="#ref_selector"><strong><a href="#">{{$.i18n.Tr "repo.clear_ref"}}</a></strong></div>
3737
{{end}}
3838
{{range .Branches}}
3939
<div class="item" data-id="refs/heads/{{.}}" data-name="{{.}}" data-id-selector="#ref_selector">{{.}}</div>
4040
{{end}}
4141
</div>
4242
<div id="tag-list" class="scrolling menu reference-list-menu {{if not .Issue}}new-issue{{end}}" style="display: none">
43-
{{if .Issue.Ref}}
43+
{{if .Reference}}
4444
<div class="item text small" data-id="" data-id-selector="#ref_selector"><strong><a href="#">{{.i18n.Tr "repo.clear_ref"}}</a></strong></div>
4545
{{end}}
4646
{{range .Tags}}

templates/swagger/v1_json.tmpl

+4
Original file line numberDiff line numberDiff line change
@@ -15578,6 +15578,10 @@
1557815578
"type": "string",
1557915579
"x-go-name": "Name"
1558015580
},
15581+
"ref": {
15582+
"type": "string",
15583+
"x-go-name": "Ref"
15584+
},
1558115585
"title": {
1558215586
"type": "string",
1558315587
"x-go-name": "Title"

0 commit comments

Comments
 (0)