name: Close feature requests with automated message

on:
  issues:
    types: [labeled]

jobs:
  needs-votes:
    if: ${{ github.event.label.name == 'feature' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions-ecosystem/action-add-labels@bd52874380e3909a1ac983768df6976535ece7f8 # v1.1.0
        with:
          labels: needs votes
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Add reactions
        uses: aidan-mundy/react-to-issue@109392cac5159c2df6c47c8ab3b5d6b708852fe5 # v1.1.2
        with:
          issue-number: ${{ github.event.issue.number }}
          reactions: '+1'
      - name: Create comment
        uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
        with:
          issue-number: ${{ github.event.issue.number }}
          body: |
            :sparkles: Thanks for sharing your idea! :sparkles:

            This repository uses a voting-based system for feature requests. While enhancement issues are automatically closed, we still welcome feature requests! The voting system helps us gauge community interest in potential features. We also encourage community contributions for any feature requests marked as needing votes (just post a comment first so we can help guide you toward a successful contribution).

            The enhancement backlog can be found here: https://github.com/actualbudget/actual/issues?q=label%3A%22needs+votes%22+sort%3Areactions-%2B1-desc+

            Don't forget to upvote the top comment with 👍!

            <!-- feature-auto-close-comment -->
      - name: Close Issue
        run: gh issue close "https://github.com/actualbudget/actual/issues/${{ github.event.issue.number }}"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
