Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support issue template assignees #31083

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/content/usage/issue-pull-request-templates.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ name: "Template Name"
about: "This template is for testing!"
title: "[TEST] "
ref: "main"
assignees: ["user1"]
labels:

- bug
Expand All @@ -120,7 +121,9 @@ 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,
`[TEST] ` while the issue body would be pre-populated with `This is the template!`.
The issue would be assigned to `user1`.
The issue would also be assigned two labels,
`bug` and `help needed`, and the issue will have a reference to `main`.

## Syntax for yaml template
Expand Down
3 changes: 2 additions & 1 deletion docs/content/usage/issue-pull-request-templates.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ name: "Template Name"
about: "This template is for testing!"
title: "[TEST] "
ref: "main"
assignees: ["user1"]
labels:

- bug
Expand All @@ -123,7 +124,7 @@ labels:
This is the template!
```

上面的示例表示用户从列表中选择一个工单模板时,列表会展示模板名称 `Template Name` 和模板描述 `This template is for testing!`。 同时,标题会预先填充为 `[TEST]`,而正文将预先填充 `This is the template!`。 最后,Issue 还会被分配两个标签,`bug` 和 `help needed`,并且将问题指向 `main` 分支。
上面的示例表示用户从列表中选择一个工单模板时,列表会展示模板名称 `Template Name` 和模板描述 `This template is for testing!`。 同时,标题会预先填充为 `[TEST]`,而正文将预先填充 `This is the template!`。该 Issue 会被指派给 `user1`。 最后,Issue 还会被分配两个标签,`bug` 和 `help needed`,并且将问题指向 `main` 分支。

## YAML 模板语法

Expand Down
12 changes: 7 additions & 5 deletions modules/issue/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ name: Name
title: Title
about: About
labels: ["label1", "label2"]
assignees: ["user1", "user2"]
ref: Ref
body:
- type: markdown
Expand Down Expand Up @@ -509,11 +510,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",
Expand Down
23 changes: 12 additions & 11 deletions modules/structs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,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
Expand Down Expand Up @@ -216,7 +217,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 {
Expand Down
4 changes: 2 additions & 2 deletions modules/structs/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,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/<ref>
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["selected_assignee_ids_value"] = strings.Join(selectedAssigneeIDStrings, ",")
ctx.Data["selected_assignee_ids"] = selectedAssigneeIDs
Comment on lines 949 to +953
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we mixing camelCase and snake_case in the same method?
Can we simply keep using CamelCase?

ctx.Data["Reference"] = template.Ref
ctx.Data["RefEndName"] = git.RefName(template.Ref).ShortName()
return true, templateErrs
Expand Down
10 changes: 5 additions & 5 deletions templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
</div>
{{end}}
<div class="divider"></div>
<input id="assignee_ids" name="assignee_ids" type="hidden" value="{{.assignee_ids}}">
<input id="assignee_ids" name="assignee_ids" type="hidden" value="{{.selected_assignee_ids_value}}">
<div class="ui {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}} floating jump select-assignees dropdown">
<span class="text flex-text-block">
<strong>{{ctx.Locale.Tr "repo.issues.new.assignees"}}</strong>
Expand All @@ -155,8 +155,8 @@
</div>
<div class="no-select item">{{ctx.Locale.Tr "repo.issues.new.clear_assignees"}}</div>
{{range .Assignees}}
<a class="item muted" href="#" data-id="{{.ID}}" data-id-selector="#assignee_{{.ID}}">
<span class="octicon-check tw-invisible">{{svg "octicon-check"}}</span>
<a class="{{if SliceUtils.Contains $.selected_assignee_ids .ID}}checked{{end}} item muted" href="#" data-id="{{.ID}}" data-id-selector="#assignee_{{.ID}}">
<span class="octicon-check {{if not (SliceUtils.Contains $.selected_assignee_ids .ID)}}tw-invisible{{end}}">{{svg "octicon-check"}}</span>
<span class="text">
{{ctx.AvatarUtils.Avatar . 28 "tw-mr-2"}}{{template "repo/search_name" .}}
</span>
Expand All @@ -165,12 +165,12 @@
</div>
</div>
<div class="ui assignees list">
<span class="no-select item {{if .HasSelectedLabel}}tw-hidden{{end}}">
<span class="no-select item {{if .HasSelectedAssignee}}tw-hidden{{end}}">
{{ctx.Locale.Tr "repo.issues.new.no_assignees"}}
</span>
<div class="selected">
{{range .Assignees}}
<a class="item tw-p-1 muted tw-hidden" id="assignee_{{.ID}}" href="{{$.RepoLink}}/issues?assignee={{.ID}}">
<a class="item tw-p-1 muted {{if not (SliceUtils.Contains $.selected_assignee_ids .ID)}}tw-hidden{{end}}" id="assignee_{{.ID}}" href="{{$.RepoLink}}/issues?assignee={{.ID}}">
{{ctx.AvatarUtils.Avatar . 28 "tw-mr-2 tw-align-middle"}}{{.GetDisplayName}}
</a>
{{end}}
Expand Down
7 changes: 5 additions & 2 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading