Skip to content

Commit 42ba89b

Browse files
committed
chore: update action bot to check repository collaborator permissions instead of team membership.
1 parent 97c689d commit 42ba89b

1 file changed

Lines changed: 19 additions & 30 deletions

File tree

.github/workflows/action_bot.yaml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Bot command handler for CI permissions.
2-
# Authorized users (ci-users team) can comment to control CI:
2+
# Repository collaborators can comment to control CI:
33
# @xllm-bot run - Add run-ci label to trigger CI
44
# @xllm-bot rerun - Cancel and rerun all workflows
55
# @xllm-bot rerun failed - Rerun failed and cancelled jobs
@@ -25,42 +25,31 @@ jobs:
2525
runs-on: ubuntu-latest
2626

2727
steps:
28-
- name: Check team membership
28+
- name: Check collaborator permission
2929
id: check-permission
3030
env:
31-
GH_TOKEN: ${{ secrets.XLLM_GITHUB_TOKEN || secrets.XLLM_BOT_TOKEN }}
32-
ORG: ${{ github.repository_owner }}
33-
TEAM: ci-users
31+
GH_TOKEN: ${{ github.token }}
32+
REPO: ${{ github.repository }}
3433
ACTOR: ${{ github.event.comment.user.login }}
3534
run: |
36-
echo "Checking if $ACTOR is a member of $ORG/$TEAM..."
35+
echo "Checking if $ACTOR is a collaborator on $REPO..."
3736
38-
# Verify token is set.
39-
if [[ -z "$GH_TOKEN" ]]; then
40-
echo "::error::XLLM_GITHUB_TOKEN or XLLM_BOT_TOKEN secret is not set"
41-
echo "authorized=false" >> "$GITHUB_OUTPUT"
42-
exit 0
43-
fi
44-
45-
# List team members and check if commenter is in the list.
46-
MEMBERS=$(gh api \
37+
PERMISSION=$(gh api \
4738
-H "Accept: application/vnd.github+json" \
4839
-H "X-GitHub-Api-Version: 2022-11-28" \
49-
--paginate \
50-
"/orgs/${ORG}/teams/${TEAM}/members" \
51-
--jq '.[].login' 2>&1) || {
52-
echo "::error::Failed to get team members: $MEMBERS"
53-
echo "authorized=false" >> "$GITHUB_OUTPUT"
54-
exit 0
55-
}
56-
57-
if echo "$MEMBERS" | grep -qx "$ACTOR"; then
58-
echo "$ACTOR is a member of $TEAM"
59-
echo "authorized=true" >> "$GITHUB_OUTPUT"
60-
else
61-
echo "$ACTOR is not a member of $TEAM"
62-
echo "authorized=false" >> "$GITHUB_OUTPUT"
63-
fi
40+
"/repos/${REPO}/collaborators/${ACTOR}/permission" \
41+
--jq '.permission' 2>/dev/null || true)
42+
43+
case "$PERMISSION" in
44+
admin|maintain|write|triage|read)
45+
echo "$ACTOR is authorized with $PERMISSION permission"
46+
echo "authorized=true" >> "$GITHUB_OUTPUT"
47+
;;
48+
*)
49+
echo "$ACTOR is not a collaborator. Repository permission: ${PERMISSION:-none}"
50+
echo "authorized=false" >> "$GITHUB_OUTPUT"
51+
;;
52+
esac
6453
6554
- name: Parse command
6655
id: parse

0 commit comments

Comments
 (0)