From fdff19948a14a0a4a403f33420173704045ebd68 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 10 Nov 2024 13:42:16 -0800 Subject: [PATCH] Add transaction for ReopenIssue --- models/issues/issue_update.go | 15 ++++++++++++++- services/issue/status.go | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go index 21458e458ca..849bc8125e5 100644 --- a/models/issues/issue_update.go +++ b/models/issues/issue_update.go @@ -139,7 +139,20 @@ func ReopenIssue(ctx context.Context, issue *Issue, doer *user_model.User) (*Com return nil, err } - return changeIssueStatus(ctx, issue, doer, false, false) + ctx, committer, err := db.TxContext(ctx) + if err != nil { + return nil, err + } + defer committer.Close() + + comment, err := changeIssueStatus(ctx, issue, doer, false, false) + if err != nil { + return nil, err + } + if err := committer.Commit(); err != nil { + return nil, err + } + return comment, nil } // ChangeIssueTitle changes the title of this issue, as the given user. diff --git a/services/issue/status.go b/services/issue/status.go index a7f3ce8f7b5..ecbf87d533f 100644 --- a/services/issue/status.go +++ b/services/issue/status.go @@ -6,6 +6,7 @@ package issue import ( "context" + "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" @@ -14,20 +15,31 @@ import ( // CloseIssue close and issue. func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string) error { - comment, err := issues_model.CloseIssue(ctx, issue, doer) + dbCtx, committer, err := db.TxContext(ctx) + if err != nil { + return err + } + defer committer.Close() + + comment, err := issues_model.CloseIssue(dbCtx, issue, doer) if err != nil { if issues_model.IsErrDependenciesLeft(err) { - if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil { + if err := issues_model.FinishIssueStopwatchIfPossible(dbCtx, doer, issue); err != nil { log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err) } } return err } - if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil { + if err := issues_model.FinishIssueStopwatchIfPossible(dbCtx, doer, issue); err != nil { return err } + if err := committer.Commit(); err != nil { + return err + } + committer.Close() + notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true) return nil