Load label ID in NewLabels (#2045)
This commit is contained in:
parent
f64c232953
commit
2559a34b97
|
@ -96,12 +96,31 @@ func (label *Label) ForegroundColor() template.CSS {
|
||||||
return template.CSS("#000")
|
return template.CSS("#000")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLabels creates new label(s) for a repository.
|
func newLabel(e Engine, label *Label) error {
|
||||||
func NewLabels(labels ...*Label) error {
|
_, err := e.Insert(label)
|
||||||
_, err := x.Insert(labels)
|
|
||||||
return err
|
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.
|
// getLabelInRepoByName returns a label by Name in given repository.
|
||||||
// If pass repoID as 0, then ORM will ignore limitation of repository
|
// If pass repoID as 0, then ORM will ignore limitation of repository
|
||||||
// and can return arbitrary label with any valid ID.
|
// and can return arbitrary label with any valid ID.
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestNewLabels(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.NoError(t, NewLabels(labels...))
|
assert.NoError(t, NewLabels(labels...))
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
AssertExistsAndLoadBean(t, label)
|
AssertExistsAndLoadBean(t, label, Cond("id = ?", label.ID))
|
||||||
}
|
}
|
||||||
CheckConsistencyFor(t, &Label{}, &Repository{})
|
CheckConsistencyFor(t, &Label{}, &Repository{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||||
Color: form.Color,
|
Color: form.Color,
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
}
|
}
|
||||||
if err := models.NewLabels(label); err != nil {
|
if err := models.NewLabel(label); err != nil {
|
||||||
ctx.Error(500, "NewLabel", err)
|
ctx.Error(500, "NewLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) {
|
||||||
Name: form.Title,
|
Name: form.Title,
|
||||||
Color: form.Color,
|
Color: form.Color,
|
||||||
}
|
}
|
||||||
if err := models.NewLabels(l); err != nil {
|
if err := models.NewLabel(l); err != nil {
|
||||||
ctx.Handle(500, "NewLabel", err)
|
ctx.Handle(500, "NewLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue