aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/issue_label.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-02-23 23:53:08 +0100
committerGitHub <noreply@github.com>2020-02-23 22:53:08 +0000
commit39b507e3c4badca0fe253a127bcbde38483cf25b (patch)
tree2c7a591dac2158a3979698903d9c3df980a2c845 /routers/api/v1/repo/issue_label.go
parent062f35109df236a06a00d403d006b90760f9cfac (diff)
downloadgitea-39b507e3c4badca0fe253a127bcbde38483cf25b.tar.gz
gitea-39b507e3c4badca0fe253a127bcbde38483cf25b.zip
Trigger webhooks on issue label-change via API too (#10421)
* trigger webhooks with api too * fix comment * notify report old too * CI restart * restart CI again * remove duplicated code
Diffstat (limited to 'routers/api/v1/repo/issue_label.go')
-rw-r--r--routers/api/v1/repo/issue_label.go65
1 files changed, 29 insertions, 36 deletions
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go
index 492da244f2..a9fb42a186 100644
--- a/routers/api/v1/repo/issue_label.go
+++ b/routers/api/v1/repo/issue_label.go
@@ -102,24 +102,8 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
// "403":
// "$ref": "#/responses/forbidden"
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, labels, err := prepareForReplaceOrAdd(ctx, form)
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.NotFound()
- } else {
- ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
- }
- return
- }
-
- if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(http.StatusForbidden)
- return
- }
-
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
return
}
@@ -204,7 +188,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return
}
- if err := models.DeleteIssueLabel(issue, label, ctx.User); err != nil {
+ if err := issue_service.RemoveLabel(issue, ctx.User, label); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
return
}
@@ -248,28 +232,12 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
// "403":
// "$ref": "#/responses/forbidden"
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, labels, err := prepareForReplaceOrAdd(ctx, form)
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.NotFound()
- } else {
- ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
- }
- return
- }
-
- if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(http.StatusForbidden)
return
}
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
- return
- }
-
- if err := issue.ReplaceLabels(labels, ctx.User); err != nil {
+ if err := issue_service.ReplaceLabels(issue, ctx.User, labels); err != nil {
ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
return
}
@@ -339,3 +307,28 @@ func ClearIssueLabels(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
+
+func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (issue *models.Issue, labels []*models.Label, err error) {
+ issue, err = models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ if err != nil {
+ if models.IsErrIssueNotExist(err) {
+ ctx.NotFound()
+ } else {
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
+ }
+ return
+ }
+
+ labels, err = models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
+ return
+ }
+
+ if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
+ ctx.Status(http.StatusForbidden)
+ return
+ }
+
+ return
+}