Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaml/yml label file if/else guards #23717

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions modules/label/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package label
import (
"errors"
"fmt"
"path/filepath"
"strings"

"code.gitea.io/gitea/modules/options"
Expand Down Expand Up @@ -36,21 +37,20 @@ func (err ErrTemplateLoad) Error() string {
// GetTemplateFile loads the label template file by given name,
// then parses and returns a list of name-color pairs and optionally description.
func GetTemplateFile(name string) ([]*Label, error) {
data, err := options.Labels(name + ".yaml")
if err == nil && len(data) > 0 {
return parseYamlFormat(name+".yaml", data)
}

data, err = options.Labels(name + ".yml")
if err == nil && len(data) > 0 {
return parseYamlFormat(name+".yml", data)
if ext := filepath.Ext(name); ext == ".yaml" || ext == ".yml" {
data, err := options.Labels(name)
if err == nil && len(data) > 0 {
return parseYamlFormat(name, data)
} else {
return nil, ErrTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %w", err)}
}
}

// Fall back to legacy format
data, err = options.Labels(name)
if err != nil {
return nil, ErrTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %w", err)}
}

return parseLegacyFormat(name, data)
}

Expand Down