Skip to content

Commit 21f9d71

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 21f9d71

File tree

1 file changed

+28
-5
lines changed
  • github-actions/create-pr-for-changes/lib

1 file changed

+28
-5
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,34 @@ async function main(): Promise<void> {
9191
});
9292

9393
if (matchingPrs.length > 0) {
94-
// 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-
);
94+
for (const matchingPr of matchingPrs) {
95+
// A PR for the same set of changes does already exist. Exit.
96+
// Check whether there is a PR is conflicting
97+
const {data} = await git.github.pulls.get({
98+
owner: repo.owner,
99+
repo: repo.name,
100+
pull_number: matchingPr.number,
101+
});
102+
103+
if (data.mergeable) {
104+
core.info(
105+
`Skipping PR creation, because there is already a PR: #${matchingPr.number} ` +
106+
`(${matchingPr.html_url})`,
107+
);
108+
} else {
109+
core.info(
110+
`PR is not mergable, rebasing PR: #${matchingPr.number} ` + `(${matchingPr.html_url})`,
111+
);
112+
113+
// Rebase PR
114+
await git.github.pulls.updateBranch({
115+
owner: repo.owner,
116+
repo: repo.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)