diff options
author | 无闻 <u@gogs.io> | 2017-06-05 15:34:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-05 15:34:11 -0400 |
commit | 51d7f1264bc39a75b4fb016bee7d0f87f8485f3f (patch) | |
tree | 63ec5e3eff2ebcbfdc78a4d7649b41a230532e96 /models/issue_label.go | |
parent | 3359b942b379bdfb7ae33b8c106c8b3bc8afbf52 (diff) |
api: GitHub compliance (#4549)
* Add undocumented endpoint for /repositories/:id
* GitHub API Compliance
Diffstat (limited to 'models/issue_label.go')
-rw-r--r-- | models/issue_label.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index 8c56a7fd..cb9723a9 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -68,7 +68,7 @@ func (label *Label) APIFormat() *api.Label { return &api.Label{ ID: label.ID, Name: label.Name, - Color: label.Color, + Color: strings.TrimLeft(label.Color, "#"), } } @@ -103,7 +103,28 @@ func NewLabels(labels ...*Label) error { return err } -// getLabelOfRepoByID returns a label by ID in given repository. +// getLabelOfRepoByName 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 getLabelOfRepoByName(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. func getLabelOfRepoByID(e Engine, repoID, labelID int64) (*Label, error) { @@ -134,6 +155,11 @@ func GetLabelOfRepoByID(repoID, labelID int64) (*Label, error) { return getLabelOfRepoByID(x, repoID, labelID) } +// GetLabelOfRepoByName returns a label by name in given repository. +func GetLabelOfRepoByName(repoID int64, labelName string) (*Label, error) { + return getLabelOfRepoByName(x, repoID, labelName) +} + // GetLabelsInRepoByIDs returns a list of labels by IDs in given repository, // it silently ignores label IDs that are not belong to the repository. func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) { |