[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>
This commit is contained in:
Otto Richter (fnetX) 2022-03-01 01:20:15 +01:00 committed by GitHub
parent 6859b69198
commit 062fd4c217
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 299 additions and 4 deletions

View file

@ -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) {