name: Bug Report Triage

on:
  issues:
    types: [opened]

jobs:
  closeTemplateViolation:
    name: Validate bug report against issue template
    runs-on: ubuntu-latest
    if: contains(github.event.issue.labels.*.name, 'type:bug')
    steps:
      - name: Check "Description"
        if: |
          !contains(github.event.issue.body, env.MUST_CONTAIN)
          || contains(toJson(github.event.issue.body), env.MUST_NOT_CONTAIN)
        run: exit 1
        env:
          MUST_CONTAIN: '### Description'
          MUST_NOT_CONTAIN: '### Description\r\n\r\n[Summarize your problem.]\r\n\r\n### System Setup'
      - name: Check "Steps to Reproduce"
        if: |
          !contains(github.event.issue.body, env.MUST_CONTAIN)
          || contains(toJson(github.event.issue.body), env.MUST_NOT_CONTAIN)
        run: exit 1
        env:
          MUST_CONTAIN: '### Steps to Reproduce'
          MUST_NOT_CONTAIN: '### Steps to Reproduce\r\n\r\n1. [First step]\r\n2. [Second step]\r\n3. [and so on…]\r\n\r\n#### Expected Behavior'
      - name: Close issue if one of the checks failed
        if: ${{ failure() }}
        uses: peter-evans/close-issue@v1
        with:
          comment: |
            This bug report did ignore our issue template. 😞
            Auto-closing this issue, since it is most likely not useful.

            _This decision was made by a bot. If you think the bot is wrong, let us know and we'll reopen this issue._

