MCPcopy Create free account
hub / github.com/angular/dev-infra / mergePullRequest

Function mergePullRequest

ng-dev/pr/merge/merge-pull-request.ts:38–118  ·  view source on GitHub ↗
(prNumber: number, flags: PullRequestMergeFlags)

Source from the content-addressed store, hash-verified

36 * @param flags Configuration options for merging pull requests.
37 */
38export async function mergePullRequest(prNumber: number, flags: PullRequestMergeFlags) {
39 // Set the environment variable to skip all git commit hooks triggered by husky. We are unable to
40 // rely on `--no-verify` as some hooks still run, notably the `prepare-commit-msg` hook.
41 process.env['HUSKY'] = '0';
42
43 const tool = await createPullRequestMergeTool(flags);
44
45 // Perform the merge. If the merge fails with non-fatal failures, the script
46 // will prompt whether it should rerun in force mode with the ignored failure.
47 if (!(await performMerge())) {
48 process.exit(1);
49 }
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:`);

Callers 1

handlerFunction · 0.85

Calls 2

performMergeFunction · 0.85

Tested by

no test coverage detected