MCPcopy Create free account
hub / github.com/gogs/gogs / GetLabelTemplateFile

Function GetLabelTemplateFile

internal/database/issue_label.go:23–51  ·  view source on GitHub ↗

GetLabelTemplateFile loads the label template file by given name, then parses and returns a list of name-color pairs.

(name string)

Source from the content-addressed store, hash-verified

21// GetLabelTemplateFile loads the label template file by given name,
22// then parses and returns a list of name-color pairs.
23func 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.
54type Label struct {

Callers 1

InitializeLabelsFunction · 0.92

Calls 5

getRepoInitFileFunction · 0.85
stringFunction · 0.85
appendFunction · 0.85
SplitMethod · 0.80
MatchStringMethod · 0.80

Tested by

no test coverage detected