From e6cfccdd40397b95dcf3de0ea9b484feea954fc2 Mon Sep 17 00:00:00 2001 From: "Kim \"BKC\" Carlbäcker" Date: Fri, 7 Oct 2016 19:17:27 +0200 Subject: GitHub API Compliance (& linting) --- models/issue_label.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'models/issue_label.go') 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. @@ -128,6 +149,11 @@ func GetLabelByID(id int64) (*Label, error) { return getLabelInRepoByID(x, 0, id) } +// 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) -- cgit v1.2.3