Skip to content

commit to test the PR label checker #2

commit to test the PR label checker

commit to test the PR label checker #2

# based on https://stackoverflow.com/a/75036059 and
# https://github.com/astropy/astropy/blob/main/.github/workflows/check_milestone.yml
name: Check PR title and labels
on:
# So it cannot be skipped.
pull_request_target:
types: [opened, edited, synchronize, labeled, unlabeled]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
if (/^\[?WIP\b/i.test(context.payload.pull_request.title)) {
core.setFailed("WIP pull requests can't be merged.");
}
check-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const requiredLabels = ['bug', 'enhancement', 'new feature', 'docs', 'infrastructure', 'dead code', 'refactor'];
let labels = context.payload.pull_request.labels;
core.info(`Current labels: ${labels.map(l => l.name).join(', ')}`);
if (labels.filter(l => requiredLabels.includes(l.name)).length === 0) {
core.setFailed('Please label this pull request with one of: bug, enhancement, new feature, docs or infrastructure.');
}