Skip to content

Commit 1064e81

Browse files
authored
Issue Templates: add option to have dropdown printed list (#31577)
Issue template dropdown can have many entries, and it could be better to have them rendered as list later on if multi-select is enabled. so this adds an option to the issue template engine to do so. DOCS: https://gitea.com/gitea/docs/pulls/19 --- ## demo: ```yaml name: Name title: Title about: About labels: ["label1", "label2"] ref: Ref body: - type: dropdown id: id6 attributes: label: Label of dropdown (list) description: Description of dropdown multiple: true list: true options: - Option 1 of dropdown - Option 2 of dropdown - Option 3 of dropdown - Option 4 of dropdown - Option 5 of dropdown - Option 6 of dropdown - Option 7 of dropdown - Option 8 of dropdown - Option 9 of dropdown ``` ![image](https://github.com/user-attachments/assets/102ed0f4-89da-420b-ab2a-1788b59676f9) ![image](https://github.com/user-attachments/assets/a2bdb14e-43ff-4cc6-9bbe-20244830453c) --- *Sponsored by Kithara Software GmbH*
1 parent 957c75b commit 1064e81

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

modules/issue/template/template.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func validateYaml(template *api.IssueTemplate) error {
8888
if err := validateBoolItem(position, field.Attributes, "multiple"); err != nil {
8989
return err
9090
}
91+
if err := validateBoolItem(position, field.Attributes, "list"); err != nil {
92+
return err
93+
}
9194
if err := validateOptions(field, idx); err != nil {
9295
return err
9396
}
@@ -340,7 +343,13 @@ func (f *valuedField) WriteTo(builder *strings.Builder) {
340343
}
341344
}
342345
if len(checkeds) > 0 {
343-
_, _ = fmt.Fprintf(builder, "%s\n", strings.Join(checkeds, ", "))
346+
if list, ok := f.Attributes["list"].(bool); ok && list {
347+
for _, check := range checkeds {
348+
_, _ = fmt.Fprintf(builder, "- %s\n", check)
349+
}
350+
} else {
351+
_, _ = fmt.Fprintf(builder, "%s\n", strings.Join(checkeds, ", "))
352+
}
344353
} else {
345354
_, _ = fmt.Fprint(builder, blankPlaceholder)
346355
}

modules/issue/template/template_test.go

+38-5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ body:
216216
`,
217217
wantErr: "body[0](dropdown): 'multiple' should be a bool",
218218
},
219+
{
220+
name: "dropdown invalid list",
221+
content: `
222+
name: "test"
223+
about: "this is about"
224+
body:
225+
- type: "dropdown"
226+
id: "1"
227+
attributes:
228+
label: "a"
229+
list: "on"
230+
`,
231+
wantErr: "body[0](dropdown): 'list' should be a bool",
232+
},
219233
{
220234
name: "checkboxes invalid description",
221235
content: `
@@ -807,7 +821,7 @@ body:
807821
- type: dropdown
808822
id: id5
809823
attributes:
810-
label: Label of dropdown
824+
label: Label of dropdown (one line)
811825
description: Description of dropdown
812826
multiple: true
813827
options:
@@ -816,8 +830,21 @@ body:
816830
- Option 3 of dropdown
817831
validations:
818832
required: true
819-
- type: checkboxes
833+
- type: dropdown
820834
id: id6
835+
attributes:
836+
label: Label of dropdown (list)
837+
description: Description of dropdown
838+
multiple: true
839+
list: true
840+
options:
841+
- Option 1 of dropdown
842+
- Option 2 of dropdown
843+
- Option 3 of dropdown
844+
validations:
845+
required: true
846+
- type: checkboxes
847+
id: id7
821848
attributes:
822849
label: Label of checkboxes
823850
description: Description of checkboxes
@@ -836,8 +863,9 @@ body:
836863
"form-field-id3": {"Value of id3"},
837864
"form-field-id4": {"Value of id4"},
838865
"form-field-id5": {"0,1"},
839-
"form-field-id6-0": {"on"},
840-
"form-field-id6-2": {"on"},
866+
"form-field-id6": {"1,2"},
867+
"form-field-id7-0": {"on"},
868+
"form-field-id7-2": {"on"},
841869
},
842870
},
843871

@@ -849,10 +877,15 @@ body:
849877
850878
Value of id4
851879
852-
### Label of dropdown
880+
### Label of dropdown (one line)
853881
854882
Option 1 of dropdown, Option 2 of dropdown
855883
884+
### Label of dropdown (list)
885+
886+
- Option 2 of dropdown
887+
- Option 3 of dropdown
888+
856889
### Label of checkboxes
857890
858891
- [x] Option 1 of checkboxes

0 commit comments

Comments
 (0)