* @param {unknown} error * @returns {boolean}
(error)
| 24 | * @returns {boolean} |
| 25 | */ |
| 26 | function isNonFatalUpdateBranchError(error) { |
| 27 | /** @type {number | undefined} */ |
| 28 | let status; |
| 29 | if (typeof error === "object" && error !== null && "status" in error) { |
| 30 | const candidateStatus = error.status; |
| 31 | if (typeof candidateStatus === "number") { |
| 32 | status = candidateStatus; |
| 33 | } |
| 34 | } |
| 35 | const message = getErrorMessage(error).toLowerCase(); |
| 36 | const hasWorkflowsPermissionPhrase = /without\s+`?workflows`?\s+permission/i.test(message); |
| 37 | const hasWorkflowMutationRefusal = message.includes("refusing to allow a github app to create or update workflow"); |
| 38 | // Require both permission wording and update-branch context to avoid treating unrelated |
| 39 | // "workflows permission" errors as non-fatal for pull request branch updates. |
| 40 | const hasWorkflowsPermissionError = hasWorkflowsPermissionPhrase && (hasWorkflowMutationRefusal || message.includes("update pull request")); |
| 41 | |
| 42 | if (status !== undefined) { |
| 43 | if (status === 403 && hasWorkflowsPermissionError) { |
| 44 | return true; |
| 45 | } |
| 46 | if (status !== 422) { |
| 47 | return false; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // GitHub update-branch API can return these 422 messages for benign conditions: |
| 52 | // - already up to date ("There are no new commits on the base branch") |
| 53 | // - cannot auto-update due to conflict ("merge conflict between base and head") |
| 54 | // These should not fail safe output processing. |
| 55 | return message.includes("there are no new commits on the base branch") || message.includes("merge conflict between base and head") || hasWorkflowsPermissionError; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Execute the pull request update API call |
no test coverage detected