Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do DB update after merge in hammer context (#21401) #21416

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions services/pull/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/references"
Expand Down Expand Up @@ -165,9 +166,10 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
go AddTestPullRequestTask(doer, pr.BaseRepo.ID, pr.BaseBranch, false, "", "")
}()

// TODO: make it able to do this in a database session
mergeCtx := context.Background()
pr.MergedCommitID, err = rawMerge(mergeCtx, pr, doer, mergeStyle, expectedHeadCommitID, message)
// Run the merge in the hammer context to prevent cancellation
hammerCtx := graceful.GetManager().HammerContext()

pr.MergedCommitID, err = rawMerge(hammerCtx, pr, doer, mergeStyle, expectedHeadCommitID, message)
if err != nil {
return err
}
Expand All @@ -176,18 +178,18 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
pr.Merger = doer
pr.MergerID = doer.ID

if _, err := pr.SetMerged(ctx); err != nil {
if _, err := pr.SetMerged(hammerCtx); err != nil {
log.Error("setMerged [%d]: %v", pr.ID, err)
}

if err := pr.LoadIssueCtx(ctx); err != nil {
if err := pr.LoadIssueCtx(hammerCtx); err != nil {
log.Error("loadIssue [%d]: %v", pr.ID, err)
}

if err := pr.Issue.LoadRepo(ctx); err != nil {
if err := pr.Issue.LoadRepo(hammerCtx); err != nil {
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
}
if err := pr.Issue.Repo.GetOwner(ctx); err != nil {
if err := pr.Issue.Repo.GetOwner(hammerCtx); err != nil {
log.Error("GetOwner for issue repo [%d]: %v", pr.ID, err)
}

Expand All @@ -197,17 +199,17 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
cache.Remove(pr.Issue.Repo.GetCommitsCountCacheKey(pr.BaseBranch, true))

// Resolve cross references
refs, err := pr.ResolveCrossReferences(ctx)
refs, err := pr.ResolveCrossReferences(hammerCtx)
if err != nil {
log.Error("ResolveCrossReferences: %v", err)
return nil
}

for _, ref := range refs {
if err = ref.LoadIssueCtx(ctx); err != nil {
if err = ref.LoadIssueCtx(hammerCtx); err != nil {
return err
}
if err = ref.Issue.LoadRepo(ctx); err != nil {
if err = ref.Issue.LoadRepo(hammerCtx); err != nil {
return err
}
close := ref.RefAction == references.XRefActionCloses
Expand Down