diff --git a/github-actions/create-pr-for-changes/lib/main.ts b/github-actions/create-pr-for-changes/lib/main.ts index bfcdb1ef0..46f59e322 100644 --- a/github-actions/create-pr-for-changes/lib/main.ts +++ b/github-actions/create-pr-for-changes/lib/main.ts @@ -92,10 +92,34 @@ 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 branch: #${branchName}`); + // Push the local branch to update the target branch (already rebased) + git.run(['checkout', '-b', branchName]); + git.run([ + 'push', + '--force-with-lease', + getRepositoryGitUrl(forkRepo, git.githubToken), + `HEAD:refs/heads/${branchName}`, + ]); + } + } + return; } else { core.info(`No pre-existing PR found for branch '${branchName}'.`); diff --git a/github-actions/create-pr-for-changes/main.js b/github-actions/create-pr-for-changes/main.js index 50e1d14ab..f2b2d86bc 100644 --- a/github-actions/create-pr-for-changes/main.js +++ b/github-actions/create-pr-for-changes/main.js @@ -47972,7 +47972,24 @@ async function main() { state: "open" }); if (matchingPrs.length > 0) { - core.info(`Skipping PR creation, because there is already a PR: #${matchingPrs[0].number} (${matchingPrs[0].html_url})`); + for (const matchingPr of matchingPrs) { + 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 branch: #${branchName}`); + git.run(["checkout", "-b", branchName]); + git.run([ + "push", + "--force-with-lease", + getRepositoryGitUrl(forkRepo, git.githubToken), + `HEAD:refs/heads/${branchName}` + ]); + } + } return; } else { core.info(`No pre-existing PR found for branch '${branchName}'.`);