name: PR milestone check
on:
  pull_request:
    types:
      - opened
      - synchronize
      - milestoned
      - demilestoned

permissions:
  contents: read
  pull-requests: read

jobs:
  milestone:
    runs-on: ubuntu-24.04
    steps:
      - name: Ensure PR has an open milestone
        uses: actions/github-script@v8
        with:
          script: |
            const pr = context.payload.pull_request;
            if (!pr) {
              core.setFailed("This workflow only runs on pull_request events.");
              return;
            }

            const milestone = pr.milestone;
            if (!milestone) {
              core.setFailed("PR must have a milestone assigned.");
              return;
            }

            if (milestone.state !== "open") {
              core.setFailed(`PR milestone "${milestone.title}" is ${milestone.state}.`);
            }
