Skip to content

Commit 022692b

Browse files
s0Andarist
andauthored
Fix PRs sometimes not getting reopened with commitMode: github-api (#488)
* Fix PRs sometimes not getting reopened There was a race-condition that means sometimes existing PRs would not be found, and new PRs would be opened. This has now been fixed by fetching existing PRs before making any changes. fixes #487 * Apply suggestions from code review --------- Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent 0564b84 commit 022692b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

.changeset/big-cougars-mate.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
Fix PRs sometimes not getting reopened with `commitMode: github-api`
6+
7+
There was a race-condition that means sometimes existing PRs would not be found,
8+
and new PRs would be opened. This has now been fixed by fetching existing PRs
9+
before making any changes.
10+

src/run.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,22 @@ export async function runVersion({
314314
!!preState ? ` (${preState.tag})` : ""
315315
}`;
316316

317-
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
318-
319-
let existingPullRequests = await octokit.rest.pulls.list({
317+
/**
318+
* Fetch any existing pull requests that are open against the branch,
319+
* before we push any changes that may inadvertently close the existing PRs.
320+
*
321+
* (`@changesets/ghcommit` has to reset the branch to the same commit as the base,
322+
* which GitHub will then react to by closing the PRs)
323+
*/
324+
const existingPullRequests = await octokit.rest.pulls.list({
320325
...github.context.repo,
321326
state: "open",
322327
head: `${github.context.repo.owner}:${versionBranch}`,
323328
base: branch,
324329
});
325-
core.info(JSON.stringify(existingPullRequests.data, null, 2));
330+
core.info(`Existing pull requests: ${JSON.stringify(existingPullRequests.data, null, 2)}`);
331+
332+
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
326333

327334
const changedPackagesInfo = (await changedPackagesInfoPromises)
328335
.filter((x) => x)

0 commit comments

Comments
 (0)