|
|
|
@ -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")) |
|
|
|
|
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) |
|
|
|
|
issue, labels, err := prepareForReplaceOrAdd(ctx, form) |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|