name: Auto Label

on:
  pull_request_target:
    types: [opened, synchronize]

permissions: {}

jobs:
  label:
    runs-on: ubuntu-latest
    # Skip PRs targeting next (retargeted or direct) to avoid label explosion
    # from the large diff between next and feature branches.
    # Skip bot sync PRs (main→next) which touch many files but are purely devops.
    if: >
      github.repository_owner == 'better-auth' &&
      github.event.pull_request.base.ref != 'next' &&
      github.actor != 'better-release[bot]'
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Generate App Token
        id: app-token
        uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
        if: vars.RELEASE_APP_ID != ''
        with:
          app-id: ${{ vars.RELEASE_APP_ID }}
          private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}

      - uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
        with:
          repo-token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
          sync-labels: false
          dot: true
