Skip to content

Commit 8883d99

Browse files
authored
Support issue template assignees (#31083)
Resolve #13955
1 parent 63c5ac6 commit 8883d99

File tree

6 files changed

+41
-24
lines changed

6 files changed

+41
-24
lines changed

modules/issue/template/template_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ name: Name
466466
title: Title
467467
about: About
468468
labels: ["label1", "label2"]
469+
assignees: ["user1", "user2"]
469470
ref: Ref
470471
body:
471472
- type: markdown
@@ -523,11 +524,12 @@ body:
523524
visible: [form]
524525
`,
525526
want: &api.IssueTemplate{
526-
Name: "Name",
527-
Title: "Title",
528-
About: "About",
529-
Labels: []string{"label1", "label2"},
530-
Ref: "Ref",
527+
Name: "Name",
528+
Title: "Title",
529+
About: "About",
530+
Labels: []string{"label1", "label2"},
531+
Assignees: []string{"user1", "user2"},
532+
Ref: "Ref",
531533
Fields: []*api.IssueFormField{
532534
{
533535
Type: "markdown",

modules/structs/issue.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,20 @@ const (
177177
// IssueTemplate represents an issue template for a repository
178178
// swagger:model
179179
type IssueTemplate struct {
180-
Name string `json:"name" yaml:"name"`
181-
Title string `json:"title" yaml:"title"`
182-
About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible
183-
Labels IssueTemplateLabels `json:"labels" yaml:"labels"`
184-
Ref string `json:"ref" yaml:"ref"`
185-
Content string `json:"content" yaml:"-"`
186-
Fields []*IssueFormField `json:"body" yaml:"body"`
187-
FileName string `json:"file_name" yaml:"-"`
180+
Name string `json:"name" yaml:"name"`
181+
Title string `json:"title" yaml:"title"`
182+
About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible
183+
Labels IssueTemplateStringSlice `json:"labels" yaml:"labels"`
184+
Assignees IssueTemplateStringSlice `json:"assignees" yaml:"assignees"`
185+
Ref string `json:"ref" yaml:"ref"`
186+
Content string `json:"content" yaml:"-"`
187+
Fields []*IssueFormField `json:"body" yaml:"body"`
188+
FileName string `json:"file_name" yaml:"-"`
188189
}
189190

190-
type IssueTemplateLabels []string
191+
type IssueTemplateStringSlice []string
191192

192-
func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error {
193+
func (l *IssueTemplateStringSlice) UnmarshalYAML(value *yaml.Node) error {
193194
var labels []string
194195
if value.IsZero() {
195196
*l = labels
@@ -217,7 +218,7 @@ func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error {
217218
*l = labels
218219
return nil
219220
}
220-
return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateLabels", value.Line, value.ShortTag())
221+
return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateStringSlice", value.Line, value.ShortTag())
221222
}
222223

223224
type IssueConfigContactLink struct {

modules/structs/issue_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestIssueTemplate_Type(t *testing.T) {
4242
}
4343
}
4444

45-
func TestIssueTemplateLabels_UnmarshalYAML(t *testing.T) {
45+
func TestIssueTemplateStringSlice_UnmarshalYAML(t *testing.T) {
4646
tests := []struct {
4747
name string
4848
content string
@@ -88,7 +88,7 @@ labels:
8888
b: bb
8989
`,
9090
tmpl: &IssueTemplate{},
91-
wantErr: "line 3: cannot unmarshal !!map into IssueTemplateLabels",
91+
wantErr: "line 3: cannot unmarshal !!map into IssueTemplateStringSlice",
9292
},
9393
}
9494
for _, tt := range tests {

routers/web/repo/issue.go

+11
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,23 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
939939
}
940940
}
941941
}
942+
selectedAssigneeIDs := make([]int64, 0, len(template.Assignees))
943+
selectedAssigneeIDStrings := make([]string, 0, len(template.Assignees))
944+
if userIDs, err := user_model.GetUserIDsByNames(ctx, template.Assignees, false); err == nil {
945+
for _, userID := range userIDs {
946+
selectedAssigneeIDs = append(selectedAssigneeIDs, userID)
947+
selectedAssigneeIDStrings = append(selectedAssigneeIDStrings, strconv.FormatInt(userID, 10))
948+
}
949+
}
942950

943951
if template.Ref != "" && !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
944952
template.Ref = git.BranchPrefix + template.Ref
945953
}
946954
ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0
947955
ctx.Data["label_ids"] = strings.Join(labelIDs, ",")
956+
ctx.Data["HasSelectedAssignee"] = len(selectedAssigneeIDs) > 0
957+
ctx.Data["assignee_ids"] = strings.Join(selectedAssigneeIDStrings, ",")
958+
ctx.Data["SelectedAssigneeIDs"] = selectedAssigneeIDs
948959
ctx.Data["Reference"] = template.Ref
949960
ctx.Data["RefEndName"] = git.RefName(template.Ref).ShortName()
950961
return true, templateErrs

templates/repo/issue/new_form.tmpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
</div>
156156
<div class="no-select item">{{ctx.Locale.Tr "repo.issues.new.clear_assignees"}}</div>
157157
{{range .Assignees}}
158-
<a class="item muted" href="#" data-id="{{.ID}}" data-id-selector="#assignee_{{.ID}}">
159-
<span class="octicon-check tw-invisible">{{svg "octicon-check"}}</span>
158+
<a class="{{if SliceUtils.Contains $.SelectedAssigneeIDs .ID}}checked{{end}} item muted" href="#" data-id="{{.ID}}" data-id-selector="#assignee_{{.ID}}">
159+
<span class="octicon-check {{if not (SliceUtils.Contains $.SelectedAssigneeIDs .ID)}}tw-invisible{{end}}">{{svg "octicon-check"}}</span>
160160
<span class="text">
161161
{{ctx.AvatarUtils.Avatar . 28 "tw-mr-2"}}{{template "repo/search_name" .}}
162162
</span>
@@ -165,12 +165,12 @@
165165
</div>
166166
</div>
167167
<div class="ui assignees list">
168-
<span class="no-select item {{if .HasSelectedLabel}}tw-hidden{{end}}">
168+
<span class="no-select item {{if .HasSelectedAssignee}}tw-hidden{{end}}">
169169
{{ctx.Locale.Tr "repo.issues.new.no_assignees"}}
170170
</span>
171171
<div class="selected">
172172
{{range .Assignees}}
173-
<a class="item tw-p-1 muted tw-hidden" id="assignee_{{.ID}}" href="{{$.RepoLink}}/issues?assignee={{.ID}}">
173+
<a class="item tw-p-1 muted {{if not (SliceUtils.Contains $.SelectedAssigneeIDs .ID)}}tw-hidden{{end}}" id="assignee_{{.ID}}" href="{{$.RepoLink}}/issues?assignee={{.ID}}">
174174
{{ctx.AvatarUtils.Avatar . 28 "tw-mr-2 tw-align-middle"}}{{.GetDisplayName}}
175175
</a>
176176
{{end}}

templates/swagger/v1_json.tmpl

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)