Skip to content

Commit 8917af8

Browse files
authored
Ignore issue template with a special name (#21830) (#21835)
Backport #21830. A file in `ISSUE_TEMPLATE` with the name `config.yml` shouldn't be treated as a YAML template, it's for [configuring the template chooser](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser). The old code tried to ignore the file, but it didn't work, caused by #20987. That's why the warning is displayed: <img width="415" alt="image" src="https://user-images.githubusercontent.com/9418365/202094067-804c42fe-0e9e-4fc5-bf01-d95fa336f54f.png"> Note that this PR is not an implementation of `config.yml`, there will be another one to do it.
1 parent 0d25292 commit 8917af8

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Diff for: modules/structs/issue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package structs
66

77
import (
8-
"path/filepath"
8+
"path"
99
"time"
1010
)
1111

@@ -163,11 +163,11 @@ const (
163163

164164
// Type returns the type of IssueTemplate, can be "md", "yaml" or empty for known
165165
func (it IssueTemplate) Type() IssueTemplateType {
166-
if it.Name == "config.yaml" || it.Name == "config.yml" {
166+
if base := path.Base(it.FileName); base == "config.yaml" || base == "config.yml" {
167167
// ignore config.yaml which is a special configuration file
168168
return ""
169169
}
170-
if ext := filepath.Ext(it.FileName); ext == ".md" {
170+
if ext := path.Ext(it.FileName); ext == ".md" {
171171
return IssueTemplateTypeMarkdown
172172
} else if ext == ".yaml" || ext == ".yml" {
173173
return IssueTemplateTypeYaml

Diff for: modules/structs/issue_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package structs
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestIssueTemplate_Type(t *testing.T) {
14+
tests := []struct {
15+
fileName string
16+
want IssueTemplateType
17+
}{
18+
{
19+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.yaml",
20+
want: IssueTemplateTypeYaml,
21+
},
22+
{
23+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.md",
24+
want: IssueTemplateTypeMarkdown,
25+
},
26+
{
27+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.txt",
28+
want: "",
29+
},
30+
{
31+
fileName: ".gitea/ISSUE_TEMPLATE/config.yaml",
32+
want: "",
33+
},
34+
}
35+
for _, tt := range tests {
36+
t.Run(tt.fileName, func(t *testing.T) {
37+
it := IssueTemplate{
38+
FileName: tt.fileName,
39+
}
40+
assert.Equal(t, tt.want, it.Type())
41+
})
42+
}
43+
}

0 commit comments

Comments
 (0)