summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-03-13 04:03:55 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2018-03-13 10:03:55 +0800
commitc0d41b1b77169553006bd9211d025de4da8bafd8 (patch)
tree95c704bdd07576766e2c29533578da2f3002ab64 /models
parentad33730dcaffed632200316a5ce5675b30ed1e99 (diff)
downloadgitea-c0d41b1b77169553006bd9211d025de4da8bafd8.tar.gz
gitea-c0d41b1b77169553006bd9211d025de4da8bafd8.zip
Add label descriptions (#3662)
* Add label descriptions * Add default descriptions to label template
Diffstat (limited to 'models')
-rw-r--r--models/issue_label.go19
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v58.go22
3 files changed, 38 insertions, 5 deletions
diff --git a/models/issue_label.go b/models/issue_label.go
index 6e48b4633b..ab6c4731ee 100644
--- a/models/issue_label.go
+++ b/models/issue_label.go
@@ -19,22 +19,24 @@ import (
var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})")
// GetLabelTemplateFile loads the label template file by given name,
-// then parses and returns a list of name-color pairs.
-func GetLabelTemplateFile(name string) ([][2]string, error) {
+// then parses and returns a list of name-color pairs and optionally description.
+func GetLabelTemplateFile(name string) ([][3]string, error) {
data, err := getRepoInitFile("label", name)
if err != nil {
return nil, fmt.Errorf("getRepoInitFile: %v", err)
}
lines := strings.Split(string(data), "\n")
- list := make([][2]string, 0, len(lines))
+ list := make([][3]string, 0, len(lines))
for i := 0; i < len(lines); i++ {
line := strings.TrimSpace(lines[i])
if len(line) == 0 {
continue
}
- fields := strings.SplitN(line, " ", 2)
+ parts := strings.SplitN(line, ";", 2)
+
+ fields := strings.SplitN(parts[0], " ", 2)
if len(fields) != 2 {
return nil, fmt.Errorf("line is malformed: %s", line)
}
@@ -43,8 +45,14 @@ func GetLabelTemplateFile(name string) ([][2]string, error) {
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
}
+ var description string
+
+ if len(parts) > 1 {
+ description = strings.TrimSpace(parts[1])
+ }
+
fields[1] = strings.TrimSpace(fields[1])
- list = append(list, [2]string{fields[1], fields[0]})
+ list = append(list, [3]string{fields[1], fields[0], description})
}
return list, nil
@@ -55,6 +63,7 @@ type Label struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
Name string
+ Description string
Color string `xorm:"VARCHAR(7)"`
NumIssues int
NumClosedIssues int
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index cc40bd8272..cc5d0bae81 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -168,6 +168,8 @@ var migrations = []Migration{
NewMigration("remove is_owner, num_teams columns from org_user", removeIsOwnerColumnFromOrgUser),
// v57 -> v58
NewMigration("add closed_unix column for issues", addIssueClosedTime),
+ // v58 -> v59
+ NewMigration("add label descriptions", addLabelsDescriptions),
}
// Migrate database to current version
diff --git a/models/migrations/v58.go b/models/migrations/v58.go
new file mode 100644
index 0000000000..6ec24b08c8
--- /dev/null
+++ b/models/migrations/v58.go
@@ -0,0 +1,22 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+
+ "github.com/go-xorm/xorm"
+)
+
+func addLabelsDescriptions(x *xorm.Engine) error {
+ type Label struct {
+ Description string
+ }
+
+ if err := x.Sync2(new(Label)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ return nil
+}