aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/org
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2023-03-02 01:44:23 +0200
committerGitHub <noreply@github.com>2023-03-02 01:44:23 +0200
commit58b414380371a4419f909491700673d43ae6b4ff (patch)
tree9d994ac5afecdf2109fe93d9ba97a12c201bd27e /routers/api/v1/org
parentde6c718b46ebd3b7f6362c766eed328044d95ec7 (diff)
downloadgitea-58b414380371a4419f909491700673d43ae6b4ff.tar.gz
gitea-58b414380371a4419f909491700673d43ae6b4ff.zip
Add loading yaml label template files (#22976)
Extract from #11669 and enhancement to #22585 to support exclusive scoped labels in label templates * Move label template functionality to label module * Fix handling of color codes * Add Advanced label template
Diffstat (limited to 'routers/api/v1/org')
-rw-r--r--routers/api/v1/org/label.go33
1 files changed, 15 insertions, 18 deletions
diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go
index 938fe79df6..183c1e6cc8 100644
--- a/routers/api/v1/org/label.go
+++ b/routers/api/v1/org/label.go
@@ -4,13 +4,13 @@
package org
import (
- "fmt"
"net/http"
"strconv"
"strings"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/label"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -84,13 +84,12 @@ func CreateLabel(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateLabelOption)
form.Color = strings.Trim(form.Color, " ")
- if len(form.Color) == 6 {
- form.Color = "#" + form.Color
- }
- if !issues_model.LabelColorPattern.MatchString(form.Color) {
- ctx.Error(http.StatusUnprocessableEntity, "ColorPattern", fmt.Errorf("bad color code: %s", form.Color))
+ color, err := label.NormalizeColor(form.Color)
+ if err != nil {
+ ctx.Error(http.StatusUnprocessableEntity, "Color", err)
return
}
+ form.Color = color
label := &issues_model.Label{
Name: form.Name,
@@ -183,7 +182,7 @@ func EditLabel(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption)
- label, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
+ l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
if err != nil {
if issues_model.IsErrOrgLabelNotExist(err) {
ctx.NotFound()
@@ -194,30 +193,28 @@ func EditLabel(ctx *context.APIContext) {
}
if form.Name != nil {
- label.Name = *form.Name
+ l.Name = *form.Name
}
if form.Exclusive != nil {
- label.Exclusive = *form.Exclusive
+ l.Exclusive = *form.Exclusive
}
if form.Color != nil {
- label.Color = strings.Trim(*form.Color, " ")
- if len(label.Color) == 6 {
- label.Color = "#" + label.Color
- }
- if !issues_model.LabelColorPattern.MatchString(label.Color) {
- ctx.Error(http.StatusUnprocessableEntity, "ColorPattern", fmt.Errorf("bad color code: %s", label.Color))
+ color, err := label.NormalizeColor(*form.Color)
+ if err != nil {
+ ctx.Error(http.StatusUnprocessableEntity, "Color", err)
return
}
+ l.Color = color
}
if form.Description != nil {
- label.Description = *form.Description
+ l.Description = *form.Description
}
- if err := issues_model.UpdateLabel(label); err != nil {
+ if err := issues_model.UpdateLabel(l); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
}
- ctx.JSON(http.StatusOK, convert.ToLabel(label, nil, ctx.Org.Organization.AsUser()))
+ ctx.JSON(http.StatusOK, convert.ToLabel(l, nil, ctx.Org.Organization.AsUser()))
}
// DeleteLabel delete a label for an organization