name: Process a newly opened issue

env:
  TRUSTED_USERS: 'RodolfoGS awinograd hesyifei LinusU SimenB actuallymentor derekstavis wscotten wcandillon tevonsb MaRaSu devashishsethia bndkt'

on:
  issues:
    types: [opened]

jobs:
  check-if-trusted:
    runs-on: ubuntu-22.04
    steps:
      - uses: 8398a7/action-slack@v3.8.0
        if: ${{ contains( env.TRUSTED_USERS, github.event.issue.user.login ) }}
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.slack_webhook_expo_support }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          status: ${{ job.status }}
          channel: '#support'
          text: 'This issue should be triaged ASAP: ${{ github.event.issue.html_url }}'
          author_name: ${{ github.event.issue.user.login }}
          fields: repo
      - uses: actions/github-script@v6
        if: ${{ contains( env.TRUSTED_USERS, github.event.issue.user.login ) }}
        with:
          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
          script: |
            github.rest.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['!']
            })

  validate:
    runs-on: ubuntu-22.04
    steps:
      - name: 👀 Checkout
        uses: actions/checkout@v3
      - name: ➕ Add `bin` to GITHUB_PATH
        run: echo "$(pwd)/bin" >> $GITHUB_PATH
      - name: ♻️ Restore caches
        uses: ./.github/actions/expo-caches
        id: expo-caches
        with:
          yarn-tools: 'true'
      - name: 🔎 Validate issue complies with requirements
        run: expotools validate-issue --issue "${{ github.event.issue.number }}"
        env:
          GITHUB_TOKEN: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
