name: Close issues

on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  close-issues:
    if: github.repository == 'withastro/astro'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false

      - name: Setup node
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: 24.18.0

      - name: Find stale issues
        id: find-stale
        run: echo "issues=$(node --experimental-strip-types .github/scripts/stale-issues.ts --token ${{ secrets.GITHUB_TOKEN }})" >> "$GITHUB_OUTPUT"

      - name: Close stale issues
        if: steps.find-stale.outputs.issues != '[]'
        env:
          GH_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
        run: |
          echo '${{ steps.find-stale.outputs.issues }}' | jq -r '.[]' | while read -r issue; do
            gh issue comment "$issue" --repo ${{ github.repository }} --body "This issue has been automatically closed because it has been inactive for more than 3 days and it does not have a minimal reproduction."
            gh issue close "$issue" --repo ${{ github.repository }} --reason "not planned"
            echo "Closed issue #$issue"
          done
