name: Dependabot auto-merge

# Approves Dependabot PRs and enables GitHub auto-merge on them.
# The merge only happens once the branch ruleset's required "CI OK"
# check passes, so nothing lands without the full CI suite being green.

on: pull_request

permissions:
  contents: write
  pull-requests: write

jobs:
  automerge:
    name: Approve and enable auto-merge
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'jkfran/killport'
    steps:
      - name: Approve PR
        run: gh pr review --approve "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Enable auto-merge
        run: gh pr merge --auto --squash "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
