Skip to content

Commit

Permalink
fix(actions/create-and-merge-pull-request): wait for pull request to …
Browse files Browse the repository at this point in the history
…be mergeable before merging it
  • Loading branch information
neilime committed Mar 31, 2023
1 parent 4ecdf82 commit 6f5c545
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion actions/create-and-merge-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,35 @@ runs:
author: ${{ steps.github-actions-bot-user.outputs.name }} <${{ steps.github-actions-bot-user.outputs.email }}>
committer: ${{ steps.github-actions-bot-user.outputs.name }} <${{ steps.github-actions-bot-user.outputs.email }}>

- name: Merge pull request
- id: wait-for-pull-request-mergeable-by-admin
if: steps.create-pull-request.outputs.pull-request-number && steps.create-pull-request.outputs.pull-request-operation != 'closed'
uses: actions/github-script@v6
with:
script: |
let attemps = 0;
const maxAttemps = 10;
while (attemps < maxAttemps) {
const { data: { mergeable, mergeable_state } } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ steps.create-pull-request.outputs.pull-request-number }},
});
if (mergeable === true) {
core.setOutput('is-mergeable', true);
return;
}
core.debug(`Pull request is not mergeable, mergeable_state: ${mergeable_state}`);
await new Promise(resolve => setTimeout(resolve, 5000));
attemps++;
}
core.error('Pull request is not mergeable');
- name: Merge pull request
if: steps.wait-for-pull-request-mergeable-by-admin.outputs.is-mergeable
shell: bash
run: gh pr merge -R "${{ github.repository }}" --rebase --admin "${{ steps.create-pull-request.outputs.pull-request-number }}"
env:
Expand Down

0 comments on commit 6f5c545

Please sign in to comment.