File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 55package structs
66
77import (
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
165165func (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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments