Skip to content

Commit

Permalink
fix: merge when pr is in mergeable state
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Dec 19, 2022
1 parent 369b7c9 commit b03bd10
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/events/pr-handlers/actions/enableGithubAutoMerge.ts
Expand Up @@ -33,6 +33,39 @@ export const enableGithubAutoMerge = async <
options,
});

if (
'mergeable_state' in pullRequest &&
(pullRequest.mergeable_state === 'clean' ||
pullRequest.mergeable_state === 'has_hooks' ||
pullRequest.mergeable_state === 'unstable')
) {
try {
await context.octokit.pulls.merge({
merge_method: 'squash',
owner: pullRequest.base.repo.owner.login,
repo: pullRequest.base.repo.name,
pull_number: pullRequest.number,
commit_title: commitHeadline,
commit_message: commitBody,
});
} catch (err) {
context.log.error(
'Could not automerge',
context.repo({
issue_number: pullRequest.number,
}),
err,
);
context.octokit.issues.createComment(
context.repo({
issue_number: pullRequest.number,
body: `${login ? `@${login} ` : ''}Could not automerge`,
}),
);
}
return null;
}

try {
/* Conditions:
Allow auto-merge enabled in settings.
Expand Down

0 comments on commit b03bd10

Please sign in to comment.