name: Auto-label issues

on:
  issues:
    types: [opened]

permissions:
  contents: read
  issues: write

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: stefanbuck/github-issue-parser@v3
        id: issue-parser
        with:
          template-path: .github/ISSUE_TEMPLATE/bug_report.yml

      - uses: redhat-plumbers-in-action/advanced-issue-labeler@v3
        with:
          issue-form: ${{ steps.issue-parser.outputs.jsonString }}
          section: component
          token: ${{ secrets.GITHUB_TOKEN }}
          config-path: .github/advanced-issue-labeler.yml

      - uses: stefanbuck/github-issue-parser@v3
        id: feature-parser
        if: contains(github.event.issue.labels.*.name, 'enhancement')
        with:
          template-path: .github/ISSUE_TEMPLATE/feature_request.yml

      - uses: redhat-plumbers-in-action/advanced-issue-labeler@v3
        if: contains(github.event.issue.labels.*.name, 'enhancement')
        with:
          issue-form: ${{ steps.feature-parser.outputs.jsonString }}
          section: component
          token: ${{ secrets.GITHUB_TOKEN }}
          config-path: .github/advanced-issue-labeler.yml
