From 1ca0fc99867ef757166c973e852b3736745ca3b2 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Thu, 8 May 2025 09:18:11 +0000 Subject: [PATCH] fix(github-actions): update `create-pr-for-changes` to rebase on conflicts Ensures the action automatically rebases pull requests when conflicts are detected, improving automation reliability and reducing manual intervention. --- .../create-pr-for-changes/lib/main.ts | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/github-actions/create-pr-for-changes/lib/main.ts b/github-actions/create-pr-for-changes/lib/main.ts index bfcdb1ef0..6630d935e 100644 --- a/github-actions/create-pr-for-changes/lib/main.ts +++ b/github-actions/create-pr-for-changes/lib/main.ts @@ -92,10 +92,33 @@ async function main(): Promise { if (matchingPrs.length > 0) { // A PR for the same set of changes does already exist. Exit. - core.info( - `Skipping PR creation, because there is already a PR: #${matchingPrs[0].number} ` + - `(${matchingPrs[0].html_url})`, - ); + for (const matchingPr of matchingPrs) { + // Check whether there is a PR is conflicting + const { + data: {mergeable}, + } = await git.github.pulls.get({ + owner: repo.owner, + repo: repo.name, + pull_number: matchingPr.number, + }); + + core.info( + `Skipping PR creation, because there is already a PR: #${matchingPr.number} ` + + `(${matchingPr.html_url})`, + ); + + if (!mergeable) { + core.info(`PR is not mergable, rebasing PR: #${matchingPr.number}`); + + // Rebase PR + await git.github.pulls.updateBranch({ + owner: forkRepo.owner, + repo: forkRepo.name, + pull_number: matchingPr.number, + }); + } + } + return; } else { core.info(`No pre-existing PR found for branch '${branchName}'.`);