name: Dependabot Automerge

on:
  pull_request_target:
    types: [opened, synchronize, reopened]

permissions:
  pull-requests: write
  contents: write
  checks: read

jobs:
  dependabot-automerge:
    name: Dependabot Automerge
    if: github.repository == 'zhom/donutbrowser' && github.actor == 'dependabot[bot]'
    runs-on: ubuntu-latest
    # Never execute pull-request code in this privileged workflow. Auto-merge
    # remains gated by the unprivileged PR checks and branch protection.
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 #v3.1.0
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      - name: Enable auto-merge for minor and patch updates
        if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
        run: gh pr merge --auto --squash "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    timeout-minutes: 10
