diff options
author | 6543 <6543@obermui.de> | 2021-01-18 21:00:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-18 21:00:50 +0100 |
commit | 2686e6bbbe0e2cbb58292732b740a6944ce09c8a (patch) | |
tree | bd7aa1b2cad2184676b7d31ab018b41c6a971559 /models/issue_label.go | |
parent | 127907c5e66d671b139a8d2bd8912911c7e58347 (diff) | |
download | gitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.tar.gz gitea-2686e6bbbe0e2cbb58292732b740a6944ce09c8a.zip |
Check if label template exist first (#14384)
* add check
* refactor
* rollback repo on error after session closed
Diffstat (limited to 'models/issue_label.go')
-rw-r--r-- | models/issue_label.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index ea12b42ae6..54b286fe7e 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -47,7 +47,7 @@ type Label struct { func GetLabelTemplateFile(name string) ([][3]string, error) { data, err := GetRepoInitFile("label", name) if err != nil { - return nil, fmt.Errorf("GetRepoInitFile: %v", err) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)} } lines := strings.Split(string(data), "\n") @@ -62,7 +62,7 @@ func GetLabelTemplateFile(name string) ([][3]string, error) { fields := strings.SplitN(parts[0], " ", 2) if len(fields) != 2 { - return nil, fmt.Errorf("line is malformed: %s", line) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("line is malformed: %s", line)} } color := strings.Trim(fields[0], " ") @@ -70,7 +70,7 @@ func GetLabelTemplateFile(name string) ([][3]string, error) { color = "#" + color } if !LabelColorPattern.MatchString(color) { - return nil, fmt.Errorf("bad HTML color code in line: %s", line) + return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("bad HTML color code in line: %s", line)} } var description string @@ -167,7 +167,7 @@ func (label *Label) ForegroundColor() template.CSS { func loadLabels(labelTemplate string) ([]string, error) { list, err := GetLabelTemplateFile(labelTemplate) if err != nil { - return nil, ErrIssueLabelTemplateLoad{labelTemplate, err} + return nil, err } labels := make([]string, len(list)) @@ -186,7 +186,7 @@ func LoadLabelsFormatted(labelTemplate string) (string, error) { func initializeLabels(e Engine, id int64, labelTemplate string, isOrg bool) error { list, err := GetLabelTemplateFile(labelTemplate) if err != nil { - return ErrIssueLabelTemplateLoad{labelTemplate, err} + return err } labels := make([]*Label, len(list)) |