Skip to content

fix(ci): guard-prod uses author_association instead of org members API#10

Merged
luke-cf merged 1 commit into
mainfrom
fix/guard-prod-author-association
May 27, 2026
Merged

fix(ci): guard-prod uses author_association instead of org members API#10
luke-cf merged 1 commit into
mainfrom
fix/guard-prod-author-association

Conversation

@luke-cf

@luke-cf luke-cf commented May 27, 2026

Copy link
Copy Markdown
Contributor

Problem

guard-prod.yml calls `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

  • Merge this PR to main
  • Re-open PR main → prod; guard-prod should now allow it (luke-cf is OWNER)

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.
@luke-cf luke-cf merged commit 801bfd8 into main May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant