Skip to content

Commit 8ff9dc6

Browse files
committed
Fix race condition in PR metadata check workflow
The workflow reads assignees, labels, and milestone from the event payload, which is a snapshot taken at trigger time. When a PR is opened, the `opened` event fires before labels/milestone/assignee are fully applied, causing the check to fail with stale data. Fix by fetching live PR data via `gh api` instead of relying on the event payload. The downstream validation logic is unchanged.
1 parent 8204668 commit 8ff9dc6

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

.github/workflows/pr-metadata-check.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
steps:
2626
- name: Check for assignee, labels, and milestone
2727
env:
28-
ASSIGNEES: ${{ toJson(github.event.pull_request.assignees) }}
29-
LABELS: ${{ toJson(github.event.pull_request.labels) }}
30-
MILESTONE: ${{ github.event.pull_request.milestone && github.event.pull_request.milestone.title || '' }}
3128
PR_URL: ${{ github.event.pull_request.html_url }}
29+
PR_NUMBER: ${{ github.event.pull_request.number }}
30+
GH_REPO: ${{ github.repository }}
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3232
IS_BOT: ${{ github.actor == 'dependabot[bot]' || github.actor == 'pre-commit-ci[bot]' || github.actor == 'copy-pr-bot[bot]' }}
3333
IS_DRAFT: ${{ github.event.pull_request.draft }}
3434
run: |
@@ -37,6 +37,13 @@ jobs:
3737
exit 0
3838
fi
3939
40+
# Fetch live PR data to avoid stale event payload (race condition
41+
# when labels/milestone are added shortly after PR creation).
42+
PR_JSON=$(gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}")
43+
ASSIGNEES=$(echo "$PR_JSON" | jq '.assignees')
44+
LABELS=$(echo "$PR_JSON" | jq '.labels')
45+
MILESTONE=$(echo "$PR_JSON" | jq -r '.milestone.title // empty')
46+
4047
ERRORS=""
4148
4249
ASSIGNEE_COUNT=$(echo "$ASSIGNEES" | jq 'length')

0 commit comments

Comments
 (0)