name: Validate Pull Request
on:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - labeled
      - unlabeled

jobs:
  required-labels-missing:
    name: required labels missing
    runs-on: ubuntu-latest
    steps:
      - name: check
        if: >-
          !contains(github.event.pull_request.labels.*.name, '💥 breaking-change')
          && !contains(github.event.pull_request.labels.*.name, '✨ enhancement')
          && !contains(github.event.pull_request.labels.*.name, '🐞 bug')
          && !contains(github.event.pull_request.labels.*.name, '📖 docs')
          && !contains(github.event.pull_request.labels.*.name, 'chore')
          && !contains(github.event.pull_request.labels.*.name, '🛠️ dependencies')
        run: >-
          echo One of the following labels is missing on this PR:
          breaking-change
          enhancement
          bug
          docs
          chore
          && exit 1
  title:
    name: check title prefix
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - name: check
        run: |
          PR_TITLE_PREFIX=$(echo "$PR_TITLE" | cut -d':' -f1)
          if [[ -d "internal/collector/$PR_TITLE_PREFIX" ]] || [[ -d "internal/$PR_TITLE_PREFIX" ]] || [[ -d "pkg/$PR_TITLE_PREFIX" ]] || [[ -d "$PR_TITLE_PREFIX" ]] || [[ "$PR_TITLE_PREFIX" == "docs" ]] || [[ "$PR_TITLE_PREFIX" == "ci" ]] || [[ "$PR_TITLE_PREFIX" == "revert" ]] || [[ "$PR_TITLE_PREFIX" == "fix" ]] || [[ "$PR_TITLE_PREFIX" == "fix(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "feat" ]] || [[ "$PR_TITLE_PREFIX" == "chore" ]] || [[ "$PR_TITLE_PREFIX" == "chore(docs)" ]] || [[ "$PR_TITLE_PREFIX" == "chore(deps)" ]] || [[ "$PR_TITLE_PREFIX" == "*" ]] || [[ "$PR_TITLE_PREFIX" == "Release"* ]] || [[ "$PR_TITLE_PREFIX" == "Synchronize common files from prometheus/prometheus" ]] || [[ "$PR_TITLE_PREFIX" == "[0."* ]] || [[ "$PR_TITLE_PREFIX" == "[1."* ]]; then
            exit 0
          fi

          echo "PR title must start with an name of an collector package"
          echo "Example: 'logical_disk: description'"
          exit 1
        env:
          PR_TITLE: ${{ github.event.pull_request.title }}
