name: Auto Merge PR
on:
  pull_request_target:
    types: [opened, reopened, auto_merge_disabled, ready_for_review]

permissions: {}

jobs:
  build:
    if: |
      github.event.pull_request.state == 'open' &&
      !github.event.pull_request.draft &&
      (contains(github.event.pull_request.base.ref, 'development') || contains(github.event.pull_request.base.ref, 'RC'))
    runs-on: ubuntu-slim

    permissions:
      contents: write

    steps:
    - name: Auto Merge PR
      shell: bash
      env:
        GH_TOKEN: ${{ secrets.PUSH_TOKEN }}
        PR_URL: ${{ github.event.pull_request.html_url }}
      run: gh pr merge "$PR_URL" --auto --squash
