name: Dependabot Auto Merge

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

permissions:
  contents: write
  pull-requests: write

concurrency:
  group: dependabot-auto-merge-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  merge:
    if: >
      github.actor == 'dependabot[bot]' &&
      github.event.pull_request.user.login == 'dependabot[bot]' &&
      contains(github.event.pull_request.labels.*.name, 'dependencies')
    name: Dependabot Auto Merge
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Enable auto-merge
        env:
          GH_TOKEN: ${{ github.token }}
          PR_URL: ${{ github.event.pull_request.html_url }}
        run: gh pr merge "$PR_URL" --auto --merge
