aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_label.go
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-10-07 19:17:27 +0200
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-12-02 09:18:15 +0100
commite6cfccdd40397b95dcf3de0ea9b484feea954fc2 (patch)
tree8c758b622b022ffae542bf4caf3eb9c8623bd317 /models/issue_label.go
parent71bb6df75ae541687c64f5e6e4da16ea9e95acfe (diff)
downloadgitea-e6cfccdd40397b95dcf3de0ea9b484feea954fc2.tar.gz
gitea-e6cfccdd40397b95dcf3de0ea9b484feea954fc2.zip
GitHub API Compliance (& linting)
Diffstat (limited to 'models/issue_label.go')
-rw-r--r--models/issue_label.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/models/issue_label.go b/models/issue_label.go
index befe3f192a..ffdaa072c8 100644
--- a/models/issue_label.go
+++ b/models/issue_label.go
@@ -67,7 +67,7 @@ func (label *Label) APIFormat() *api.Label {
return &api.Label{
ID: label.ID,
Name: label.Name,
- Color: label.Color,
+ Color: strings.TrimLeft(label.Color, "#"),
}
}
@@ -102,6 +102,27 @@ func NewLabels(labels ...*Label) error {
return err
}
+// getLabelInRepoByName returns a label by Name in given repository.
+// If pass repoID as 0, then ORM will ignore limitation of repository
+// and can return arbitrary label with any valid ID.
+func getLabelInRepoByName(e Engine, repoID int64, labelName string) (*Label, error) {
+ if len(labelName) <= 0 {
+ return nil, ErrLabelNotExist{0, repoID}
+ }
+
+ l := &Label{
+ Name: labelName,
+ RepoID: repoID,
+ }
+ has, err := x.Get(l)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrLabelNotExist{0, l.RepoID}
+ }
+ return l, nil
+}
+
// getLabelInRepoByID returns a label by ID in given repository.
// If pass repoID as 0, then ORM will ignore limitation of repository
// and can return arbitrary label with any valid ID.
@@ -129,6 +150,11 @@ func GetLabelByID(id int64) (*Label, error) {
}
// GetLabelInRepoByID returns a label by ID in given repository.
+func GetLabelInRepoByName(repoID int64, labelName string) (*Label, error) {
+ return getLabelInRepoByName(x, repoID, labelName)
+}
+
+// GetLabelInRepoByID returns a label by ID in given repository.
func GetLabelInRepoByID(repoID, labelID int64) (*Label, error) {
return getLabelInRepoByID(x, repoID, labelID)
}