* @param {{ pullRequestId: number, base: string }} param0 * @returns {Promise }
({ pullRequestId, mergeMode, mergeMessage, base })
| 482 | * @returns {Promise<void>} |
| 483 | */ |
| 484 | async prAutoMerge({ pullRequestId, mergeMode, mergeMessage, base }) { |
| 485 | const octo = octokit(this.token, this.repo); |
| 486 | const graphql = withCustomRequest(octo.request); |
| 487 | const { owner, repo } = this.ownerRepo(); |
| 488 | const [commitHeadline, commitBody] = mergeMessage |
| 489 | ? mergeMessage.split(/\n\n(.*)/s) |
| 490 | : []; |
| 491 | const { |
| 492 | data: { node_id: nodeId } |
| 493 | } = await octo.pulls.get({ owner, repo, pull_number: pullRequestId }); |
| 494 | try { |
| 495 | await graphql( |
| 496 | ` |
| 497 | mutation autoMerge( |
| 498 | $pullRequestId: ID! |
| 499 | $mergeMethod: PullRequestMergeMethod |
| 500 | $commitHeadline: String |
| 501 | $commitBody: String |
| 502 | ) { |
| 503 | enablePullRequestAutoMerge( |
| 504 | input: { |
| 505 | pullRequestId: $pullRequestId |
| 506 | mergeMethod: $mergeMethod |
| 507 | commitHeadline: $commitHeadline |
| 508 | commitBody: $commitBody |
| 509 | } |
| 510 | ) { |
| 511 | clientMutationId |
| 512 | } |
| 513 | } |
| 514 | `, |
| 515 | { |
| 516 | pullRequestId: nodeId, |
| 517 | mergeMethod: mergeMode.toUpperCase(), |
| 518 | commitHeadline, |
| 519 | commitBody |
| 520 | } |
| 521 | ); |
| 522 | } catch (err) { |
| 523 | const tolerate = [ |
| 524 | "Can't enable auto-merge for this pull request", |
| 525 | 'Pull request Protected branch rules not configured for this branch', |
| 526 | 'Pull request is in clean status' |
| 527 | ]; |
| 528 | |
| 529 | if (!tolerate.some((message) => err.message.includes(message))) throw err; |
| 530 | |
| 531 | const settingsUrl = `https://github.com/${owner}/${repo}/settings`; |
| 532 | |
| 533 | try { |
| 534 | if (await this.isProtected({ branch: base })) { |
| 535 | logger.warn( |
| 536 | `Failed to enable auto-merge: Enable the feature in your repository settings: ${settingsUrl}#merge_types_auto_merge. Trying to merge immediately...` |
| 537 | ); |
| 538 | } else { |
| 539 | logger.warn( |
| 540 | `Failed to enable auto-merge: Set up branch protection and add "required status checks" for branch '${base}': ${settingsUrl}/branches. Trying to merge immediately...` |
| 541 | ); |
no test coverage detected