From 398580975c2c07a14dcf9954fce71f8a4cf28a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Sun, 9 Apr 2023 11:46:25 +0200 Subject: [PATCH] [API] fix deleting an issue when the git repo does not exist Fixes: https://codeberg.org/forgejo/forgejo/issues/629 (cherry picked from commit 5f06dcae267230fc9b22ac171ba7253b47fe0bbf) (cherry picked from commit 1d8ae34e57e46b84a885b4f072d949344c5977c4) --- services/issue/issue.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/issue/issue.go b/services/issue/issue.go index b91ee4fc18..bc7b1ac5d9 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" @@ -132,11 +133,17 @@ 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 { + var ctx context.Context + if gitRepo == nil { + ctx = db.DefaultContext + } else { + ctx = gitRepo.Ctx + } // 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 } @@ -152,7 +159,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m } } - notification.NotifyDeleteIssue(gitRepo.Ctx, doer, issue) + notification.NotifyDeleteIssue(ctx, doer, issue) return nil }