fix: push release PR updates via Git Data API instead of code-suggester - #2774
fix: push release PR updates via Git Data API instead of code-suggester#2774Kerwood wants to merge 3 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
I believe this PR aligns well with the future plan to remove code-suggester as a dependency in this project, since it implements its own @chingor13 Any chance you've had time to look at this PR? |
|
@chingor13 Would you mind giving feedback on this PR when you have a chance? |
|
@chingor13 Any feedback for this PR ? |
Fixes #2773
When
separate-pull-requests: trueis set, updating an existing release PR consistently fails with:The branch is updated successfully (
Updating reference heads/release-please--branches--main--components--<comp>), but the action exits non-zero.Reproduces on
release-please-action@v4and@v5, against library 17.3.0 and 17.6.0, with a GitHub App token.Root cause
GitHub.updatePullRequest(andLocalGitHub.updatePullRequest) was reusingcode-suggester.createPullRequestto do both the branch push and the PR refresh.code-suggesteralways:octokit.pulls.list({head})plus a strictpr.head.label === headfind,octokit.pulls.create.The lookup in step (2) is best-effort. It can miss the PR for several reasons, case-sensitivity differences between
repository.owner(sometimes lowercased through env-var paths likeGITHUB_REPOSITORY) and the org login as GitHub returns it inpr.head.label, the un-paginated single-page response, brief eventual consistency onpulls.list. When the lookup misses, step (3) runs and GitHub returns 422 because there's obviously already a PR for that branch.release-pleasealready knows the PR number it's updating,manifest.ts:1040matched the existing PR before callingupdatePullRequest. So the detect-or-create step is unnecessary work that can fail. Only the create path actually needs find-or-create semantics; the update path was misusingcode-suggester.The bug surfaces especially under
separate-pull-requests: truebecause each component's body diverges independently after a new commit, and every divergent body hits the update path.Fix
commitAndPushChanges(branch, message, changes)toGitHubApi. It uses the Git Data API directly:getRef → getCommit → createBlob (per file) → createTree → createCommit → updateRef --force. No PR detection. No PR create. Empty change sets are a no-op.GitHub.updatePullRequestandLocalGitHub.updatePullRequestnow callcommitAndPushChangesfollowed by the existinggitHubApi.updatePullRequest(number, title, body)PATCH.code-suggesteris no longer touched in the update path, sooctokit.pulls.createcannot be called and the 422 cannot occur, regardless of how the upstream lookup would have behaved.GitHub.createPullRequest) is unchanged. "Find-or-create" is the correct semantic there; only the reuse in the update path was wrong.Test plan
npm run compile, passesnpm run lint, clean (only pre-existing warnings in unrelated files)npm test, full suite (1101 tests) passesYou can test the fix by using my
release-please-actionfork.