aboutsummaryrefslogtreecommitdiffstats
path: root/modules/issue/template
diff options
context:
space:
mode:
Diffstat (limited to 'modules/issue/template')
-rw-r--r--modules/issue/template/template.go19
-rw-r--r--modules/issue/template/template_test.go7
-rw-r--r--modules/issue/template/unmarshal.go2
3 files changed, 12 insertions, 16 deletions
diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go
index a2b9d6b33e..192aaf8e01 100644
--- a/modules/issue/template/template.go
+++ b/modules/issue/template/template.go
@@ -4,9 +4,11 @@
package template
import (
+ "errors"
"fmt"
"net/url"
"regexp"
+ "slices"
"strconv"
"strings"
@@ -31,17 +33,17 @@ func Validate(template *api.IssueTemplate) error {
func validateMetadata(template *api.IssueTemplate) error {
if strings.TrimSpace(template.Name) == "" {
- return fmt.Errorf("'name' is required")
+ return errors.New("'name' is required")
}
if strings.TrimSpace(template.About) == "" {
- return fmt.Errorf("'about' is required")
+ return errors.New("'about' is required")
}
return nil
}
func validateYaml(template *api.IssueTemplate) error {
if len(template.Fields) == 0 {
- return fmt.Errorf("'body' is required")
+ return errors.New("'body' is required")
}
ids := make(container.Set[string])
for idx, field := range template.Fields {
@@ -401,7 +403,7 @@ func (f *valuedField) Render() string {
}
func (f *valuedField) Value() string {
- return strings.TrimSpace(f.Get(fmt.Sprintf("form-field-%s", f.ID)))
+ return strings.TrimSpace(f.Get("form-field-" + f.ID))
}
func (f *valuedField) Options() []*valuedOption {
@@ -444,14 +446,9 @@ func (o *valuedOption) Label() string {
func (o *valuedOption) IsChecked() bool {
switch o.field.Type {
case api.IssueFormFieldTypeDropdown:
- checks := strings.Split(o.field.Get(fmt.Sprintf("form-field-%s", o.field.ID)), ",")
+ checks := strings.Split(o.field.Get("form-field-"+o.field.ID), ",")
idx := strconv.Itoa(o.index)
- for _, v := range checks {
- if v == idx {
- return true
- }
- }
- return false
+ return slices.Contains(checks, idx)
case api.IssueFormFieldTypeCheckboxes:
return o.field.Get(fmt.Sprintf("form-field-%s-%d", o.field.ID, o.index)) == "on"
}
diff --git a/modules/issue/template/template_test.go b/modules/issue/template/template_test.go
index 689a285b47..7fec9431b6 100644
--- a/modules/issue/template/template_test.go
+++ b/modules/issue/template/template_test.go
@@ -904,7 +904,7 @@ Option 1 of dropdown, Option 2 of dropdown
t.Fatal(err)
}
if got := RenderToMarkdown(template, tt.args.values); got != tt.want {
- assert.EqualValues(t, tt.want, got)
+ assert.Equal(t, tt.want, got)
}
})
}
@@ -957,9 +957,8 @@ func Test_minQuotes(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- if got := minQuotes(tt.args.value); got != tt.want {
- t.Errorf("minQuotes() = %v, want %v", got, tt.want)
- }
+ got := minQuotes(tt.args.value)
+ assert.Equal(t, tt.want, got)
})
}
}
diff --git a/modules/issue/template/unmarshal.go b/modules/issue/template/unmarshal.go
index 0fc13d7ddf..1d8e9dd02d 100644
--- a/modules/issue/template/unmarshal.go
+++ b/modules/issue/template/unmarshal.go
@@ -109,7 +109,7 @@ func unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
it.Content = string(content)
it.Name = path.Base(it.FileName) // paths in Git are always '/' separated - do not use filepath!
- it.About, _ = util.SplitStringAtByteN(it.Content, 80)
+ it.About = util.EllipsisDisplayString(it.Content, 80)
} else {
it.Content = templateBody
if it.About == "" {