name: 📨 Issues/PRs Open Handler

on:
  issues:
    types: [opened]
  pull_request_target:
    types: [opened]

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

jobs:
  label-maintainer:
    name: 🏷️ Label if Author is a Repo Maintainer
    runs-on: ubuntu-latest
    if: always() && contains(fromJson('["Cohee1207", "RossAscends", "Wolfsblvt"]'), github.actor)

    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: Label if Author is a Repo Maintainer
        # 🤖 Issues Helper
        # https://github.com/marketplace/actions/issues-helper
        uses: actions-cool/issues-helper@v3.6.0
        with:
          actions: 'add-labels'
          token: ${{ steps.app.outputs.token }}
          issue-number: ${{ github.event.issue.number || github.event.pull_request.number }}
          labels: '👷 Maintainer'
