#
# This workflow is used to asign labels to issues created through the templates. 
# There is another file associated that maps a issue label name to each field on the 
# issue template. You can find that file in /.github/advanced-issue-labeler.yml 
#
# More info: https://github.com/marketplace/actions/advanced-issue-labeler
#

name: Issue labeler
on:
  issues:
    types: [ opened ]

permissions:
  contents: read

jobs:
  label-component:
    runs-on: ubuntu-latest

    permissions:
      # required for all workflows
      issues: write

    strategy:
      matrix:
        template: [ bug_report.yml, feature_request.yml ]

    steps:
      - uses: actions/checkout@v3

      - name: Parse issue form
        uses: stefanbuck/github-issue-parser@v3
        id: issue-parser
        with:
          template-path: .github/ISSUE_TEMPLATE/${{ matrix.template }}

      - name: Set labels based on policy
        uses: redhat-plumbers-in-action/advanced-issue-labeler@v2
        with:
          issue-form: ${{ steps.issue-parser.outputs.jsonString }}
          template: ${{ matrix.template }}
          token: ${{ secrets.GITHUB_TOKEN }}
