name: Ensure changelog

on:
  pull_request:
    types: [labeled, unlabeled, opened, synchronize, reopened]

jobs:
  ensure_changelog:
    name: Verify that a changelog entry exists for this pull request
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2
        with:
          submodules: true
      - run: grep -P '\[[^\]]*#${{github.event.number}}[,\]]' CHANGES.rst
        if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-changelog-entry-needed') }}
