Skip to content

Commit c0d41b1

Browse files
lafrikslunny
authored andcommitted
Add label descriptions (#3662)
* Add label descriptions * Add default descriptions to label template
1 parent ad33730 commit c0d41b1

File tree

14 files changed

+109
-34
lines changed

14 files changed

+109
-34
lines changed

models/issue_label.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ import (
1919
var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})")
2020

2121
// 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) {
22+
// then parses and returns a list of name-color pairs and optionally description.
23+
func GetLabelTemplateFile(name string) ([][3]string, error) {
2424
data, err := getRepoInitFile("label", name)
2525
if err != nil {
2626
return nil, fmt.Errorf("getRepoInitFile: %v", err)
2727
}
2828

2929
lines := strings.Split(string(data), "\n")
30-
list := make([][2]string, 0, len(lines))
30+
list := make([][3]string, 0, len(lines))
3131
for i := 0; i < len(lines); i++ {
3232
line := strings.TrimSpace(lines[i])
3333
if len(line) == 0 {
3434
continue
3535
}
3636

37-
fields := strings.SplitN(line, " ", 2)
37+
parts := strings.SplitN(line, ";", 2)
38+
39+
fields := strings.SplitN(parts[0], " ", 2)
3840
if len(fields) != 2 {
3941
return nil, fmt.Errorf("line is malformed: %s", line)
4042
}
@@ -43,8 +45,14 @@ func GetLabelTemplateFile(name string) ([][2]string, error) {
4345
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
4446
}
4547

48+
var description string
49+
50+
if len(parts) > 1 {
51+
description = strings.TrimSpace(parts[1])
52+
}
53+
4654
fields[1] = strings.TrimSpace(fields[1])
47-
list = append(list, [2]string{fields[1], fields[0]})
55+
list = append(list, [3]string{fields[1], fields[0], description})
4856
}
4957

5058
return list, nil
@@ -55,6 +63,7 @@ type Label struct {
5563
ID int64 `xorm:"pk autoincr"`
5664
RepoID int64 `xorm:"INDEX"`
5765
Name string
66+
Description string
5867
Color string `xorm:"VARCHAR(7)"`
5968
NumIssues int
6069
NumClosedIssues int

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ var migrations = []Migration{
168168
NewMigration("remove is_owner, num_teams columns from org_user", removeIsOwnerColumnFromOrgUser),
169169
// v57 -> v58
170170
NewMigration("add closed_unix column for issues", addIssueClosedTime),
171+
// v58 -> v59
172+
NewMigration("add label descriptions", addLabelsDescriptions),
171173
}
172174

173175
// Migrate database to current version

models/migrations/v58.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/go-xorm/xorm"
11+
)
12+
13+
func addLabelsDescriptions(x *xorm.Engine) error {
14+
type Label struct {
15+
Description string
16+
}
17+
18+
if err := x.Sync2(new(Label)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}

modules/auth/repo_form.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors
310310

311311
// CreateLabelForm form for creating label
312312
type CreateLabelForm struct {
313-
ID int64
314-
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_name"`
315-
Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
313+
ID int64
314+
Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
315+
Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
316+
Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
316317
}
317318

318319
// Validate validates the fields

options/label/Default

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#ee0701 bug
2-
#cccccc duplicate
3-
#84b6eb enhancement
4-
#128a0c help wanted
5-
#e6e6e6 invalid
6-
#cc317c question
7-
#ffffff wontfix
1+
#ee0701 bug ; Something is not working
2+
#cccccc duplicate ; This issue or pull request already exists
3+
#84b6eb enhancement ; New feature
4+
#128a0c help wanted ; Need some help
5+
#e6e6e6 invalid ; Something is wrong
6+
#cc317c question ; More information is needed
7+
#ffffff wontfix ; This won't be fixed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ issues.no_ref = No Branch/Tag Specified
627627
issues.create = Create Issue
628628
issues.new_label = New Label
629629
issues.new_label_placeholder = Label name…
630+
issues.new_label_desc_placeholder = Description…
630631
issues.create_label = Create Label
631632
issues.label_templates.title = Load a predefined set of labels
632633
issues.label_templates.info = There are not any labels yet. You can click on the "New Label" button above to create one or use a predefined set below.
@@ -697,6 +698,7 @@ issues.edit = Edit
697698
issues.cancel = Cancel
698699
issues.save = Save
699700
issues.label_title = Label name
701+
issues.label_description = Label description
700702
issues.label_color = Label color
701703
issues.label_count = %d labels
702704
issues.label_open_issues = %d open issues

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ function initRepository() {
491491
$('.edit-label-button').click(function () {
492492
$('#label-modal-id').val($(this).data('id'));
493493
$('.edit-label .new-label-input').val($(this).data('title'));
494+
$('.edit-label .new-label-desc-input').val($(this).data('description'));
494495
$('.edit-label .color-picker').val($(this).data('color'));
495496
$('.minicolors-swatch-color').css("background-color", $(this).data('color'));
496497
$('.edit-label.modal').modal({

public/less/_repository.less

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@
134134
}
135135
}
136136

137+
.select-label {
138+
.item {
139+
max-width: 250px;
140+
overflow: hidden;
141+
text-overflow: ellipsis;
142+
}
143+
.desc {
144+
padding-left: 16px;
145+
}
146+
}
147+
137148
.ui.tabs {
138149
&.container {
139150
margin-top: 14px;

routers/repo/issue_label.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
4242
labels := make([]*models.Label, len(list))
4343
for i := 0; i < len(list); i++ {
4444
labels[i] = &models.Label{
45-
RepoID: ctx.Repo.Repository.ID,
46-
Name: list[i][0],
47-
Color: list[i][1],
45+
RepoID: ctx.Repo.Repository.ID,
46+
Name: list[i][0],
47+
Description: list[i][2],
48+
Color: list[i][1],
4849
}
4950
}
5051
if err := models.NewLabels(labels...); err != nil {
@@ -81,9 +82,10 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
8182
}
8283

8384
l := &models.Label{
84-
RepoID: ctx.Repo.Repository.ID,
85-
Name: form.Title,
86-
Color: form.Color,
85+
RepoID: ctx.Repo.Repository.ID,
86+
Name: form.Title,
87+
Description: form.Description,
88+
Color: form.Color,
8789
}
8890
if err := models.NewLabel(l); err != nil {
8991
ctx.ServerError("NewLabel", err)
@@ -106,6 +108,7 @@ func UpdateLabel(ctx *context.Context, form auth.CreateLabelForm) {
106108
}
107109

108110
l.Name = form.Title
111+
l.Description = form.Description
109112
l.Color = form.Color
110113
if err := models.UpdateLabel(l); err != nil {
111114
ctx.ServerError("UpdateLabel", err)

0 commit comments

Comments
 (0)