-
Notifications
You must be signed in to change notification settings - Fork 424
Handle update_pull_request.update_branch workflow-permission failures as non-fatal
#32900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
10efb47
2e83d62
6623ed4
8de97af
a9c0780
ea50650
59386ed
c148a58
a973720
2b8eb85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,16 +31,27 @@ function isNonFatalUpdateBranchError(error) { | |
| status = candidateStatus; | ||
| } | ||
| } | ||
| if (status !== undefined && status !== 422) { | ||
| return false; | ||
| const message = getErrorMessage(error).toLowerCase(); | ||
| const hasWorkflowsPermissionPhrase = /without\s+`?workflows`?\s+permission/i.test(message); | ||
| const hasWorkflowMutationRefusal = message.includes("refusing to allow a github app to create or update workflow"); | ||
| // Require both permission wording and update-branch context to avoid treating unrelated | ||
| // "workflows permission" errors as non-fatal for pull request branch updates. | ||
| const hasWorkflowsPermissionError = hasWorkflowsPermissionPhrase && (hasWorkflowMutationRefusal || message.includes("update pull request")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The |
||
|
|
||
| if (status !== undefined) { | ||
| if (status === 403 && hasWorkflowsPermissionError) { | ||
| return true; | ||
| } | ||
| if (status !== 422) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // GitHub update-branch API can return these 422 messages for benign conditions: | ||
| // - already up to date ("There are no new commits on the base branch") | ||
| // - cannot auto-update due to conflict ("merge conflict between base and head") | ||
| // These should not fail safe output processing. | ||
| const message = getErrorMessage(error).toLowerCase(); | ||
| return message.includes("there are no new commits on the base branch") || message.includes("merge conflict between base and head"); | ||
| return message.includes("there are no new commits on the base branch") || message.includes("merge conflict between base and head") || hasWorkflowsPermissionError; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -879,4 +879,26 @@ describe("update_pull_request.cjs - update_branch behavior", () => { | |
| }); | ||
| expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("branch from base (non-fatal)")); | ||
| }); | ||
|
|
||
| it("should continue title/body updates when updateBranch gets workflows-permission 403", async () => { | ||
| const permissionError = new Error("refusing to allow a GitHub App to create or update workflow `.github/workflows/test.lock.yml` without `workflows` permission"); | ||
| permissionError.status = 403; | ||
| mockGithub.rest.pulls.updateBranch.mockRejectedValueOnce(permissionError); | ||
|
|
||
| const handler = await updatePRModule.main({ update_branch: true }); | ||
| const result = await handler({ | ||
| pull_request_number: 100, | ||
| title: "Updated PR", | ||
| }); | ||
|
|
||
| expect(result.success).toBe(true); | ||
| expect(mockGithub.rest.pulls.updateBranch).toHaveBeenCalledTimes(1); | ||
| expect(mockGithub.rest.pulls.update).toHaveBeenCalledWith({ | ||
| owner: "testowner", | ||
| repo: "testrepo", | ||
| pull_number: 100, | ||
| title: "Updated PR", | ||
| }); | ||
| expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("branch from base (non-fatal)")); | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The new test verifies the passing case but there's no negative/guard test confirming that a workflows-permission phrase alone (without the mutation-refusal or "update pull request" context) is still treated as fatal. This matters because the PR description explicitly calls out "scoped matching to avoid over-catching". A test like: it("should propagate error when workflows permission phrase appears without update-branch context", async () => {
mockGithub.rest.pulls.updateBranch.mockRejectedValueOnce(
new Error("missing `workflows` permission")
);
const handler = await updatePRModule.main({ update_branch: true });
const result = await handler({ pull_request_number: 100, title: "PR" });
expect(result.success).toBe(false);
});would lock down the guard condition and prevent accidental over-broadening in future edits. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose] The
iflag on this regex is redundant —messagewas already lowercased on the line above (getErrorMessage(error).toLowerCase()), so the flag has no effect. It is harmless but misleading; remove it for clarity: