Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/big-cougars-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@changesets/action": patch
---

Fix PRs sometimes not getting reopened with `commitMode: github-api`

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.

15 changes: 11 additions & 4 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,22 @@ export async function runVersion({
!!preState ? ` (${preState.tag})` : ""
}`;

await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });

let existingPullRequests = await octokit.rest.pulls.list({
/**
* Fetch any existing pull requests that are open against the branch,
* before we push any changes that may inadvertently close the existing PRs.
*
* (`@changesets/ghcommit` has to reset the branch to the same commit as the base,
* which GitHub will then react to by closing the PRs)
*/
const existingPullRequests = await octokit.rest.pulls.list({
...github.context.repo,
state: "open",
head: `${github.context.repo.owner}:${versionBranch}`,
base: branch,
});
core.info(JSON.stringify(existingPullRequests.data, null, 2));
core.info(`Existing pull requests: ${JSON.stringify(existingPullRequests.data, null, 2)}`);

await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });

const changedPackagesInfo = (await changedPackagesInfoPromises)
.filter((x) => x)
Expand Down