# yamllint disable rule:line-length
# shellcheck disable=SC2043
---
name: automerge
on:
  pull_request_review:
    types:
      - submitted
  issue_comment:
    types: created
  check_suite:
    types:
      - completed
  status: {}
jobs:
  labeler:
    runs-on: ubuntu-latest
    steps:
      - name: Add the automerge label
        if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/automerge') }}
        uses: actions/github-script@v4
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            github.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['automerge']
            })
  automerge:
    runs-on: ubuntu-latest
    needs: [labeler]
    steps:
      - id: automerge
        if: ${{ github.event.issue.pull_request }}
        name: automerge
        uses: "pascalgn/automerge-action@v0.16.2"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
