Skip to content

Commit 1ca0fc9

Browse files
committed
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.
1 parent 2c7bab7 commit 1ca0fc9

File tree

1 file changed

+27
-4
lines changed
  • github-actions/create-pr-for-changes/lib

1 file changed

+27
-4
lines changed

github-actions/create-pr-for-changes/lib/main.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,33 @@ async function main(): Promise<void> {
9292

9393
if (matchingPrs.length > 0) {
9494
// A PR for the same set of changes does already exist. Exit.
95-
core.info(
96-
`Skipping PR creation, because there is already a PR: #${matchingPrs[0].number} ` +
97-
`(${matchingPrs[0].html_url})`,
98-
);
95+
for (const matchingPr of matchingPrs) {
96+
// Check whether there is a PR is conflicting
97+
const {
98+
data: {mergeable},
99+
} = await git.github.pulls.get({
100+
owner: repo.owner,
101+
repo: repo.name,
102+
pull_number: matchingPr.number,
103+
});
104+
105+
core.info(
106+
`Skipping PR creation, because there is already a PR: #${matchingPr.number} ` +
107+
`(${matchingPr.html_url})`,
108+
);
109+
110+
if (!mergeable) {
111+
core.info(`PR is not mergable, rebasing PR: #${matchingPr.number}`);
112+
113+
// Rebase PR
114+
await git.github.pulls.updateBranch({
115+
owner: forkRepo.owner,
116+
repo: forkRepo.name,
117+
pull_number: matchingPr.number,
118+
});
119+
}
120+
}
121+
99122
return;
100123
} else {
101124
core.info(`No pre-existing PR found for branch '${branchName}'.`);

0 commit comments

Comments
 (0)