mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Batch updates for issues (#926)
This commit is contained in:
committed by
Kim "BKC" Carlbäcker
parent
021904e4e6
commit
09fe4a2ae9
@@ -9,6 +9,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -129,18 +130,20 @@ func DeleteLabel(ctx *context.Context) {
|
||||
|
||||
// UpdateIssueLabel change issue's labels
|
||||
func UpdateIssueLabel(ctx *context.Context) {
|
||||
issue := getActionIssue(ctx)
|
||||
issues := getActionIssues(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Query("action") == "clear" {
|
||||
if err := issue.ClearLabels(ctx.User); err != nil {
|
||||
ctx.Handle(500, "ClearLabels", err)
|
||||
return
|
||||
switch action := ctx.Query("action"); action {
|
||||
case "clear":
|
||||
for _, issue := range issues {
|
||||
if err := issue.ClearLabels(ctx.User); err != nil {
|
||||
ctx.Handle(500, "ClearLabels", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isAttach := ctx.Query("action") == "attach"
|
||||
case "attach", "detach", "toggle":
|
||||
label, err := models.GetLabelByID(ctx.QueryInt64("id"))
|
||||
if err != nil {
|
||||
if models.IsErrLabelNotExist(err) {
|
||||
@@ -151,17 +154,40 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if isAttach && !issue.HasLabel(label.ID) {
|
||||
if err = issue.AddLabel(ctx.User, label); err != nil {
|
||||
ctx.Handle(500, "AddLabel", err)
|
||||
return
|
||||
if action == "toggle" {
|
||||
anyHaveLabel := false
|
||||
for _, issue := range issues {
|
||||
if issue.HasLabel(label.ID) {
|
||||
anyHaveLabel = true
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if !isAttach && issue.HasLabel(label.ID) {
|
||||
if err = issue.RemoveLabel(ctx.User, label); err != nil {
|
||||
ctx.Handle(500, "RemoveLabel", err)
|
||||
return
|
||||
if anyHaveLabel {
|
||||
action = "detach"
|
||||
} else {
|
||||
action = "attach"
|
||||
}
|
||||
}
|
||||
|
||||
if action == "attach" {
|
||||
for _, issue := range issues {
|
||||
if err = issue.AddLabel(ctx.User, label); err != nil {
|
||||
ctx.Handle(500, "AddLabel", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, issue := range issues {
|
||||
if err = issue.RemoveLabel(ctx.User, label); err != nil {
|
||||
ctx.Handle(500, "RemoveLabel", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Warn("Unrecognized action: %s", action)
|
||||
ctx.Error(500)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
|
Reference in New Issue
Block a user