Skip to content

Commit de2286e

Browse files
committed
fix: use collaborator permission fallback for auth check
Team membership API only works for org repos. Fall back to collaborator write access check for personal repos.
1 parent fda8bef commit de2286e

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

.github/workflows/pr-ai-review.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,48 @@ jobs:
1919
ai-review:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- name: Check team membership
22+
- name: Check authorization
2323
id: auth
2424
if: github.event_name == 'pull_request'
2525
uses: actions/github-script@v8
2626
with:
2727
script: |
2828
const user = context.payload.pull_request.user.login;
29-
const org = context.repo.owner;
3029
try {
30+
// Try team membership first (works for org repos)
3131
await github.rest.teams.getMembershipForUserInOrg({
32-
org,
32+
org: context.repo.owner,
3333
team_slug: 'agentcore-cli-devs',
3434
username: user,
3535
});
3636
console.log(`${user} is a member of agentcore-cli-devs`);
3737
core.setOutput('authorized', 'true');
38-
} catch (error) {
39-
console.log(`${user} is not a member of agentcore-cli-devs (${error.status}) — skipping review`);
40-
core.setOutput('authorized', 'false');
38+
} catch (teamError) {
39+
// Fall back to collaborator write access (works for personal repos)
40+
try {
41+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
username: user,
45+
});
46+
const hasWriteAccess = ['write', 'admin'].includes(data.permission);
47+
if (hasWriteAccess) {
48+
console.log(`${user} has write access (${data.permission})`);
49+
core.setOutput('authorized', 'true');
50+
} else {
51+
console.log(`${user} does not have write access (${data.permission}) — skipping review`);
52+
core.setOutput('authorized', 'false');
53+
}
54+
} catch (collabError) {
55+
console.log(`${user} authorization check failed (${collabError.status}) — skipping review`);
56+
core.setOutput('authorized', 'false');
57+
}
4158
}
4259
4360
- name: Skip if not authorized
4461
if: github.event_name == 'pull_request' && steps.auth.outputs.authorized != 'true'
4562
run: |
46-
echo "PR author is not in agentcore-cli-devs team. Skipping AI review."
63+
echo "PR author is not authorized. Skipping AI review."
4764
exit 0
4865
4966
- name: Determine PR URL

0 commit comments

Comments
 (0)