name: Issue Labeled

on:
  issues:
    types: [labeled]
  # zizmor: ignore[dangerous-triggers]
  # We don't use any information from the PR content itself except the login of the user.
  # The login is used only in the GitHub comment, not passed down as untrusted code.
  pull_request_target:
    types: [labeled]

permissions: {}

concurrency:
  group: ${{ github.workflow }}-${{ github.event.issue.number || github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  reproduction-reply-labeled:
    runs-on: ubuntu-slim
    if: github.repository == 'vitest-dev/vitest' && github.event.label.name == 'needs reproduction'
    name: Minimal Reproduction Label
    permissions:
      contents: read # to check out the repo for local actions
      issues: write # adding a label
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
          ref: main
      - name: needs reproduction
        uses: ./.github/actions/issues-helper
        with:
          actions: create-comment
          token: ${{ secrets.GITHUB_TOKEN }}
          issue-number: ${{ github.event.issue.number }}
          body: |
            Hello @${{ github.event.issue.user.login }}. Please provide a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) using a GitHub repository or [StackBlitz](https://vitest.new) (you can also use [examples](https://github.com/vitest-dev/vitest/tree/main/examples)). Issues marked with `needs reproduction` will be closed if they have no activity within 3 days.

  issue-clanker-comment:
    runs-on: ubuntu-slim
    if: github.repository == 'vitest-dev/vitest' && github.event.label.name == 'maybe automated' && github.event_name == 'issues'
    name: Comment on Bot Issue
    permissions:
      contents: read # to check out the repo for local actions
      issues: write # sending a comment
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
          ref: main
      - name: maybe automated
        uses: ./.github/actions/issues-helper
        with:
          actions: create-comment
          token: ${{ secrets.GITHUB_TOKEN }}
          issue-number: ${{ github.event.issue.number }}
          body: |
            Hello @${{ github.event.issue.user.login }}. Your issue has been labeled `maybe automated` because it appears to have been fully generated by AI with no human involvement. It will be **closed automatically in 3 days** unless a real person responds.

            If you're a real person behind this contribution, please:
            - Confirm you've personally reviewed and stand behind its content
            - Make sure it follows our [contribution guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md) and uses the correct [GitHub template](https://github.com/vitest-dev/vitest/blob/main/.github/ISSUE_TEMPLATE/bug_report.yml)
            - Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

            If you believe this was flagged by mistake, leave a comment.

            *These measures help us reduce maintenance burden and keep the team's work efficient. See our [AI contributions policy](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md#ai-contributions) for more context.*

  pr-clanker-comment:
    runs-on: ubuntu-slim
    if: github.repository == 'vitest-dev/vitest' && github.event.label.name == 'maybe automated' && github.event_name == 'pull_request_target'
    name: Comment on Bot PR
    permissions:
      contents: read # to check out the repo for local actions
      pull-requests: write # sending a comment
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false
          ref: main
      - uses: ./.github/actions/send-ai-bot-comment
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          pr-number: ${{ github.event.pull_request.number }}
          login: ${{ github.event.pull_request.user.login }}
