aboutsummaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
authorOtto Richter (fnetX) <git@fralix.ovh>2022-03-01 01:20:15 +0100
committerGitHub <noreply@github.com>2022-03-01 01:20:15 +0100
commit062fd4c217cc7302f56acf043d6214a9db46ee2f (patch)
tree4aaa51baaee1d7ddfab00a88a2d22f5911af1312 /services/issue
parent6859b6919800cbf2958dbfbe76fca42f4dcbb194 (diff)
downloadgitea-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 'services/issue')
-rw-r--r--services/issue/issue.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go
index 8b6262c571..6e5e4bfd37 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -5,6 +5,8 @@
package issue
import (
+ "fmt"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
@@ -125,6 +127,33 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
return
}
+// DeleteIssue deletes an issue
+func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue) error {
+ // load issue before deleting it
+ if err := issue.LoadAttributes(); err != nil {
+ return err
+ }
+ if err := issue.LoadPullRequest(); err != nil {
+ return err
+ }
+
+ // delete entries in database
+ if err := models.DeleteIssue(issue); err != nil {
+ return err
+ }
+
+ // delete pull request related git data
+ if issue.IsPull {
+ if err := gitRepo.RemoveReference(fmt.Sprintf("%s%d", git.PullPrefix, issue.PullRequest.Index)); err != nil {
+ return err
+ }
+ }
+
+ notification.NotifyDeleteIssue(doer, issue)
+
+ return nil
+}
+
// AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue.
// Also checks for access of assigned user
func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assigneeID int64) (err error) {