name: PR Title Lint

on:
  pull_request:
    types: [opened, edited, synchronize]

jobs:
  pr-title:
    runs-on: ubuntu-latest
    steps:
      - name: Check PR title
        run: |
          title="$(jq -r '.pull_request.title' < "$GITHUB_EVENT_PATH")"
          if ! grep -Eq '^(feat|fix|docs|chore|refactor|test)(\(.+\))?: .+' <<<"$title"; then
            echo "PR title must follow Conventional Commits. Got: $title"
            exit 1
          fi
