fix(automerge): validate head commit before merge (#39235)

Co-authored-by: zihao_wang <zihao_wang@geelark.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Even
2026-09-05 10:20:00 +00:00
committed by GitHub
co-authored by zihao_wang wxiaoguang
parent bde1af541c
commit cf0f4dce72
+6 -1
View File
@@ -221,7 +221,12 @@ func handlePullRequestAutoMerge(ctx context.Context, pr *issues_model.PullReques
return errors.Join(errSkipAutoMerge, errors.New("pull request is not mergeable"))
}
if err := pull_service.Merge(pr, doer, scheduledPRM.MergeStyle, "", scheduledPRM.Message, true); err != nil {
// although expectedHeadCommitID is checked before, we should pass it to the Merge function to
// make it be checked again in case the head commit id changed after the previous check.
if err := pull_service.Merge(pr, doer, scheduledPRM.MergeStyle, expectedHeadCommitID, scheduledPRM.Message, true); err != nil {
if pull_service.IsErrSHADoesNotMatch(err) {
return errors.Join(errSkipAutoMerge, err)
}
// FIXME: if merge failed, we should display some error message to the pull request page, or retry later.
// The resolution is add a new column on automerge table named `error_message` to store the error message and displayed
// on the pull request page. But this should not be finished in a bug fix PR which will be backport to release branch.