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

Show label list on label set #9251

Merged
merged 7 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ func (label *Label) ForegroundColor() template.CSS {
return template.CSS("#000")
}

func loadLabels(labelTemplate string) ([]string, error) {
list, err := GetLabelTemplateFile(labelTemplate)
if err != nil {
return nil, ErrIssueLabelTemplateLoad{labelTemplate, err}
}

labels := make([]string, len(list))
for i := 0; i < len(list); i++ {
labels[i] = list[i][0]
}
return labels, nil
}

// LoadLabelsFormatted loads the labels' list of a template file as a string separated by comma
func LoadLabelsFormatted(labelTemplate string) (string, error) {
labels, err := loadLabels(labelTemplate)
return strings.Join(labels, ", "), err
}

func initalizeLabels(e Engine, repoID int64, labelTemplate string) error {
list, err := GetLabelTemplateFile(labelTemplate)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ var (
// Readmes contains the readme files
Readmes []string

// LabelTemplates contains the label template files
LabelTemplates []string
// LabelTemplates contains the label template files and the list of labels for each file
LabelTemplates map[string]string

// ItemsPerPage maximum items per page in forks, watchers and stars of a repo
ItemsPerPage = 40
Expand Down Expand Up @@ -100,11 +100,21 @@ func loadRepoConfig() {
Gitignores = typeFiles[0]
Licenses = typeFiles[1]
Readmes = typeFiles[2]
LabelTemplates = typeFiles[3]
LabelTemplatesFiles := typeFiles[3]
sort.Strings(Gitignores)
sort.Strings(Licenses)
sort.Strings(Readmes)
sort.Strings(LabelTemplates)
sort.Strings(LabelTemplatesFiles)

// Load label templates
LabelTemplates = make(map[string]string)
for _, templateFile := range LabelTemplatesFiles {
labels, err := LoadLabelsFormatted(templateFile)
if err != nil {
log.Error("Failed to load labels: %v", err)
}
LabelTemplates[templateFile] = labels
}

// Filter out invalid names and promote preferred licenses.
sortedLicenses := make([]string, 0, len(Licenses))
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
<div class="default text">{{.i18n.Tr "repo.issue_labels_helper"}}</div>
<div class="menu">
<div class="item" data-value="">{{.i18n.Tr "repo.issue_labels_helper"}}</div>
{{range .LabelTemplates}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{range $template, $labels := .LabelTemplates}}
<div class="item" data-value="{{$template}}">{{$template}}<br/><i>({{$labels}})</i></div>
{{end}}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/labels.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
<input type="hidden" name="template_name" value="Default">
<div class="default text">{{.i18n.Tr "repo.issues.label_templates.helper"}}</div>
<div class="menu">
{{range .LabelTemplates}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{range $template, $labels := .LabelTemplates}}
<div class="item" data-value="{{$template}}">{{$template}}<br/><i>({{$labels}})</i></div>
{{end}}
</div>
</div>
Expand Down