@@ -47,13 +47,13 @@ var (
47
47
)
48
48
49
49
type optionFileList struct {
50
- builtin []string
51
- custom []string
50
+ all []string
51
+ custom []string
52
52
}
53
53
54
- // mergeBuiltinCustomFiles merges the builtin and custom files, de-duplicates and returns a sorted list of files
55
- func mergeBuiltinCustomFiles (fl optionFileList ) []string {
56
- files := fl .builtin
54
+ // mergeCustomFiles merges the custom files, de-duplicates and returns a sorted list of files
55
+ func mergeCustomFiles (fl optionFileList ) []string {
56
+ files := fl .all
57
57
for _ , f := range fl .custom {
58
58
// for most cases, the SliceContainsString is good enough because there are only a few custom files
59
59
if ! util .SliceContainsString (files , f ) {
@@ -64,12 +64,24 @@ func mergeBuiltinCustomFiles(fl optionFileList) []string {
64
64
return files
65
65
}
66
66
67
- // mergeBuiltinCustomLabels merges the builtin and custom files. Always use the file's main name as the key to de-duplicate.
68
- func mergeBuiltinCustomLabels (fl optionFileList ) []string {
69
- files := fl .builtin
67
+ // mergeCustomLabels merges the custom label files. Always use the file's main name as the key to de-duplicate.
68
+ func mergeCustomLabels (fl optionFileList ) []string {
69
+ exts := map [string ]int {
70
+ "" : 0 ,
71
+ ".yml" : 1 ,
72
+ ".yaml" : 2 ,
73
+ }
74
+ sort .Slice (fl .all , func (i , j int ) bool {
75
+ return exts [filepath .Ext (fl .all [i ])] < exts [filepath .Ext (fl .all [j ])]
76
+ })
77
+ sort .Slice (fl .custom , func (i , j int ) bool {
78
+ return exts [filepath .Ext (fl .custom [i ])] < exts [filepath .Ext (fl .custom [j ])]
79
+ })
80
+
81
+ files := fl .all
70
82
if len (fl .custom ) > 0 {
71
83
m := map [string ]string {}
72
- for _ , f := range fl .builtin {
84
+ for _ , f := range fl .all {
73
85
m [strings .TrimSuffix (f , filepath .Ext (f ))] = f
74
86
}
75
87
for _ , f := range fl .custom {
@@ -92,7 +104,7 @@ func LoadRepoConfig() error {
92
104
93
105
for i , t := range types {
94
106
var err error
95
- if optionTypeFiles [i ].builtin , err = options .Dir (t ); err != nil {
107
+ if optionTypeFiles [i ].all , err = options .Dir (t ); err != nil {
96
108
return fmt .Errorf ("failed to list %s files: %w" , t , err )
97
109
}
98
110
customPath := filepath .Join (setting .CustomPath , "options" , t )
@@ -106,10 +118,10 @@ func LoadRepoConfig() error {
106
118
}
107
119
}
108
120
109
- Gitignores = mergeBuiltinCustomFiles (optionTypeFiles [0 ])
110
- Licenses = mergeBuiltinCustomFiles (optionTypeFiles [1 ])
111
- Readmes = mergeBuiltinCustomFiles (optionTypeFiles [2 ])
112
- labelTemplatesFiles := mergeBuiltinCustomLabels (optionTypeFiles [3 ])
121
+ Gitignores = mergeCustomFiles (optionTypeFiles [0 ])
122
+ Licenses = mergeCustomFiles (optionTypeFiles [1 ])
123
+ Readmes = mergeCustomFiles (optionTypeFiles [2 ])
124
+ labelTemplatesFiles := mergeCustomLabels (optionTypeFiles [3 ])
113
125
114
126
// Load label templates
115
127
for _ , templateFile := range labelTemplatesFiles {
0 commit comments