Skip to content

Commit 936eb64

Browse files
wxiaoguangearl-warren
authored andcommitted
Make DeleteIssue use correct context (go-gitea#24885)
Fix go-gitea#24884 , the `ctx.Repo.GitRepo` might be nil. (cherry picked from commit d19d5bc)
1 parent a28fd05 commit 936eb64

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

routers/api/v1/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ func DeleteIssue(ctx *context.APIContext) {
880880
return
881881
}
882882

883-
if err = issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
883+
if err = issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
884884
ctx.Error(http.StatusInternalServerError, "DeleteIssueByID", err)
885885
return
886886
}

routers/web/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ func DeleteIssue(ctx *context.Context) {
978978
return
979979
}
980980

981-
if err := issue_service.DeleteIssue(ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
981+
if err := issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
982982
ctx.ServerError("DeleteIssueByID", err)
983983
return
984984
}

services/issue/issue.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package issue
55

66
import (
7+
"context"
78
"fmt"
89

910
activities_model "code.gitea.io/gitea/models/activities"
@@ -131,12 +132,12 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
131132
}
132133

133134
// DeleteIssue deletes an issue
134-
func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
135+
func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
135136
// load issue before deleting it
136-
if err := issue.LoadAttributes(gitRepo.Ctx); err != nil {
137+
if err := issue.LoadAttributes(ctx); err != nil {
137138
return err
138139
}
139-
if err := issue.LoadPullRequest(gitRepo.Ctx); err != nil {
140+
if err := issue.LoadPullRequest(ctx); err != nil {
140141
return err
141142
}
142143

@@ -146,13 +147,13 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m
146147
}
147148

148149
// delete pull request related git data
149-
if issue.IsPull {
150+
if issue.IsPull && gitRepo != nil {
150151
if err := gitRepo.RemoveReference(fmt.Sprintf("%s%d/head", git.PullPrefix, issue.PullRequest.Index)); err != nil {
151152
return err
152153
}
153154
}
154155

155-
notification.NotifyDeleteIssue(gitRepo.Ctx, doer, issue)
156+
notification.NotifyDeleteIssue(ctx, doer, issue)
156157

157158
return nil
158159
}

0 commit comments

Comments
 (0)