fix(ci): guard-prod uses author_association instead of org members API#10
Merged
Conversation
Previous implementation called gh api orgs/<org>/members/<user> with the workflow's GITHUB_TOKEN. The token authenticates as github-actions[bot] which is NOT an org member, so the API returns 404 for members whose membership is private - the script read that as "external contributor" and closed the PR. Symptom: PR main → prod opened by an admin/maintainer was auto-closed with the "PRs to prod are restricted to org members" comment. push:prod events were unaffected because guard-prod only runs on pull_request_target. Fix: use github.event.pull_request.author_association which GitHub already computes server-side per event. Values OWNER, MEMBER, COLLABORATOR allow the PR; anything else (CONTRIBUTOR / FIRST_TIME_CONTRIBUTOR / NONE) closes it. No extra API call, no token scope dependency, no private-membership false negatives.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
guard-prod.ymlcalls `gh api orgs//members/` with workflow GITHUB_TOKEN. That token runs as `github-actions[bot]` (not an org member), so the API returns 404 for org members whose membership is private — script then reads "external contributor" and closes the PR.Repro
Opened PR #9 (main → prod) as @luke-cf (org admin). guard-prod closed it with "PRs to prod are restricted to org members."
Fix
Use `github.event.pull_request.author_association` — GitHub computes it server-side per event, no extra API call needed, no token-scope dependency.
`OWNER` / `MEMBER` / `COLLABORATOR` → PR allowed.
Anything else (`CONTRIBUTOR`, `FIRST_TIME_CONTRIBUTOR`, `NONE`) → PR closed.
Test plan