diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-25 02:15:09 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-25 14:15:09 +0800 |
commit | 2559a34b97c4f156a4fec82b03b88a6ba4caeb76 (patch) | |
tree | 915aeaa4ddb5f577ee3445d42f2b94cd578876c7 /models | |
parent | f64c232953d13043b262dc8da55acb3738e58d15 (diff) | |
download | gitea-2559a34b97c4f156a4fec82b03b88a6ba4caeb76.tar.gz gitea-2559a34b97c4f156a4fec82b03b88a6ba4caeb76.zip |
Load label ID in NewLabels (#2045)
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_label.go | 25 | ||||
-rw-r--r-- | models/issue_label_test.go | 2 |
2 files changed, 23 insertions, 4 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index 19bf01c6c7..5ecd355a6b 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -96,12 +96,31 @@ func (label *Label) ForegroundColor() template.CSS { return template.CSS("#000") } -// NewLabels creates new label(s) for a repository. -func NewLabels(labels ...*Label) error { - _, err := x.Insert(labels) +func newLabel(e Engine, label *Label) error { + _, err := e.Insert(label) return err } +// NewLabel creates a new label for a repository +func NewLabel(label *Label) error { + return newLabel(x, label) +} + +// NewLabels creates new labels for a repository. +func NewLabels(labels ...*Label) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + for _, label := range labels { + if err := newLabel(sess, label); err != nil { + return err + } + } + return sess.Commit() +} + // 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. diff --git a/models/issue_label_test.go b/models/issue_label_test.go index 2ef396668a..33630cd901 100644 --- a/models/issue_label_test.go +++ b/models/issue_label_test.go @@ -52,7 +52,7 @@ func TestNewLabels(t *testing.T) { } assert.NoError(t, NewLabels(labels...)) for _, label := range labels { - AssertExistsAndLoadBean(t, label) + AssertExistsAndLoadBean(t, label, Cond("id = ?", label.ID)) } CheckConsistencyFor(t, &Label{}, &Repository{}) } |