GetLabelTemplateFile loads the label template file by given name, then parses and returns a list of name-color pairs.
(name string)
| 21 | // GetLabelTemplateFile loads the label template file by given name, |
| 22 | // then parses and returns a list of name-color pairs. |
| 23 | func GetLabelTemplateFile(name string) ([][2]string, error) { |
| 24 | data, err := getRepoInitFile("label", name) |
| 25 | if err != nil { |
| 26 | return nil, errors.Newf("getRepoInitFile: %v", err) |
| 27 | } |
| 28 | |
| 29 | lines := strings.Split(string(data), "\n") |
| 30 | list := make([][2]string, 0, len(lines)) |
| 31 | for i := 0; i < len(lines); i++ { |
| 32 | line := strings.TrimSpace(lines[i]) |
| 33 | if line == "" { |
| 34 | continue |
| 35 | } |
| 36 | |
| 37 | fields := strings.SplitN(line, " ", 2) |
| 38 | if len(fields) != 2 { |
| 39 | return nil, errors.Newf("line is malformed: %s", line) |
| 40 | } |
| 41 | |
| 42 | if !labelColorPattern.MatchString(fields[0]) { |
| 43 | return nil, errors.Newf("bad HTML color code in line: %s", line) |
| 44 | } |
| 45 | |
| 46 | fields[1] = strings.TrimSpace(fields[1]) |
| 47 | list = append(list, [2]string{fields[1], fields[0]}) |
| 48 | } |
| 49 | |
| 50 | return list, nil |
| 51 | } |
| 52 | |
| 53 | // Label represents a label of repository for issues. |
| 54 | type Label struct { |
no test coverage detected