Skip to content

Commit

Permalink
Make DeleteIssue use correct context (go-gitea#24885)
Browse files Browse the repository at this point in the history
Fix go-gitea#24884 , the `ctx.Repo.GitRepo` might be nil.

(cherry picked from commit d19d5bc)
  • Loading branch information
wxiaoguang authored and earl-warren committed May 30, 2023
1 parent a28fd05 commit 936eb64
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions services/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package issue

import (
"context"
"fmt"

activities_model "code.gitea.io/gitea/models/activities"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down

0 comments on commit 936eb64

Please sign in to comment.