From 27f86453705bf4453decd7fd8057cace5f968d70 Mon Sep 17 00:00:00 2001 From: Sam Lanning Date: Mon, 12 May 2025 22:36:19 +0100 Subject: [PATCH 1/2] 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 --- .changeset/big-cougars-mate.md | 11 +++++++++++ src/run.ts | 15 +++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .changeset/big-cougars-mate.md diff --git a/.changeset/big-cougars-mate.md b/.changeset/big-cougars-mate.md new file mode 100644 index 00000000..ef691bf2 --- /dev/null +++ b/.changeset/big-cougars-mate.md @@ -0,0 +1,11 @@ +--- +"@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. + +fixes #487 diff --git a/src/run.ts b/src/run.ts index 60dba996..3c330f29 100644 --- a/src/run.ts +++ b/src/run.ts @@ -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) From 73df049fa3095a5824b7f913ff195cba9297e6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 15 May 2025 21:45:50 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- .changeset/big-cougars-mate.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/big-cougars-mate.md b/.changeset/big-cougars-mate.md index ef691bf2..1ec58e48 100644 --- a/.changeset/big-cougars-mate.md +++ b/.changeset/big-cougars-mate.md @@ -2,10 +2,9 @@ "@changesets/action": patch --- -Fix PRs sometimes not getting reopened (with `commitMode: github-api`) +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. -fixes #487