diff --git a/modules/issue/template/template_test.go b/modules/issue/template/template_test.go index 349dbeabb0..689a285b47 100644 --- a/modules/issue/template/template_test.go +++ b/modules/issue/template/template_test.go @@ -466,6 +466,7 @@ name: Name title: Title about: About labels: ["label1", "label2"] +assignees: ["user1", "user2"] ref: Ref body: - type: markdown @@ -523,11 +524,12 @@ body: visible: [form] `, want: &api.IssueTemplate{ - Name: "Name", - Title: "Title", - About: "About", - Labels: []string{"label1", "label2"}, - Ref: "Ref", + Name: "Name", + Title: "Title", + About: "About", + Labels: []string{"label1", "label2"}, + Assignees: []string{"user1", "user2"}, + Ref: "Ref", Fields: []*api.IssueFormField{ { Type: "markdown", diff --git a/modules/structs/issue.go b/modules/structs/issue.go index 3c06e38356..3682191be5 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -177,19 +177,20 @@ const ( // IssueTemplate represents an issue template for a repository // swagger:model type IssueTemplate struct { - Name string `json:"name" yaml:"name"` - Title string `json:"title" yaml:"title"` - About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible - Labels IssueTemplateLabels `json:"labels" yaml:"labels"` - Ref string `json:"ref" yaml:"ref"` - Content string `json:"content" yaml:"-"` - Fields []*IssueFormField `json:"body" yaml:"body"` - FileName string `json:"file_name" yaml:"-"` + Name string `json:"name" yaml:"name"` + Title string `json:"title" yaml:"title"` + About string `json:"about" yaml:"about"` // Using "description" in a template file is compatible + Labels IssueTemplateStringSlice `json:"labels" yaml:"labels"` + Assignees IssueTemplateStringSlice `json:"assignees" yaml:"assignees"` + Ref string `json:"ref" yaml:"ref"` + Content string `json:"content" yaml:"-"` + Fields []*IssueFormField `json:"body" yaml:"body"` + FileName string `json:"file_name" yaml:"-"` } -type IssueTemplateLabels []string +type IssueTemplateStringSlice []string -func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error { +func (l *IssueTemplateStringSlice) UnmarshalYAML(value *yaml.Node) error { var labels []string if value.IsZero() { *l = labels @@ -217,7 +218,7 @@ func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error { *l = labels return nil } - return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateLabels", value.Line, value.ShortTag()) + return fmt.Errorf("line %d: cannot unmarshal %s into IssueTemplateStringSlice", value.Line, value.ShortTag()) } type IssueConfigContactLink struct { diff --git a/modules/structs/issue_test.go b/modules/structs/issue_test.go index fa7a20db8b..55bd01df49 100644 --- a/modules/structs/issue_test.go +++ b/modules/structs/issue_test.go @@ -42,7 +42,7 @@ func TestIssueTemplate_Type(t *testing.T) { } } -func TestIssueTemplateLabels_UnmarshalYAML(t *testing.T) { +func TestIssueTemplateStringSlice_UnmarshalYAML(t *testing.T) { tests := []struct { name string content string @@ -88,7 +88,7 @@ labels: b: bb `, tmpl: &IssueTemplate{}, - wantErr: "line 3: cannot unmarshal !!map into IssueTemplateLabels", + wantErr: "line 3: cannot unmarshal !!map into IssueTemplateStringSlice", }, } for _, tt := range tests { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 691de94290..856e2f7392 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -939,12 +939,23 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles } } } + selectedAssigneeIDs := make([]int64, 0, len(template.Assignees)) + selectedAssigneeIDStrings := make([]string, 0, len(template.Assignees)) + if userIDs, err := user_model.GetUserIDsByNames(ctx, template.Assignees, false); err == nil { + for _, userID := range userIDs { + selectedAssigneeIDs = append(selectedAssigneeIDs, userID) + selectedAssigneeIDStrings = append(selectedAssigneeIDStrings, strconv.FormatInt(userID, 10)) + } + } if template.Ref != "" && !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/ template.Ref = git.BranchPrefix + template.Ref } ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0 ctx.Data["label_ids"] = strings.Join(labelIDs, ",") + ctx.Data["HasSelectedAssignee"] = len(selectedAssigneeIDs) > 0 + ctx.Data["assignee_ids"] = strings.Join(selectedAssigneeIDStrings, ",") + ctx.Data["SelectedAssigneeIDs"] = selectedAssigneeIDs ctx.Data["Reference"] = template.Ref ctx.Data["RefEndName"] = git.RefName(template.Ref).ShortName() return true, templateErrs diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 88a6c39e52..e56d1b9ecc 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -155,8 +155,8 @@
{{ctx.Locale.Tr "repo.issues.new.clear_assignees"}}
{{range .Assignees}} - - {{svg "octicon-check"}} + + {{svg "octicon-check"}} {{ctx.AvatarUtils.Avatar . 28 "tw-mr-2"}}{{template "repo/search_name" .}} @@ -165,12 +165,12 @@
- + {{ctx.Locale.Tr "repo.issues.new.no_assignees"}}
{{range .Assignees}} - + {{ctx.AvatarUtils.Avatar . 28 "tw-mr-2 tw-align-middle"}}{{.GetDisplayName}} {{end}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 18ea4a62b5..52d3754737 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -22345,6 +22345,9 @@ "type": "string", "x-go-name": "About" }, + "assignees": { + "$ref": "#/definitions/IssueTemplateStringSlice" + }, "body": { "type": "array", "items": { @@ -22361,7 +22364,7 @@ "x-go-name": "FileName" }, "labels": { - "$ref": "#/definitions/IssueTemplateLabels" + "$ref": "#/definitions/IssueTemplateStringSlice" }, "name": { "type": "string", @@ -22378,7 +22381,7 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "IssueTemplateLabels": { + "IssueTemplateStringSlice": { "type": "array", "items": { "type": "string"