Skip to content

Commit dffb348

Browse files
johntmyerslinuxdevel
authored andcommitted
fix(ci): check author_association before API calls in vouch gate (NVIDIA#442)
The vouch-check workflow was closing PRs from NVIDIA org members because the GITHUB_TOKEN lacks read:org scope, causing orgs.checkMembershipForUser to return 404 for non-public members. The catch block silently swallowed these as expected 'not found' responses. Add an author_association check from the webhook payload as the primary bypass. GitHub sets this field server-side (MEMBER, OWNER, COLLABORATOR) regardless of membership visibility, with no extra token permissions needed. The existing API calls are kept as fallbacks. Fixes the false positive that closed NVIDIA#430. Co-authored-by: John Myers <johntmyers@users.noreply.github.com>
1 parent 890a19f commit dffb348

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

.github/workflows/vouch-check.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,33 @@ jobs:
1919
script: |
2020
const author = context.payload.pull_request.user.login;
2121
const authorType = context.payload.pull_request.user.type;
22+
const authorAssociation = context.payload.pull_request.author_association;
2223
2324
// Skip bots (dependabot, renovate, github-actions, etc.).
2425
if (authorType === 'Bot') {
2526
console.log(`${author} is a bot. Skipping vouch check.`);
2627
return;
2728
}
2829
30+
// Check author_association from the webhook payload. This is set by
31+
// GitHub itself and doesn't require extra token permissions, so it
32+
// works reliably for org members even when their membership is private.
33+
const trustedAssociations = ['MEMBER', 'OWNER', 'COLLABORATOR'];
34+
if (trustedAssociations.includes(authorAssociation)) {
35+
console.log(`${author} has author_association=${authorAssociation}. Skipping vouch check.`);
36+
return;
37+
}
38+
39+
// Fallback: explicit API checks in case author_association is unexpected.
40+
2941
// Check org membership — members bypass the vouch gate.
3042
try {
3143
const { status } = await github.rest.orgs.checkMembershipForUser({
3244
org: context.repo.owner,
3345
username: author,
3446
});
3547
if (status === 204 || status === 302) {
36-
console.log(`${author} is an org member. Skipping vouch check.`);
48+
console.log(`${author} is an org member (API). Skipping vouch check.`);
3749
return;
3850
}
3951
} catch (e) {
@@ -50,7 +62,7 @@ jobs:
5062
username: author,
5163
});
5264
if (status === 204) {
53-
console.log(`${author} is a collaborator. Skipping vouch check.`);
65+
console.log(`${author} is a collaborator (API). Skipping vouch check.`);
5466
return;
5567
}
5668
} catch (e) {

0 commit comments

Comments
 (0)