name: 🚪 Issues/PRs On Close Handler

on:
  issues:
    types: [closed]
  pull_request_target:
    types: [closed]

permissions:
  contents: read
  issues: write
  pull-requests: write

jobs:
  remove-labels:
    name: 🗑️ Remove Pending Labels on Close
    runs-on: ubuntu-latest
    if: always()

    steps:
      - name: Mint App Token
        id: app
        # Create a GitHub App token
        # https://github.com/marketplace/actions/create-github-app-token
        uses: actions/create-github-app-token@v2
        with:
          app-id: ${{ vars.ST_BOT_APP_ID }}
          private-key: ${{ secrets.ST_BOT_PRIVATE_KEY }}
          owner: ${{ github.repository_owner }}

      - name: Remove Pending Labels on Close
        # 🤖 Issues Helper
        # https://github.com/marketplace/actions/issues-helper
        uses: actions-cool/issues-helper@v3.6.0
        with:
          actions: remove-labels
          token: ${{ steps.app.outputs.token }}
          issue-number: ${{ github.event.issue.number || github.event.pull_request.number }}
          labels: '🚏 Awaiting User Response,🧑‍💻 In Progress,📌 Keep Open,🚫 Merge Conflicts,🔬 Needs Testing,🔨 Needs Work,⚰️ Stale,⛔ Waiting For External/Upstream'
