@@ -47,30 +47,13 @@ var (
47
47
)
48
48
49
49
type optionFileList struct {
50
- all []string
51
- custom []string
52
- }
53
-
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
- for _ , f := range fl .custom {
58
- // for most cases, the SliceContainsString is good enough because there are only a few custom files
59
- if ! util .SliceContainsString (files , f ) {
60
- files = append (files , f )
61
- }
62
- }
63
- sort .Strings (files )
64
- return files
50
+ all []string // all files provided by bindata & custom-path. sorted.
51
+ custom []string // custom files provided by custom-path. non-sorted.
65
52
}
66
53
67
54
// mergeCustomLabels merges the custom label files. Always use the file's main name as the key to de-duplicate.
68
55
func mergeCustomLabels (fl optionFileList ) []string {
69
- exts := map [string ]int {
70
- "" : 0 ,
71
- ".yml" : 1 ,
72
- ".yaml" : 2 ,
73
- }
56
+ exts := map [string ]int {"" : 0 , ".yml" : 1 , ".yaml" : 2 } // "yaml" file has the highest priority to be used.
74
57
sort .Slice (fl .all , func (i , j int ) bool {
75
58
return exts [filepath .Ext (fl .all [i ])] < exts [filepath .Ext (fl .all [j ])]
76
59
})
@@ -98,32 +81,31 @@ func mergeCustomLabels(fl optionFileList) []string {
98
81
99
82
// LoadRepoConfig loads the repository config
100
83
func LoadRepoConfig () error {
101
- // Load .gitignore and license files and readme templates.
102
- types := []string {"gitignore" , "license" , "readme" , "label" }
103
- optionTypeFiles := make ([]optionFileList , len (types ))
104
-
84
+ types := []string {"gitignore" , "license" , "readme" , "label" } // option file directories
85
+ typeFiles := make ([]optionFileList , len (types ))
105
86
for i , t := range types {
106
87
var err error
107
- if optionTypeFiles [i ].all , err = options .Dir (t ); err != nil {
88
+ if typeFiles [i ].all , err = options .Dir (t ); err != nil {
108
89
return fmt .Errorf ("failed to list %s files: %w" , t , err )
109
90
}
91
+ sort .Strings (typeFiles [i ].all )
110
92
customPath := filepath .Join (setting .CustomPath , "options" , t )
111
93
if isDir , err := util .IsDir (customPath ); err != nil {
112
94
return fmt .Errorf ("failed to check custom %s dir: %w" , t , err )
113
95
} else if isDir {
114
- optionTypeFiles [i ].custom , err = util .StatDir (customPath )
96
+ typeFiles [i ].custom , err = util .StatDir (customPath )
115
97
if err != nil {
116
98
return fmt .Errorf ("failed to list custom %s files: %w" , t , err )
117
99
}
118
100
}
119
101
}
120
102
121
- Gitignores = mergeCustomFiles (optionTypeFiles [0 ])
122
- Licenses = mergeCustomFiles (optionTypeFiles [1 ])
123
- Readmes = mergeCustomFiles (optionTypeFiles [2 ])
124
- labelTemplatesFiles := mergeCustomLabels (optionTypeFiles [3 ])
103
+ Gitignores = typeFiles [0 ].all
104
+ Licenses = typeFiles [1 ].all
105
+ Readmes = typeFiles [2 ].all
125
106
126
107
// Load label templates
108
+ labelTemplatesFiles := mergeCustomLabels (typeFiles [3 ])
127
109
for _ , templateFile := range labelTemplatesFiles {
128
110
labels , err := label .LoadFormatted (templateFile )
129
111
if err != nil {
0 commit comments