Make DeleteIssue use correct context (#24885)

Fix #24884 , the `ctx.Repo.GitRepo` might be nil.
This commit is contained in:
wxiaoguang 2023-05-24 01:11:19 +08:00 committed by GitHub
parent e7757aa4be
commit d19d5bc5b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -880,7 +880,7 @@ func DeleteIssue(ctx *context.APIContext) {
return
}
if err = issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
return
}

View File

@ -978,7 +978,7 @@ func DeleteIssue(ctx *context.Context) {
return
}
if err := issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
if err := issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
ctx.ServerError("DeleteIssueByID", err)
return
}

View File

@ -4,6 +4,7 @@
package issue
import (
"context"
"fmt"
activities_model "code.gitea.io/gitea/models/activities"
@ -131,12 +132,12 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
}
// DeleteIssue deletes an issue
func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
// load issue before deleting it
if err := issue.LoadAttributes(gitRepo.Ctx); err != nil {
if err := issue.LoadAttributes(ctx); err != nil {
return err
}
if err := issue.LoadPullRequest(gitRepo.Ctx); err != nil {
if err := issue.LoadPullRequest(ctx); err != nil {
return err
}
@ -146,13 +147,13 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m
}
// delete pull request related git data
if issue.IsPull {
if issue.IsPull && gitRepo != nil {
if err := gitRepo.RemoveReference(fmt.Sprintf("%s%d/head", git.PullPrefix, issue.PullRequest.Index)); err != nil {
return err
}
}
notification.NotifyDeleteIssue(gitRepo.Ctx, doer, issue)
notification.NotifyDeleteIssue(ctx, doer, issue)
return nil
}