From f4041fd70bbac19dac1c0a07fe64401ab5e96655 Mon Sep 17 00:00:00 2001 From: William Harrison <87287585+wdhdev@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:47:36 +0800 Subject: [PATCH] Implement merge conflict handling in PR updates Added logic to handle merge conflicts in PRs, including labeling and commenting. --- .github/workflows/update-pr-branches.yml | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.github/workflows/update-pr-branches.yml b/.github/workflows/update-pr-branches.yml index 88ff96976c..d69a4f9ae2 100644 --- a/.github/workflows/update-pr-branches.yml +++ b/.github/workflows/update-pr-branches.yml @@ -26,6 +26,8 @@ jobs: with: github-token: ${{ secrets.BOT }} script: | + const marker = ""; + const prs = await github.paginate( github.rest.pulls.list, { @@ -49,5 +51,57 @@ jobs: console.log(`Updated #${pr.number} (${pr.head.ref})`); } catch (error) { console.log(`Could not update #${pr.number}: ${error.message}`); + + const { data: updatedPr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number + }); + + if (updatedPr.mergeable !== false) { + continue; + } + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + labels: ["reason: merge conflict"] + }); + + const comments = await github.paginate( + github.rest.issues.listComments, + { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number + } + ); + + const alreadyCommented = comments.some( + (comment) => + comment.user?.login === "is-a-dev-bot" && + comment.body?.includes(marker) + ); + + if (!alreadyCommented) { + const body = [ + marker, + "## ❌ Merge conflict", + "", + "This pull request can not be merged because it has merge conflicts with `main`.", + "", + "***Please resolve the merge conflicts before this PR can be merged!***" + ].join("\n"); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body + }); + } + + console.log(`Marked #${pr.number} as having merge conflicts`); } }