name: PR Status Check

on:
    pull_request:
        types: [ opened, labeled, unlabeled, reopened, synchronize, ready_for_review ]
    pull_request_review:
        types: [ submitted, dismissed ]

jobs:
    check-status:
        runs-on: ubuntu-22.04

        steps:
            -   name: Check PR Status
                uses: actions/github-script@v8
                with:
                    script: |
                        const blockedLabels = ['Status: Blocked', 'Status: Abandoned'];
                        const labels = context.payload.pull_request.labels.map(label => label.name);

                        const hasBlockedLabel = blockedLabels.some(blockedLabel =>
                          labels.includes(blockedLabel)
                        );

                        if (hasBlockedLabel) {
                          core.setFailed(`This PR cannot be merged because it has a blocking status: "${
                            blockedLabels.filter(label => labels.includes(label)).join(', ')
                          }"`);
                        }
