feat: add whitelist

This commit is contained in:
Saravana Dhandapani 2025-02-08 22:13:47 -08:00
parent 3bd5260fc3
commit e2bc48c4cb

View File

@ -1,5 +1,8 @@
#!/bin/bash
# Define the whitelist of allowed collaborators
WHITELIST=("saravanakumardb" "saravanange" "abhinaisai2002" "sandho" "akshaj-us" "saravanakumardb1" "bytelyst-ai" "umadev0931")
# Fetch all private repositories where the user is an owner or collaborator
REPO_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/user/repos?per_page=100&affiliation=owner,collaborator&visibility=private")
@ -13,24 +16,28 @@ if [[ -z "$REPO_LIST" ]]; then
exit 1
fi
echo "🔍 Fetching collaborators for all private repositories..."
echo "🔍 Fetching repositories with non-whitelisted collaborators..."
for REPO in $REPO_LIST; do
# Determine the actual owner (useful for org-owned repos)
# Determine the actual owner (useful if it belongs to an org)
REPO_OWNER=$(echo "$REPO_DATA" | jq -r --arg REPO "$REPO" '.[] | select(.name==$REPO) | .owner.login')
echo "📂 Repository: $REPO (Owner: $REPO_OWNER)"
# Fetch all collaborators (includes users even if they haven't committed)
COLLABORATORS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO/collaborators" | jq -r '.[].login')
ALL_COLLABORATORS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO/collaborators" | jq -r '.[].login')
# Display collaborators or notify if none found
if [[ -z "$COLLABORATORS" ]]; then
echo "🚫 No collaborators found."
else
echo "👥 Collaborators:"
echo "$COLLABORATORS"
# Identify non-whitelisted collaborators
NON_WHITELISTED_COLLABS=()
for COLLAB in $ALL_COLLABORATORS; do
if [[ ! " ${WHITELIST[@]} " =~ " ${COLLAB} " ]]; then
NON_WHITELISTED_COLLABS+=("$COLLAB")
fi
done
# Only show repositories where non-whitelisted collaborators exist
if [[ ${#NON_WHITELISTED_COLLABS[@]} -gt 0 ]]; then
echo "🚨 Repository: $REPO (Owner: $REPO_OWNER)"
echo "❌ Non-Whitelisted Collaborators:"
printf '%s\n' "${NON_WHITELISTED_COLLABS[@]}"
echo "--------------------------------------------"
fi
echo "--------------------------------------------"
done