aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-05-08 15:46:34 +0200
committerGitHub <noreply@github.com>2022-05-08 15:46:34 +0200
commit6a969681cd862bf153fa7921485278be1e8a092a (patch)
treef9a23ee85652c0ee179f215b23d928058176ae6c /services
parent4344a6410788f30848e5153f6356dcdd0774bebc (diff)
downloadgitea-6a969681cd862bf153fa7921485278be1e8a092a.tar.gz
gitea-6a969681cd862bf153fa7921485278be1e8a092a.zip
Delete related PullAutoMerge and ReviewState on User/Repo Deletion (#19649)
* delete pullautomerges on repo/user deletion * delete reviewstates on repo/user deletion * optimize automerhe code * add index to reviewstate
Diffstat (limited to 'services')
-rw-r--r--services/automerge/automerge.go40
-rw-r--r--services/pull/merge.go2
2 files changed, 32 insertions, 10 deletions
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index e098f2cec0..85af2659c6 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
pull_model "code.gitea.io/gitea/models/pull"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -61,17 +62,38 @@ func addToQueue(pr *models.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 *models.PullRequest, style repo_model.MergeStyle, message string) (scheduled bool, err error) {
- lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull)
- if err != nil {
- return false, err
- }
+ err = db.WithTx(func(ctx context.Context) error {
+ lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull)
+ if err != nil {
+ return err
+ }
- // we don't need to schedule
- if lastCommitStatus.IsSuccess() {
- return false, nil
- }
+ // we don't need to schedule
+ if lastCommitStatus.IsSuccess() {
+ return nil
+ }
+
+ if err := pull_model.ScheduleAutoMerge(ctx, doer, pull.ID, style, message); err != nil {
+ return err
+ }
+ scheduled = true
+
+ _, err = models.CreateAutoMergeComment(ctx, models.CommentTypePRScheduledToAutoMerge, pull, doer)
+ return err
+ }, ctx)
+ return
+}
- return true, pull_model.ScheduleAutoMerge(ctx, doer, pull.ID, style, message)
+// RemoveScheduledAutoMerge cancels a previously scheduled pull request
+func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *models.PullRequest) error {
+ return db.WithTx(func(ctx context.Context) error {
+ if err := pull_model.DeleteScheduledAutoMerge(ctx, pull.ID); err != nil {
+ return err
+ }
+
+ _, err := models.CreateAutoMergeComment(ctx, models.CommentTypePRUnScheduledToAutoMerge, pull, doer)
+ return err
+ }, ctx)
}
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded
diff --git a/services/pull/merge.go b/services/pull/merge.go
index b14abcd780..e054df716b 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -141,7 +141,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
// Removing an auto merge pull and ignore if not exist
- if err := pull_model.RemoveScheduledAutoMerge(db.DefaultContext, doer, pr.ID, false); err != nil && !models.IsErrNotExist(err) {
+ if err := pull_model.DeleteScheduledAutoMerge(db.DefaultContext, pr.ID); err != nil && !db.IsErrNotExist(err) {
return err
}