---
name: "Dependabot merge"

on:
  pull_request:

permissions:
  contents: read

jobs:
  dependabot:
    name: "Dependabot merge"
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]'
    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: "Fetch dependabot metadata"
        uses: dependabot/fetch-metadata@v3
        with:
          github-token: ${{ github.token }}

      - name: "Approve and auto merge"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ github.token }}
        run: |
          gh pr review --approve "$PR_URL"
          gh pr merge --squash --auto "$PR_URL"
