| name: Check PR body for changelog convention | |
| on: | |
| merge_group: | |
| pull_request_target: | |
| types: [opened, synchronize, reopened, edited, labeled, unlabeled, converted_to_draft, ready_for_review] | |
| permissions: | |
| pull-requests: read | |
| jobs: | |
| check-pr-body: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check PR body | |
| if: github.event_name == 'pull_request_target' | |
| uses: actions/github-script@v9 | |
| with: | |
| # Safety note: this uses pull_request_target, so the workflow has elevated privileges. | |
| # The PR title and body are only used in regex tests (read-only string matching), | |
| # never interpolated into shell commands, eval'd, or written to GITHUB_ENV/GITHUB_OUTPUT. | |
| script: | | |
| const { title, body, labels, draft } = context.payload.pull_request; | |
| const changelogLabels = labels.filter(label => label.name.startsWith("changelog-")); | |
| if (changelogLabels.length > 1) { | |
| core.setFailed('PR must not have more than one `changelog-*` label (found: ' + changelogLabels.map(label => label.name).join(', ') + ')'); | |
| } | |
| if (!draft && /^(feat|fix):/.test(title) && !labels.some(label => label.name == "changelog-no")) { | |
| if (changelogLabels.length === 0) { | |
| core.setFailed('feat/fix PR must have a `changelog-*` label'); | |
| } | |
| if (!/^This PR [^<]/.test(body)) { | |
| core.setFailed('feat/fix PR must have changelog summary starting with "This PR ..." as first line.'); | |
| } | |
| } |