name: Auto Approve
on: pull_request
jobs:
  auto-approve:
    runs-on: ubuntu-latest
    steps:
      - if: github.actor == 'shunkakinoki'
        uses: actions/github-script@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.pulls.createReview({
              pull_number: ${{ github.event.pull_request.number }},
              owner: context.repo.owner,
              repo: context.repo.repo,
              event: 'APPROVE',
            })
      - if: |
          github.actor == 'github-actions[bot]' ||
          github.actor == 'dependabot[bot]' ||
          github.actor == 'dependabot-preview[bot]' ||
          github.actor == 'imgbot' ||
          github.actor == 'imgbot[bot]'
        uses: actions/github-script@v2
        with:
          github-token: ${{ secrets.ACCESS_TOKEN }}
          script: |
            github.pulls.createReview({
              pull_number: ${{ github.event.pull_request.number }},
              owner: context.repo.owner,
              repo: context.repo.repo,
              event: 'APPROVE',
            })
      - if: contains(toJson(github.event.pull_request.title), '[sentrei-auto-pr]') == true
        uses: actions/github-script@v2
        with:
          github-token: ${{ secrets.ACCESS_TOKEN }}
          script: |
            github.issues.addLabels({
              issue_number: ${{ github.event.pull_request.number }},
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['sentrei-auto-pr'],
            })
