aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/issue_lock.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issues/issue_lock.go')
-rw-r--r--models/issues/issue_lock.go33
1 files changed, 13 insertions, 20 deletions
diff --git a/models/issues/issue_lock.go b/models/issues/issue_lock.go
index fa0d128f74..2e5bf64cc6 100644
--- a/models/issues/issue_lock.go
+++ b/models/issues/issue_lock.go
@@ -47,26 +47,19 @@ func updateIssueLock(ctx context.Context, opts *IssueLockOptions, lock bool) err
commentType = CommentTypeUnlock
}
- ctx, committer, err := db.TxContext(ctx)
- if err != nil {
- return err
- }
- defer committer.Close()
-
- if err := UpdateIssueCols(ctx, opts.Issue, "is_locked"); err != nil {
- return err
- }
+ return db.WithTx(ctx, func(ctx context.Context) error {
+ if err := UpdateIssueCols(ctx, opts.Issue, "is_locked"); err != nil {
+ return err
+ }
- opt := &CreateCommentOptions{
- Doer: opts.Doer,
- Issue: opts.Issue,
- Repo: opts.Issue.Repo,
- Type: commentType,
- Content: opts.Reason,
- }
- if _, err := CreateComment(ctx, opt); err != nil {
+ opt := &CreateCommentOptions{
+ Doer: opts.Doer,
+ Issue: opts.Issue,
+ Repo: opts.Issue.Repo,
+ Type: commentType,
+ Content: opts.Reason,
+ }
+ _, err := CreateComment(ctx, opt)
return err
- }
-
- return committer.Commit()
+ })
}