aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/pull.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-08-10 10:39:21 +0800
committerGitHub <noreply@github.com>2023-08-10 02:39:21 +0000
commit36eb3c433ae384f21beec63eb648141fb9dba676 (patch)
tree4f8ad47b15981b1f802de9695ec402f8b756cb62 /models/issues/pull.go
parenta85a8628042c788ce2b372a29ca1cefab544f1ed (diff)
downloadgitea-36eb3c433ae384f21beec63eb648141fb9dba676.tar.gz
gitea-36eb3c433ae384f21beec63eb648141fb9dba676.zip
Add transaction when creating pull request created dirty data (#26259)
Fix #26129 Replace #26258 This PR will introduce a transaction on creating pull request so that if some step failed, it will rollback totally. And there will be no dirty pull request exist. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/issues/pull.go')
-rw-r--r--models/issues/pull.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/models/issues/pull.go b/models/issues/pull.go
index cedbb62c3c..676224a3d6 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -533,13 +533,12 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) {
}
// NewPullRequest creates new pull request with labels for repository.
-func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string, pr *PullRequest) (err error) {
- ctx, committer, err := db.TxContext(outerCtx)
+func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string, pr *PullRequest) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
- ctx.WithContext(outerCtx)
idx, err := db.GetNextResourceIndex(ctx, "issue_index", repo.ID)
if err != nil {
@@ -948,14 +947,14 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque
for _, u := range uniqUsers {
if u.ID != pull.Poster.ID {
- if _, err := AddReviewRequest(pull, u, pull.Poster); err != nil {
+ if _, err := AddReviewRequest(ctx, pull, u, pull.Poster); err != nil {
log.Warn("Failed add assignee user: %s to PR review: %s#%d, error: %s", u.Name, pr.BaseRepo.Name, pr.ID, err)
return err
}
}
}
for _, t := range uniqTeams {
- if _, err := AddTeamReviewRequest(pull, t, pull.Poster); err != nil {
+ if _, err := AddTeamReviewRequest(ctx, pull, t, pull.Poster); err != nil {
log.Warn("Failed add assignee team: %s to PR review: %s#%d, error: %s", t.Name, pr.BaseRepo.Name, pr.ID, err)
return err
}