# Auto-applies the `needs-triage` label to any newly opened or reopened issue
# that has no labels yet. Keeps fresh issues from slipping past `/triage` and
# `/afk` (which only consumes `ready-for-agent`).
#
# Installed by `/red-setup`. Filename prefix `red-` marks it as belonging
# to the RedSkills ecosystem.

name: red-issues-needs-triage

on:
  issues:
    types: [opened, reopened]

permissions:
  issues: write

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v7
        with:
          script: |
            const issue = context.payload.issue;
            const labels = (issue.labels || []).map(l => l.name);
            if (labels.length > 0) {
              core.info(`Issue #${issue.number} already labelled (${labels.join(', ')}). Skipping.`);
              return;
            }
            await github.rest.issues.addLabels({
              owner: context.repo.owner,
              repo:  context.repo.repo,
              issue_number: issue.number,
              labels: ['needs-triage']
            });
            core.info(`Applied 'needs-triage' to #${issue.number}.`);
