@@ -30,24 +30,24 @@ func IsErrTemplateLoad(err error) bool {
3030}
3131
3232func (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 )
3434}
3535
36- // GetTemplateFile loads the label template file by given name,
36+ // LoadTemplateFile loads the label template file by given file name,
3737// 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 )
4040 if err != nil {
41- return nil , ErrTemplateLoad {name , fmt .Errorf ("GetTemplateFile : %w" , err )}
41+ return nil , ErrTemplateLoad {fileName , fmt .Errorf ("LoadTemplateFile : %w" , err )}
4242 }
4343
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 )
4646 }
47- return parseLegacyFormat (name , data )
47+ return parseLegacyFormat (fileName , data )
4848}
4949
50- func parseYamlFormat (name string , data []byte ) ([]* Label , error ) {
50+ func parseYamlFormat (fileName string , data []byte ) ([]* Label , error ) {
5151 lf := & labelFile {}
5252
5353 if err := yaml .Unmarshal (data , lf ); err != nil {
@@ -58,19 +58,19 @@ func parseYamlFormat(name string, data []byte) ([]*Label, error) {
5858 for _ , l := range lf .Labels {
5959 l .Color = strings .TrimSpace (l .Color )
6060 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" )}
6262 }
6363 color , err := NormalizeColor (l .Color )
6464 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 )}
6666 }
6767 l .Color = color
6868 }
6969
7070 return lf .Labels , nil
7171}
7272
73- func parseLegacyFormat (name string , data []byte ) ([]* Label , error ) {
73+ func parseLegacyFormat (fileName string , data []byte ) ([]* Label , error ) {
7474 lines := strings .Split (string (data ), "\n " )
7575 list := make ([]* Label , 0 , len (lines ))
7676 for i := 0 ; i < len (lines ); i ++ {
@@ -81,18 +81,18 @@ func parseLegacyFormat(name string, data []byte) ([]*Label, error) {
8181
8282 parts , description , _ := strings .Cut (line , ";" )
8383
84- color , name , ok := strings .Cut (parts , " " )
84+ color , labelName , ok := strings .Cut (parts , " " )
8585 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 )}
8787 }
8888
8989 color , err := NormalizeColor (color )
9090 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 )}
9292 }
9393
9494 list = append (list , & Label {
95- Name : strings .TrimSpace (name ),
95+ Name : strings .TrimSpace (labelName ),
9696 Color : color ,
9797 Description : strings .TrimSpace (description ),
9898 })
@@ -101,10 +101,10 @@ func parseLegacyFormat(name string, data []byte) ([]*Label, error) {
101101 return list , nil
102102}
103103
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 ) {
106106 var buf strings.Builder
107- list , err := GetTemplateFile ( name )
107+ list , err := LoadTemplateFile ( fileName )
108108 if err != nil {
109109 return "" , err
110110 }
0 commit comments