@@ -30,24 +30,24 @@ func IsErrTemplateLoad(err error) bool {
30
30
}
31
31
32
32
func (err ErrTemplateLoad ) Error () string {
33
- return fmt .Sprintf ("Failed to load label template file '%s' : %v" , err .TemplateFile , err .OriginalError )
33
+ return fmt .Sprintf ("failed to load label template file %q : %v" , err .TemplateFile , err .OriginalError )
34
34
}
35
35
36
- // GetTemplateFile loads the label template file by given name,
36
+ // LoadTemplateFile loads the label template file by given file name,
37
37
// then parses and returns a list of name-color pairs and optionally description.
38
- func GetTemplateFile ( name string ) ([]* Label , error ) {
39
- data , err := options .Labels (name )
38
+ func LoadTemplateFile ( fileName string ) ([]* Label , error ) {
39
+ data , err := options .Labels (fileName )
40
40
if err != nil {
41
- return nil , ErrTemplateLoad {name , fmt .Errorf ("GetTemplateFile : %w" , err )}
41
+ return nil , ErrTemplateLoad {fileName , fmt .Errorf ("LoadTemplateFile : %w" , err )}
42
42
}
43
43
44
- if strings .HasSuffix (name , ".yaml" ) || strings .HasSuffix (name , ".yml" ) {
45
- return parseYamlFormat (name , data )
44
+ if strings .HasSuffix (fileName , ".yaml" ) || strings .HasSuffix (fileName , ".yml" ) {
45
+ return parseYamlFormat (fileName , data )
46
46
}
47
- return parseLegacyFormat (name , data )
47
+ return parseLegacyFormat (fileName , data )
48
48
}
49
49
50
- func parseYamlFormat (name string , data []byte ) ([]* Label , error ) {
50
+ func parseYamlFormat (fileName string , data []byte ) ([]* Label , error ) {
51
51
lf := & labelFile {}
52
52
53
53
if err := yaml .Unmarshal (data , lf ); err != nil {
@@ -58,19 +58,19 @@ func parseYamlFormat(name string, data []byte) ([]*Label, error) {
58
58
for _ , l := range lf .Labels {
59
59
l .Color = strings .TrimSpace (l .Color )
60
60
if len (l .Name ) == 0 || len (l .Color ) == 0 {
61
- return nil , ErrTemplateLoad {name , errors .New ("label name and color are required fields" )}
61
+ return nil , ErrTemplateLoad {fileName , errors .New ("label name and color are required fields" )}
62
62
}
63
63
color , err := NormalizeColor (l .Color )
64
64
if err != nil {
65
- return nil , ErrTemplateLoad {name , fmt .Errorf ("bad HTML color code '%s' in label: %s" , l .Color , l .Name )}
65
+ return nil , ErrTemplateLoad {fileName , fmt .Errorf ("bad HTML color code '%s' in label: %s" , l .Color , l .Name )}
66
66
}
67
67
l .Color = color
68
68
}
69
69
70
70
return lf .Labels , nil
71
71
}
72
72
73
- func parseLegacyFormat (name string , data []byte ) ([]* Label , error ) {
73
+ func parseLegacyFormat (fileName string , data []byte ) ([]* Label , error ) {
74
74
lines := strings .Split (string (data ), "\n " )
75
75
list := make ([]* Label , 0 , len (lines ))
76
76
for i := 0 ; i < len (lines ); i ++ {
@@ -81,18 +81,18 @@ func parseLegacyFormat(name string, data []byte) ([]*Label, error) {
81
81
82
82
parts , description , _ := strings .Cut (line , ";" )
83
83
84
- color , name , ok := strings .Cut (parts , " " )
84
+ color , labelName , ok := strings .Cut (parts , " " )
85
85
if ! ok {
86
- return nil , ErrTemplateLoad {name , fmt .Errorf ("line is malformed: %s" , line )}
86
+ return nil , ErrTemplateLoad {fileName , fmt .Errorf ("line is malformed: %s" , line )}
87
87
}
88
88
89
89
color , err := NormalizeColor (color )
90
90
if err != nil {
91
- return nil , ErrTemplateLoad {name , fmt .Errorf ("bad HTML color code '%s' in line: %s" , color , line )}
91
+ return nil , ErrTemplateLoad {fileName , fmt .Errorf ("bad HTML color code '%s' in line: %s" , color , line )}
92
92
}
93
93
94
94
list = append (list , & Label {
95
- Name : strings .TrimSpace (name ),
95
+ Name : strings .TrimSpace (labelName ),
96
96
Color : color ,
97
97
Description : strings .TrimSpace (description ),
98
98
})
@@ -101,10 +101,10 @@ func parseLegacyFormat(name string, data []byte) ([]*Label, error) {
101
101
return list , nil
102
102
}
103
103
104
- // LoadFormatted loads the labels' list of a template file as a string separated by comma
105
- func LoadFormatted ( name string ) (string , error ) {
104
+ // LoadLabelFileDescription loads the labels' list of a template file as a string separated by comma
105
+ func LoadLabelFileDescription ( fileName string ) (string , error ) {
106
106
var buf strings.Builder
107
- list , err := GetTemplateFile ( name )
107
+ list , err := LoadTemplateFile ( fileName )
108
108
if err != nil {
109
109
return "" , err
110
110
}
0 commit comments