Performs the merge and returns whether it was successful or not.
(
validationConfig = {
assertCompletedReviews: !flags.ignorePendingReviews,
},
)
| 50 | |
| 51 | /** Performs the merge and returns whether it was successful or not. */ |
| 52 | async function performMerge( |
| 53 | validationConfig = { |
| 54 | assertCompletedReviews: !flags.ignorePendingReviews, |
| 55 | }, |
| 56 | ): Promise<boolean> { |
| 57 | try { |
| 58 | await tool.merge(prNumber, validationConfig); |
| 59 | return true; |
| 60 | } catch (e) { |
| 61 | // Catch errors to the Github API for invalid requests. We want to |
| 62 | // exit the script with a better explanation of the error. |
| 63 | if (isGithubApiError(e) && e.status === 401) { |
| 64 | Log.error('Github API request failed: ' + bold(e.message)); |
| 65 | Log.error('Please ensure that your provided token is valid.'); |
| 66 | Log.warn(`You can generate a token here: ${GITHUB_TOKEN_GENERATE_URL}`); |
| 67 | return false; |
| 68 | } |
| 69 | // Catch errors to the Github API for repository rule violations. We want to |
| 70 | // exit the script with a better explanation of the error. |
| 71 | if ( |
| 72 | isGithubApiError(e) && |
| 73 | e.status === 405 && |
| 74 | e.message.startsWith('Repository rule violations found') |
| 75 | ) { |
| 76 | Log.error(' ✘ Repository Rule Violation. This typically indicates that you are not'); |
| 77 | Log.error(' currently a member of the expected group for merge permissions in this'); |
| 78 | Log.error(' repository. Have you been placed in the expected caretaking group?'); |
| 79 | Log.debug('Github API request failed: ' + bold(e.message)); |
| 80 | return false; |
| 81 | } |
| 82 | if (isGithubApiError(e)) { |
| 83 | Log.error('Github API request failed: ' + bold(e.message)); |
| 84 | return false; |
| 85 | } |
| 86 | if (e instanceof UserAbortedMergeToolError) { |
| 87 | Log.warn('Manually aborted merging..'); |
| 88 | return false; |
| 89 | } |
| 90 | if (e instanceof InvalidTargetBranchError) { |
| 91 | Log.error(`Pull request selects an invalid GitHub destination branch:`); |
| 92 | Log.error(` -> ${bold(e.failureMessage)}`); |
| 93 | } |
| 94 | if (e instanceof InvalidTargetLabelError) { |
| 95 | Log.error(`Pull request target label could not be determined:`); |
| 96 | Log.error(` -> ${bold(e.failureMessage)}`); |
| 97 | } |
| 98 | |
| 99 | if (e instanceof PullRequestValidationError) { |
| 100 | Log.error('Pull request failed at least one validation check.'); |
| 101 | Log.error('See above for specific error information'); |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | // Note: Known errors in the merge tooling extend from the FatalMergeToolError, as such |
| 106 | // the instance check for FatalMergeToolError should remain last as it will be truthy for |
| 107 | // all of the subclasses. |
| 108 | if (e instanceof FatalMergeToolError) { |
| 109 | Log.error(`Could not merge the specified pull request. Error:`); |
no test coverage detected