aboutsummaryrefslogtreecommitdiffstats
path: root/services/automerge
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-11-13 04:18:50 +0800
committerGitHub <noreply@github.com>2022-11-12 21:18:50 +0100
commit34283a74e85278fed2c9b70d6f8749dc6a4001ca (patch)
treef8fa43399cb723d55efc34dacf7947faf0ed5acf /services/automerge
parenta0a425a13ba587829a831aaecd8469d39d372111 (diff)
downloadgitea-34283a74e85278fed2c9b70d6f8749dc6a4001ca.tar.gz
gitea-34283a74e85278fed2c9b70d6f8749dc6a4001ca.zip
Allow detect whether it's in a database transaction for a context.Context (#21756)
Fix #19513 This PR introduce a new db method `InTransaction(context.Context)`, and also builtin check on `db.TxContext` and `db.WithTx`. There is also a new method `db.AutoTx` has been introduced but could be used by other PRs. `WithTx` will always open a new transaction, if a transaction exist in context, return an error. `AutoTx` will try to open a new transaction if no transaction exist in context. That means it will always enter a transaction if there is no error. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'services/automerge')
-rw-r--r--services/automerge/automerge.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index 3ee8af2344..5c38367e3b 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -63,7 +63,7 @@ func addToQueue(pr *issues_model.PullRequest, sha string) {
// ScheduleAutoMerge if schedule is false and no error, pull can be merged directly
func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest, style repo_model.MergeStyle, message string) (scheduled bool, err error) {
- err = db.WithTx(func(ctx context.Context) error {
+ err = db.WithTx(ctx, func(ctx context.Context) error {
lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull)
if err != nil {
return err
@@ -81,20 +81,20 @@ func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_
_, err = issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRScheduledToAutoMerge, pull, doer)
return err
- }, ctx)
+ })
return scheduled, err
}
// RemoveScheduledAutoMerge cancels a previously scheduled pull request
func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest) error {
- return db.WithTx(func(ctx context.Context) error {
+ return db.WithTx(ctx, func(ctx context.Context) error {
if err := pull_model.DeleteScheduledAutoMerge(ctx, pull.ID); err != nil {
return err
}
_, err := issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRUnScheduledToAutoMerge, pull, doer)
return err
- }, ctx)
+ })
}
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded