name: Watch Stale Issues
on:
  schedule:
    - cron: '0 9 * * *' # Run daily at 9am UTC
  workflow_dispatch: # Allows manual triggering from the Github UI

permissions:
  issues: write # Required to close issues and post comments
  contents: read # Needed by most GitHub Actions

jobs:
  close-inactive:
    runs-on: ubuntu-latest
    steps:
      - name: Watch stale issues
        uses: actions/stale@v10.2.0
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          ascending: true # Start with oldest issues first
          exempt-issue-labels: 'issue: security,severity: critical,severity: high,status: confirmed' # Don't close issues with any of these labels
          exempt-all-milestones: true # Don't close issues that are part of a milestone
          exempt-all-assignees: false # Close even if they are assigned
          days-before-stale: 90 # Mark as stale after 90 days of no activity
          days-before-close: 14 # Close 14 days after stale warning
          days-before-pr-stale: -1 # Don't apply to PRs
          days-before-pr-close: -1 # PRs disabled
          operations-per-run: 100
          stale-issue-message: |
            👋 Hello, and thank you for helping us to make Strapi better!

            This issue has had no activity for over **90 days**. As part of our effort to keep the issue tracker focused and manageable, we are reviewing older reports.

            To ensure we spend our limited resources effectively, we are prioritizing:
            - Active issues related to Strapi v5
            - High severity issues that have been confirmed
            - Issues with recent engagement
            - Issues that are not duplicates of others

            ⚠️ This issue will be automatically closed in **14 days** unless there is new activity.

            👉 If this is still relevant, please add a comment with any updates or context.

            Thank you for helping us improve Strapi! 🙏
          close-issue-message: |
            This issue has been closed due to inactivity as part of our backlog review.  

            If the problem is still relevant (especially in **Strapi v5**), please let us know or open a new issue. 
            We truly appreciate your input and contributions 💜
