Add transaction for ReopenIssue

This commit is contained in:
Lunny Xiao 2024-11-10 13:42:16 -08:00
parent ed261f1403
commit fdff19948a
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 29 additions and 4 deletions

View File

@ -139,7 +139,20 @@ func ReopenIssue(ctx context.Context, issue *Issue, doer *user_model.User) (*Com
return nil, err 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. // ChangeIssueTitle changes the title of this issue, as the given user.

View File

@ -6,6 +6,7 @@ package issue
import ( import (
"context" "context"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
@ -14,20 +15,31 @@ import (
// CloseIssue close and issue. // CloseIssue close and issue.
func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string) error { 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 err != nil {
if issues_model.IsErrDependenciesLeft(err) { 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) log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err)
} }
} }
return 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 return err
} }
if err := committer.Commit(); err != nil {
return err
}
committer.Close()
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true) notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true)
return nil return nil