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}'.`);