Skip to content

fix(CI): retry /forcemerge with squash and merge when rebase fails - #823

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
hudeng-go:fix/forcemerge-rebase-fallback
Nov 30, 2026
Merged

BLumia merged 1 commit into
linuxdeepin:masterfrom
hudeng-go:fix/forcemerge-rebase-fallback

Conversation

@hudeng-go

@hudeng-go hudeng-go commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

问题

/forcemerge 在部分 PR 上无法合并,GitHub API 返回:

RequestError [HttpError]: This branch can't be rebased
  status: 405
  url: 'https://api.github.com/repos/linuxdeepin/dtkdeclarative/pulls/760/merge'
  body: '{"merge_method":"rebase"}'

例如 linuxdeepin/dtkdeclarative#760(chore: merge master into v25-flowstyle)。该 PR 的 head 是一个 merge commit,v25-flowstyle..head 有 32 个提交;GitHub 的 rebase 合并需要把这些提交重放到 base 上,与 base 分支的改动冲突(qt6/src/qml/ArrowListView.qml),因此 rebase 方式不可用。

修改

forcemerge 步骤按 rebase → squash → merge 的顺序尝试合并:某一种方式被 GitHub 以 405/409 拒绝(如 This branch can't be rebased)时换下一种,三种都失败才抛错并汇总各方式的原因;非 405/409 的错误(权限、参数等)直接抛出。

  • Fallback merge goes unreported:只要最终使用了回退方式(squash/merge),就发送 This pr force merged! 注释并在内容里带上实际使用的 merge_method,即使合并前 mergeable_state 已经是 clean;原来只在状态非 clean 时才发注释,回退成功是静默的。
  • Modified workflow lacks copyright year:按 .github/copilot-instructions.md 的要求补上 SPDX 头(该文件创建于 2022 年、本次修改于 2026 年,使用 2022-2026 范围格式)。

验证

  • yaml.safe_load 通过;内嵌脚本 node --check 通过。
  • 本地 mock 验证合并顺序:rebase 成功 → rebase;rebase 405 → squash;两者都失败 → merge;三种都失败 → 抛出汇总错误;403 等直接抛出。
  • 本地对 chore: merge master into v25-flowstyle dtkdeclarative#760 验证:git rebase 冲突,git merge 干净通过(base 是 head 的祖先,fast-forward)。

备注

  • /merge 步骤同样硬编码 merge_method: 'rebase',但它只在 mergeable_state == "clean" 时才会走到合并,本次未改动。

@sourcery-ai

sourcery-ai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Add SPDX headers and update the ChatOps /forcemerge workflow to try rebase, squash, then merge on 405/409 errors, and report success only after merging with the method used.

  • .github/workflows/chatOps.yml L376-406 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@hudeng-go
hudeng-go force-pushed the fix/forcemerge-rebase-fallback branch from 54c57ee to 6229977 Compare November 30, 2026 06:12

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/workflows/chatOps.yml" line_range="395" />
<code_context>
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                pull_number: context.issue.number,
+                merge_method: mergeMethod
+              })
+            } catch (error) {
</code_context>
<issue_to_address>
**Fallback remains disabled for target repository**

When `/forcemerge` runs in `dtkdeclarative` and rebase is rejected, gitHub rejects the `merge` fallback because `organization.yaml` lists `dtkdeclarative` among repositories with `allow_merge_commit` disabled; the error propagates, so `/forcemerge` still cannot merge the reported PR.

Enable merge commits for `dtkdeclarative`, or use a fallback method permitted by its repository settings.
</issue_to_address>

### Comment 2
<location path=".github/workflows/chatOps.yml" line_range="404" />
<code_context>
                 owner: context.repo.owner,
                 repo: context.repo.repo,
-                body: `This pr force merged! (status: ${pull.data.mergeable_state})`
+                body: `This pr force merged! (status: ${pull.data.mergeable_state}, merge_method: ${mergeMethod})`
               })
             }
</code_context>
<issue_to_address>
**Merged PR loses success notice**

When the merge succeeds but the post-merge comment request fails or the job stops before it completes, `issues.createComment` can fail after the merge, leaving the PR merged without a force-merge comment; an uncaught API error also marks the workflow run as failed, and retrying `/forcemerge` attempts the merge again and exits before restoring the comment.

Make post-merge comment delivery recoverable without rerunning the merge, and handle comment API errors separately from merge success.
</issue_to_address>

### Comment 3
<location path=".github/workflows/chatOps.yml" line_range="404" />
<code_context>
                 owner: context.repo.owner,
                 repo: context.repo.repo,
-                body: `This pr force merged! (status: ${pull.data.mergeable_state})`
+                body: `This pr force merged! (status: ${pull.data.mergeable_state}, merge_method: ${mergeMethod})`
               })
             }
</code_context>
<issue_to_address>
**Fallback merge goes unreported**

When the rebase attempt is rejected, the merge-method fallback succeeds, and the fetched PR state is `clean`, `pull.data.mergeable_state` is `clean`, so the guard at line 399 skips `createComment` even after `mergeMethod` changes to `merge`; users get no success notice or indication that the fallback merge method was used.

Post the success comment after any successful fallback merge, regardless of the initial mergeable state.
</issue_to_address>

### Comment 4
<location path=".github/workflows/chatOps.yml" line_range="374" />
<code_context>
               pull_number: context.issue.number,
             })

+            // A rebase merge keeps the history linear, but GitHub rejects it with
+            // 405 "This branch can't be rebased" when the PR branch contains merge
+            // commits or conflicts with the base branch (e.g. a sync PR merging
</code_context>
<issue_to_address>
**Modified workflow lacks copyright year**

When this pull request modifies `.github/workflows/chatOps.yml` without adding an SPDX header, `.github/workflows/chatOps.yml` has no SPDX copyright header, so this modification leaves the file without the required copyright-year update.

Add the required SPDX copyright and license header, with the copyright year updated through 2026.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .github/workflows/chatOps.yml Outdated
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: mergeMethod

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Fallback remains disabled for target repository

When /forcemerge runs in dtkdeclarative and rebase is rejected, gitHub rejects the merge fallback because organization.yaml lists dtkdeclarative among repositories with allow_merge_commit disabled; the error propagates, so /forcemerge still cannot merge the reported PR.

Enable merge commits for dtkdeclarative, or use a fallback method permitted by its repository settings.

Prompt for AI agents
In `.github/workflows/chatOps.yml` at line 395:

**Fallback remains disabled for target repository**

When `/forcemerge` runs in `dtkdeclarative` and rebase is rejected, gitHub rejects the `merge` fallback because `organization.yaml` lists `dtkdeclarative` among repositories with `allow_merge_commit` disabled; the error propagates, so `/forcemerge` still cannot merge the reported PR.

Enable merge commits for `dtkdeclarative`, or use a fallback method permitted by its repository settings.

owner: context.repo.owner,
repo: context.repo.repo,
body: `This pr force merged! (status: ${pull.data.mergeable_state})`
body: `This pr force merged! (status: ${pull.data.mergeable_state}, merge_method: ${mergeMethod})`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Merged PR loses success notice

When the merge succeeds but the post-merge comment request fails or the job stops before it completes, issues.createComment can fail after the merge, leaving the PR merged without a force-merge comment; an uncaught API error also marks the workflow run as failed, and retrying /forcemerge attempts the merge again and exits before restoring the comment.

Make post-merge comment delivery recoverable without rerunning the merge, and handle comment API errors separately from merge success.

Prompt for AI agents
In `.github/workflows/chatOps.yml` at line 404:

**Merged PR loses success notice**

When the merge succeeds but the post-merge comment request fails or the job stops before it completes, `issues.createComment` can fail after the merge, leaving the PR merged without a force-merge comment; an uncaught API error also marks the workflow run as failed, and retrying `/forcemerge` attempts the merge again and exits before restoring the comment.

Make post-merge comment delivery recoverable without rerunning the merge, and handle comment API errors separately from merge success.

Comment thread .github/workflows/chatOps.yml Resolved
Comment thread .github/workflows/chatOps.yml Resolved
@hudeng-go
hudeng-go force-pushed the fix/forcemerge-rebase-fallback branch from 6229977 to 102b9b3 Compare November 30, 2026 07:01
@hudeng-go hudeng-go changed the title fix(CI): fall back to merge commit when /forcemerge rebase fails fix(CI): retry /forcemerge with squash and merge when rebase fails Nov 30, 2026
@hudeng-go
hudeng-go force-pushed the fix/forcemerge-rebase-fallback branch from 102b9b3 to 8765f1e Compare November 30, 2026 07:03
GitHub rejects a merge method that cannot be applied to the PR with
405/409, e.g. "This branch can't be rebased" for a sync PR that merges
master into a release branch. /forcemerge then fails silently after
posting "This pr force merged!". Try rebase first, then squash, and fall
back to a merge commit as the last resort, reporting the method used.

Post the success comment whenever a fallback method was used, even if
the PR was already clean, so the method switch is not silent. Add the
SPDX copyright header with the year range 2022-2026.
@hudeng-go
hudeng-go force-pushed the fix/forcemerge-rebase-fallback branch from 8765f1e to 5c248ef Compare November 30, 2026 07:25
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, hudeng-go

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia
BLumia merged commit 7ac2e9a into linuxdeepin:master Nov 30, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants