forked from forgejo/forgejo
Backport #21831. The [labels in issue YAML templates](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms#top-level-syntax) can be a string array or a comma-delimited string, so a single string should be valid labels. The old codes committed in #20987 ignore this, that's why the warning is displayed: <img width="618" alt="image" src="https://user-images.githubusercontent.com/9418365/202112642-93dc72d0-71c3-40a2-9720-30fc2d48c97c.png"> Fixes #17877.
This commit is contained in:
parent
af8b2250c4
commit
7a004ad7eb
7 changed files with 369 additions and 140 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestIssueTemplate_Type(t *testing.T) {
|
||||
|
@ -41,3 +42,65 @@ func TestIssueTemplate_Type(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueTemplateLabels_UnmarshalYAML(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
tmpl *IssueTemplate
|
||||
want *IssueTemplate
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "array",
|
||||
content: `labels: ["a", "b", "c"]`,
|
||||
tmpl: &IssueTemplate{
|
||||
Labels: []string{"should_be_overwrote"},
|
||||
},
|
||||
want: &IssueTemplate{
|
||||
Labels: []string{"a", "b", "c"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "string",
|
||||
content: `labels: "a,b,c"`,
|
||||
tmpl: &IssueTemplate{
|
||||
Labels: []string{"should_be_overwrote"},
|
||||
},
|
||||
want: &IssueTemplate{
|
||||
Labels: []string{"a", "b", "c"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
content: `labels:`,
|
||||
tmpl: &IssueTemplate{
|
||||
Labels: []string{"should_be_overwrote"},
|
||||
},
|
||||
want: &IssueTemplate{
|
||||
Labels: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "error",
|
||||
content: `
|
||||
labels:
|
||||
a: aa
|
||||
b: bb
|
||||
`,
|
||||
tmpl: &IssueTemplate{},
|
||||
wantErr: "line 3: cannot unmarshal !!map into IssueTemplateLabels",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := yaml.Unmarshal([]byte(tt.content), tt.tmpl)
|
||||
if tt.wantErr != "" {
|
||||
assert.EqualError(t, err, tt.wantErr)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, tt.tmpl)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue