fix: PR merge (#39442)

* Revert the behavior introduced by #30805
* Now the PR status is still managed in Gitea's code where the operation
is triggerred but not in post-receive hook
* Fix #39254 and many more related bugs.
    * Fix #39124

```
// MarkAsMerged sets a pull request to merged and closes the corresponding issue
// To make sure the pull request is marked as merged correctly, the caller uses multiple-stage operations:
//  1. Create a temp repo from base, merge the head into the temp repo, and get the merged commit ID and timestamp,
//  2. The merged commit ID and related information are stored into pull request
//  3. Push the merged commit to the base repo
//  4. Call MarkAsMerged to mark the pull request as merged and do post-processing (notification, close issues, etc)
//
// If failure occurs in step 1/2/3: the pull request is still open, the base repo is not changed, the doer can start a new merge.
// If failure occurs in step 4: the pull request can be marked as merged by the merged commit ID stored in it later.
```
This commit is contained in:
wxiaoguang
2026-09-27 01:38:42 +08:00
committed by GitHub
parent dcef88a233
commit ea91028028
20 changed files with 359 additions and 356 deletions
+1
View File
@@ -428,6 +428,7 @@ func prepareMigrationTasks() []*migration {
newMigration(352, "Add token columns to deploy_key", v28.AddTokenToDeployKey),
newMigration(353, "Add audit event table", v28.AddAuditEventTable),
newMigration(354, "Add Actions job queue indexes", v28.AddActionQueueIndexes),
newMigration(355, "Add AutoMerge merged_commit_id column", v28.AddAutoMergeMergedCommitID),
}
return preparedMigrations
}
+28
View File
@@ -0,0 +1,28 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v28
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
type pullAutoMerge struct {
MergedCommitID string `xorm:"VARCHAR(64)"`
}
func (pullAutoMerge) TableName() string {
return "pull_auto_merge"
}
func AddAutoMergeMergedCommitID(_ context.Context, x base.EngineMigration) error {
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreConstrains: true,
IgnoreDropIndices: true,
}, new(pullAutoMerge))
return err
}