From d19d5bc5b89ef2e46fc3b8f6c55551ce935d05bc Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 24 May 2023 01:11:19 +0800 Subject: [PATCH] Make DeleteIssue use correct context (#24885) Fix #24884 , the `ctx.Repo.GitRepo` might be nil. --- routers/api/v1/repo/issue.go | 2 +- routers/web/repo/issue.go | 2 +- services/issue/issue.go | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 458838b93562..97421b35c0a6 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -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 } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 9c9bf9ad1e19..1d480096a9ba 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -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 } diff --git a/services/issue/issue.go b/services/issue/issue.go index b91ee4fc18b0..ac5535577c29 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -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 }