name: OpenOSRS - Auto merge

on:
  pull_request_review:
    types:
      - submitted

jobs:
  automerge:
    name: Auto merge
    runs-on: ubuntu-latest

    steps:
      - name: automerge
        if: github.event_name == 'pull_request' && github.actor == 'Owain94'
        uses: pascalgn/automerge-action@v0.12.0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          MERGE_FORKS: false
          MERGE_LABELS: automated-pull-request

  cleanup:
    name: Cleanup
    needs: automerge
    runs-on: ubuntu-latest

    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo $(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH"))"
        id: extract_branch

      - name: Delete PR head branch
        if: github.event_name == 'pull_request' && github.actor == 'Owain94'
        uses: dawidd6/action-delete-branch@v3.0.2
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branches: ${{ steps.extract_branch.outputs.branch }}
