krabmaga 0.6.1

A modern developing art for reliable and efficient Agent-based Model (ABM) simulation with the Rust language.
Documentation
name: Manage PR and issue labels

on:
  pull_request_target:
    types: [opened, synchronize, reopened]
  issues:
    types: [opened, reopened, labeled, unlabeled]

jobs:
  label:
    if: github.event_name == 'pull_request_target'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - uses: actions/labeler@v6
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          configuration-path: .github/labeler.yml
          sync-labels: true

  assignees:
    if: github.event_name == 'pull_request_target' && (github.event.action == 'opened' || github.event.action == 'reopened')
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: write
      pull-requests: write
    steps:
      - uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            await github.rest.issues.addAssignees({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.payload.pull_request.number,
              assignees: [context.payload.pull_request.user.login]
            })

  validate-issue-labels:
    if: github.event_name == 'issues'
    runs-on: ubuntu-latest
    permissions:
      issues: write
    steps:
      - uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const requiredType = ["chore", "docs","feature", "fix", "refactoring"];

            const labels = (context.payload.issue.labels || []).map((l) => l.name);
            const hasType = labels.some((name) => requiredType.includes(name));

            if (!hasType) {
              await github.rest.issues.createComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.payload.issue.number,
                body: [
                  "This issue is missing a required label.",
                  "",
                  "Please add at least one of:",
                  `- ${requiredType.join("\n- ")}`,
                  "",
                  `Current labels: ${labels.length ? labels.join(", ") : "(none)"}`,
                ].join("\n"),
              });
              core.notice("Missing required issue labels. A comment was posted on the issue.");
            }