diff options
author | Otto Richter (fnetX) <git@fralix.ovh> | 2022-03-01 01:20:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-01 01:20:15 +0100 |
commit | 062fd4c217cc7302f56acf043d6214a9db46ee2f (patch) | |
tree | 4aaa51baaee1d7ddfab00a88a2d22f5911af1312 /routers | |
parent | 6859b6919800cbf2958dbfbe76fca42f4dcbb194 (diff) | |
download | gitea-062fd4c217cc7302f56acf043d6214a9db46ee2f.tar.gz gitea-062fd4c217cc7302f56acf043d6214a9db46ee2f.zip |
[API] Allow removing issues (#18879)
Add new feature to delete issues and pulls via API
Co-authored-by: fnetx <git@fralix.ovh>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/api.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 46 |
2 files changed, 48 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 6d8ab8ce98..d4891daef0 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -835,7 +835,8 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { }) m.Group("/{index}", func() { m.Combo("").Get(repo.GetIssue). - Patch(reqToken(), bind(api.EditIssueOption{}), repo.EditIssue) + Patch(reqToken(), bind(api.EditIssueOption{}), repo.EditIssue). + Delete(reqToken(), reqAdmin(), repo.DeleteIssue) m.Group("/comments", func() { m.Combo("").Get(repo.ListIssueComments). Post(reqToken(), mustNotBeArchived, bind(api.CreateIssueCommentOption{}), repo.CreateIssueComment) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index e2afa72498..9e550c4c47 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -834,6 +834,52 @@ func EditIssue(ctx *context.APIContext) { ctx.JSON(http.StatusCreated, convert.ToAPIIssue(issue)) } +func DeleteIssue(ctx *context.APIContext) { + // swagger:operation DELETE /repos/{owner}/{repo}/issues/{index} issue issueDelete + // --- + // summary: Delete an issue + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: index + // in: path + // description: index of issue to delete + // type: integer + // format: int64 + // required: true + // responses: + // "204": + // "$ref": "#/responses/empty" + // "403": + // "$ref": "#/responses/forbidden" + // "404": + // "$ref": "#/responses/notFound" + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrIssueNotExist(err) { + ctx.NotFound(err) + } else { + ctx.Error(http.StatusInternalServerError, "GetIssueByID", err) + } + return + } + + if err = issue_service.DeleteIssue(ctx.User, ctx.Repo.GitRepo, issue); err != nil { + ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err) + return + } + + ctx.Status(http.StatusNoContent) +} + // UpdateIssueDeadline updates an issue deadline func UpdateIssueDeadline(ctx *context.APIContext) { // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/deadline issue issueEditIssueDeadline |