name: Feature Issue Check

on:
  issues:
    types: [ opened ]

jobs:
  auto-close:
    runs-on: ubuntu-latest
    permissions:
      issues: write

    steps:
      - name: Check and close feature issues
        uses: actions/github-script@v8
        with:
          script: |
            const issue = context.payload.issue;
            
            if (issue.title.startsWith('[FEAT]: ')) {
              const message = `
                Feature requests on this repository are only open to current [GitHub sponsors](https://github.com/sponsors/LGUG2Z) on the $5/month tier and above, people with a valid [individual commercial use license](https://lgug2z.com/software/komorebi), and approved contributors. 
            
                This issue has been automatically closed until one of those pre-requisites can be validated.
              `.replace(/^\s+/gm, ''); 
            
              await github.rest.issues.createComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: issue.number,
                body: message,
              });

              await github.rest.issues.update({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: issue.number,
                state: 'closed'
              });

              await github.rest.issues.lock({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: issue.number,
                state: 'resolved'
              });
            }