mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-27 04:33:50 +00:00
fix: prevent pull requests from being merged multiple times
This commit is contained in:
parent
445e2b1344
commit
0b552407fe
5 changed files with 63 additions and 4 deletions
|
@ -239,7 +239,30 @@ func AddCommitMessageTrailer(message, tailerKey, tailerValue string) string {
|
|||
// Merge merges pull request to base repository.
|
||||
// Caller should check PR is ready to be merged (review and status checks)
|
||||
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
|
||||
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
|
||||
|
||||
pr, err := issues_model.GetPullRequestByID(ctx, pr.ID)
|
||||
if err != nil {
|
||||
log.Error("Unable to load pull request itself: %v", err)
|
||||
return fmt.Errorf("unable to load pull request itself: %w", err)
|
||||
}
|
||||
|
||||
if pr.HasMerged {
|
||||
return models.ErrPullRequestHasMerged{
|
||||
ID: pr.ID,
|
||||
IssueID: pr.IssueID,
|
||||
HeadRepoID: pr.HeadRepoID,
|
||||
BaseRepoID: pr.BaseRepoID,
|
||||
HeadBranch: pr.HeadBranch,
|
||||
BaseBranch: pr.BaseBranch,
|
||||
}
|
||||
}
|
||||
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("Unable to load issue: %v", err)
|
||||
return fmt.Errorf("unable to load issue: %w", err)
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repo: %v", err)
|
||||
return fmt.Errorf("unable to load base repo: %w", err)
|
||||
} else if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
|
@ -247,9 +270,6 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
|||
return fmt.Errorf("unable to load head repo: %w", err)
|
||||
}
|
||||
|
||||
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
|
||||
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
|
||||
|
||||
prUnit, err := pr.BaseRepo.GetUnit(ctx, unit.TypePullRequests)
|
||||
if err != nil {
|
||||
log.Error("pr.BaseRepo.GetUnit(unit.TypePullRequests): %v", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue