File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed
github-actions/create-pr-for-changes Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -92,10 +92,34 @@ 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 branch: #${ branchName } ` ) ;
112+ // Push the local branch to update the target branch (already rebased)
113+ git . run ( [ 'checkout' , '-b' , branchName ] ) ;
114+ git . run ( [
115+ 'push' ,
116+ '--force-with-lease' ,
117+ getRepositoryGitUrl ( forkRepo , git . githubToken ) ,
118+ `HEAD:refs/heads/${ branchName } ` ,
119+ ] ) ;
120+ }
121+ }
122+
99123 return ;
100124 } else {
101125 core . info ( `No pre-existing PR found for branch '${ branchName } '.` ) ;
Original file line number Diff line number Diff line change @@ -47972,7 +47972,24 @@ async function main() {
4797247972 state: "open"
4797347973 });
4797447974 if (matchingPrs.length > 0) {
47975- core.info(`Skipping PR creation, because there is already a PR: #${matchingPrs[0].number} (${matchingPrs[0].html_url})`);
47975+ for (const matchingPr of matchingPrs) {
47976+ const { data: { mergeable } } = await git.github.pulls.get({
47977+ owner: repo.owner,
47978+ repo: repo.name,
47979+ pull_number: matchingPr.number
47980+ });
47981+ core.info(`Skipping PR creation, because there is already a PR: #${matchingPr.number} (${matchingPr.html_url})`);
47982+ if (!mergeable) {
47983+ core.info(`PR is not mergable, rebasing branch: #${branchName}`);
47984+ git.run(["checkout", "-b", branchName]);
47985+ git.run([
47986+ "push",
47987+ "--force-with-lease",
47988+ getRepositoryGitUrl(forkRepo, git.githubToken),
47989+ `HEAD:refs/heads/${branchName}`
47990+ ]);
47991+ }
47992+ }
4797647993 return;
4797747994 } else {
4797847995 core.info(`No pre-existing PR found for branch '${branchName}'.`);
You can’t perform that action at this time.
0 commit comments