name: "Labeler"

on:
  issues:
    types: [opened, edited]
  pull_request_target:
    types: [opened, edited]

jobs:
  triage:
    if: >
      ${{ github.event_name == 'issues'
          || (!startsWith(github.event.pull_request.title, 'chore(deps):')
              && !contains(fromJSON('["chore/sync-gomod2nix","chore/update-flake-lock","update-screenshots","update-demo-gif"]'), github.head_ref)) }}
    permissions:
      contents: read
      issues: write
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - name: Apply Labels (issues — includes area/*)
        if: github.event_name == 'issues'
        uses: github/issue-labeler@v3.4
        with:
          repo-token: "${{ secrets.HOMEBREW_GITHUB_TOKEN }}"
          configuration-path: .github/labeler-config.yml
          enable-versioned-regex: 0
          include-title: 1

      - name: Apply Labels (PRs — no area/*, paths handle those)
        if: github.event_name == 'pull_request_target'
        uses: github/issue-labeler@v3.4
        with:
          repo-token: "${{ secrets.HOMEBREW_GITHUB_TOKEN }}"
          configuration-path: .github/labeler-config-pr.yml
          enable-versioned-regex: 0
          include-title: 1
