Skip to content
Merged
Changes from all 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
43 changes: 34 additions & 9 deletions .github/workflows/chatOps.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
# SPDX-License-Identifier: GPL-3.0-or-later
name: chatOps
on:
workflow_call:
Expand Down Expand Up @@ -371,22 +373,45 @@ jobs:
pull_number: context.issue.number,
})

if( pull.data.mergeable_state != "clean" ){
// GitHub rejects a merge method that cannot be applied to this PR with
// 405/409, e.g. "This branch can't be rebased" for a sync PR that merges
// master into a release branch. Try the methods in order of preference:
// rebase keeps the history linear, squash flattens the PR, and a merge
// commit is the last resort.
let mergeMethod
const mergeFailures = []
for (const method of ['rebase', 'squash', 'merge']) {
try {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: method
})
mergeMethod = method
break
} catch (error) {
if (error.status !== 405 && error.status !== 409) {
throw error
}
mergeFailures.push(`${method}: ${error.status} ${error.message}`)
}
}
if( !mergeMethod ){
throw new Error(`could not merge #${context.issue.number} with any merge method (${mergeFailures.join('; ')})`)
}

// Report the merge whenever a fallback method was used, even if the PR
// was already clean, so the method switch is not silent.
if( mergeMethod != "rebase" || pull.data.mergeable_state != "clean" ){
await github.rest.issues.createComment({
issue_number: context.issue.number,
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
sourcery-ai[bot] marked this conversation as resolved.
Resolved
})
}

await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
merge_method: 'rebase'
});

pr-info:
runs-on: ubuntu-latest
outputs:
Expand Down
Loading