name: Label Issues by Installation Type

on:
  issues:
    types: [opened]

permissions:
  issues: write

jobs:
  add-label:
    runs-on: ubuntu-latest
    steps:
      - name: Get issue content
        uses: actions/github-script@v7
        with:
          script: |
            const body = context.payload.issue.body;

            const lowerBody = body.toLowerCase();

            let labelsToAdd = [];

            if (lowerBody.includes('bare-metal')) {
              labelsToAdd.push('bare-metal ❗');
            }

            if (lowerBody.includes('home assistant')) {
              labelsToAdd.push('Home Assistant 🏠');
            }

            if (lowerBody.includes('production (netalertx)') || lowerBody.includes('dev (netalertx-dev)')) {
              labelsToAdd.push('Docker 🐋');
            }

            if (labelsToAdd.length > 0) {
              await github.rest.issues.addLabels({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.issue.number,
                labels: labelsToAdd
              });
            }
