aboutsummaryrefslogtreecommitdiffstats
path: root/modules/issue/template
diff options
context:
space:
mode:
Diffstat (limited to 'modules/issue/template')
-rw-r--r--modules/issue/template/template.go4
-rw-r--r--modules/issue/template/template_test.go312
-rw-r--r--modules/issue/template/unmarshal.go2
3 files changed, 220 insertions, 98 deletions
diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go
index 3b33852cb5..0bdf5a1987 100644
--- a/modules/issue/template/template.go
+++ b/modules/issue/template/template.go
@@ -165,7 +165,7 @@ func validateOptions(field *api.IssueFormField, idx int) error {
return position.Errorf("should be a string")
}
case api.IssueFormFieldTypeCheckboxes:
- opt, ok := option.(map[interface{}]interface{})
+ opt, ok := option.(map[string]interface{})
if !ok {
return position.Errorf("should be a dictionary")
}
@@ -351,7 +351,7 @@ func (o *valuedOption) Label() string {
return label
}
case api.IssueFormFieldTypeCheckboxes:
- if vs, ok := o.data.(map[interface{}]interface{}); ok {
+ if vs, ok := o.data.(map[string]interface{}); ok {
if v, ok := vs["label"].(string); ok {
return v
}
diff --git a/modules/issue/template/template_test.go b/modules/issue/template/template_test.go
index 883e1e0780..c3863a64a6 100644
--- a/modules/issue/template/template_test.go
+++ b/modules/issue/template/template_test.go
@@ -6,18 +6,21 @@ package template
import (
"net/url"
- "reflect"
"testing"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
+
+ "github.com/stretchr/testify/require"
)
func TestValidate(t *testing.T) {
tests := []struct {
- name string
- content string
- wantErr string
+ name string
+ filename string
+ content string
+ want *api.IssueTemplate
+ wantErr string
}{
{
name: "miss name",
@@ -316,21 +319,9 @@ body:
`,
wantErr: "body[0](checkboxes), option[0]: 'required' should be a bool",
},
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- tmpl, err := unmarshal("test.yaml", []byte(tt.content))
- if err != nil {
- t.Fatal(err)
- }
- if err := Validate(tmpl); (err == nil) != (tt.wantErr == "") || err != nil && err.Error() != tt.wantErr {
- t.Errorf("Validate() error = %v, wantErr %q", err, tt.wantErr)
- }
- })
- }
-
- t.Run("valid", func(t *testing.T) {
- content := `
+ {
+ name: "valid",
+ content: `
name: Name
title: Title
about: About
@@ -386,96 +377,227 @@ body:
required: false
- label: Option 3 of checkboxes
required: true
-`
- want := &api.IssueTemplate{
- Name: "Name",
- Title: "Title",
- About: "About",
- Labels: []string{"label1", "label2"},
- Ref: "Ref",
- Fields: []*api.IssueFormField{
- {
- Type: "markdown",
- ID: "id1",
- Attributes: map[string]interface{}{
- "value": "Value of the markdown",
+`,
+ want: &api.IssueTemplate{
+ Name: "Name",
+ Title: "Title",
+ About: "About",
+ Labels: []string{"label1", "label2"},
+ Ref: "Ref",
+ Fields: []*api.IssueFormField{
+ {
+ Type: "markdown",
+ ID: "id1",
+ Attributes: map[string]interface{}{
+ "value": "Value of the markdown",
+ },
},
- },
- {
- Type: "textarea",
- ID: "id2",
- Attributes: map[string]interface{}{
- "label": "Label of textarea",
- "description": "Description of textarea",
- "placeholder": "Placeholder of textarea",
- "value": "Value of textarea",
- "render": "bash",
+ {
+ Type: "textarea",
+ ID: "id2",
+ Attributes: map[string]interface{}{
+ "label": "Label of textarea",
+ "description": "Description of textarea",
+ "placeholder": "Placeholder of textarea",
+ "value": "Value of textarea",
+ "render": "bash",
+ },
+ Validations: map[string]interface{}{
+ "required": true,
+ },
},
- Validations: map[string]interface{}{
- "required": true,
+ {
+ Type: "input",
+ ID: "id3",
+ Attributes: map[string]interface{}{
+ "label": "Label of input",
+ "description": "Description of input",
+ "placeholder": "Placeholder of input",
+ "value": "Value of input",
+ },
+ Validations: map[string]interface{}{
+ "required": true,
+ "is_number": true,
+ "regex": "[a-zA-Z0-9]+",
+ },
},
- },
- {
- Type: "input",
- ID: "id3",
- Attributes: map[string]interface{}{
- "label": "Label of input",
- "description": "Description of input",
- "placeholder": "Placeholder of input",
- "value": "Value of input",
+ {
+ Type: "dropdown",
+ ID: "id4",
+ Attributes: map[string]interface{}{
+ "label": "Label of dropdown",
+ "description": "Description of dropdown",
+ "multiple": true,
+ "options": []interface{}{
+ "Option 1 of dropdown",
+ "Option 2 of dropdown",
+ "Option 3 of dropdown",
+ },
+ },
+ Validations: map[string]interface{}{
+ "required": true,
+ },
},
- Validations: map[string]interface{}{
- "required": true,
- "is_number": true,
- "regex": "[a-zA-Z0-9]+",
+ {
+ Type: "checkboxes",
+ ID: "id5",
+ Attributes: map[string]interface{}{
+ "label": "Label of checkboxes",
+ "description": "Description of checkboxes",
+ "options": []interface{}{
+ map[string]interface{}{"label": "Option 1 of checkboxes", "required": true},
+ map[string]interface{}{"label": "Option 2 of checkboxes", "required": false},
+ map[string]interface{}{"label": "Option 3 of checkboxes", "required": true},
+ },
+ },
},
},
- {
- Type: "dropdown",
- ID: "id4",
- Attributes: map[string]interface{}{
- "label": "Label of dropdown",
- "description": "Description of dropdown",
- "multiple": true,
- "options": []interface{}{
- "Option 1 of dropdown",
- "Option 2 of dropdown",
- "Option 3 of dropdown",
+ FileName: "test.yaml",
+ },
+ wantErr: "",
+ },
+ {
+ name: "single label",
+ content: `
+name: Name
+title: Title
+about: About
+labels: label1
+ref: Ref
+body:
+ - type: markdown
+ id: id1
+ attributes:
+ value: Value of the markdown
+`,
+ want: &api.IssueTemplate{
+ Name: "Name",
+ Title: "Title",
+ About: "About",
+ Labels: []string{"label1"},
+ Ref: "Ref",
+ Fields: []*api.IssueFormField{
+ {
+ Type: "markdown",
+ ID: "id1",
+ Attributes: map[string]interface{}{
+ "value": "Value of the markdown",
},
},
- Validations: map[string]interface{}{
- "required": true,
+ },
+ FileName: "test.yaml",
+ },
+ wantErr: "",
+ },
+ {
+ name: "comma-delimited labels",
+ content: `
+name: Name
+title: Title
+about: About
+labels: label1,label2,,label3 ,,
+ref: Ref
+body:
+ - type: markdown
+ id: id1
+ attributes:
+ value: Value of the markdown
+`,
+ want: &api.IssueTemplate{
+ Name: "Name",
+ Title: "Title",
+ About: "About",
+ Labels: []string{"label1", "label2", "label3"},
+ Ref: "Ref",
+ Fields: []*api.IssueFormField{
+ {
+ Type: "markdown",
+ ID: "id1",
+ Attributes: map[string]interface{}{
+ "value": "Value of the markdown",
+ },
},
},
- {
- Type: "checkboxes",
- ID: "id5",
- Attributes: map[string]interface{}{
- "label": "Label of checkboxes",
- "description": "Description of checkboxes",
- "options": []interface{}{
- map[interface{}]interface{}{"label": "Option 1 of checkboxes", "required": true},
- map[interface{}]interface{}{"label": "Option 2 of checkboxes", "required": false},
- map[interface{}]interface{}{"label": "Option 3 of checkboxes", "required": true},
+ FileName: "test.yaml",
+ },
+ wantErr: "",
+ },
+ {
+ name: "empty string as labels",
+ content: `
+name: Name
+title: Title
+about: About
+labels: ''
+ref: Ref
+body:
+ - type: markdown
+ id: id1
+ attributes:
+ value: Value of the markdown
+`,
+ want: &api.IssueTemplate{
+ Name: "Name",
+ Title: "Title",
+ About: "About",
+ Labels: nil,
+ Ref: "Ref",
+ Fields: []*api.IssueFormField{
+ {
+ Type: "markdown",
+ ID: "id1",
+ Attributes: map[string]interface{}{
+ "value": "Value of the markdown",
},
},
},
+ FileName: "test.yaml",
},
- FileName: "test.yaml",
- }
- got, err := unmarshal("test.yaml", []byte(content))
- if err != nil {
- t.Fatal(err)
- }
- if err := Validate(got); err != nil {
- t.Errorf("Validate() error = %v", err)
- }
- if !reflect.DeepEqual(want, got) {
- jsonWant, _ := json.Marshal(want)
- jsonGot, _ := json.Marshal(got)
- t.Errorf("want:\n%s\ngot:\n%s", jsonWant, jsonGot)
- }
- })
+ wantErr: "",
+ },
+ {
+ name: "comma delimited labels in markdown",
+ filename: "test.md",
+ content: `---
+name: Name
+title: Title
+about: About
+labels: label1,label2,,label3 ,,
+ref: Ref
+---
+Content
+`,
+ want: &api.IssueTemplate{
+ Name: "Name",
+ Title: "Title",
+ About: "About",
+ Labels: []string{"label1", "label2", "label3"},
+ Ref: "Ref",
+ Fields: nil,
+ Content: "Content\n",
+ FileName: "test.md",
+ },
+ wantErr: "",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ filename := "test.yaml"
+ if tt.filename != "" {
+ filename = tt.filename
+ }
+ tmpl, err := unmarshal(filename, []byte(tt.content))
+ require.NoError(t, err)
+ if tt.wantErr != "" {
+ require.EqualError(t, Validate(tmpl), tt.wantErr)
+ } else {
+ require.NoError(t, Validate(tmpl))
+ want, _ := json.Marshal(tt.want)
+ got, _ := json.Marshal(tmpl)
+ require.JSONEq(t, string(want), string(got))
+ }
+ })
+ }
}
func TestRenderToMarkdown(t *testing.T) {
diff --git a/modules/issue/template/unmarshal.go b/modules/issue/template/unmarshal.go
index 24587b0fed..3398719cf6 100644
--- a/modules/issue/template/unmarshal.go
+++ b/modules/issue/template/unmarshal.go
@@ -16,7 +16,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
- "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v3"
)
// CouldBe indicates a file with the filename could be a template,
Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/FullTextSearch/Model/ISearchOption.php
blob: 8e902296ff6afed9640f945042a0cf4cecd4551e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165