diff --git a/.github/workflows/pr-metadata-check.yml b/.github/workflows/pr-metadata-check.yml index d8cf91579d..6f60ec45bf 100644 --- a/.github/workflows/pr-metadata-check.yml +++ b/.github/workflows/pr-metadata-check.yml @@ -25,10 +25,10 @@ jobs: steps: - name: Check for assignee, labels, and milestone env: - ASSIGNEES: ${{ toJson(github.event.pull_request.assignees) }} - LABELS: ${{ toJson(github.event.pull_request.labels) }} - MILESTONE: ${{ github.event.pull_request.milestone && github.event.pull_request.milestone.title || '' }} PR_URL: ${{ github.event.pull_request.html_url }} + PR_NUMBER: ${{ github.event.pull_request.number }} + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} IS_BOT: ${{ github.actor == 'dependabot[bot]' || github.actor == 'pre-commit-ci[bot]' || github.actor == 'copy-pr-bot[bot]' }} IS_DRAFT: ${{ github.event.pull_request.draft }} run: | @@ -37,6 +37,15 @@ jobs: exit 0 fi + # Fetch live PR data to avoid stale event payload (race condition + # when labels/milestone are added shortly after PR creation). + PR_JSON=$(gh pr view "${PR_NUMBER}" --repo "${GH_REPO}" \ + --json assignees,labels,milestone \ + --jq '{assignees: .assignees, labels: .labels, milestone: (.milestone.title // empty)}') + ASSIGNEES=$(echo "$PR_JSON" | jq '.assignees') + LABELS=$(echo "$PR_JSON" | jq '.labels') + MILESTONE=$(echo "$PR_JSON" | jq -r '.milestone') + ERRORS="" ASSIGNEE_COUNT=$(echo "$ASSIGNEES" | jq 'length')