feat: delete users who are not part of whitelist

This commit is contained in:
Saravana Dhandapani 2025-02-08 22:34:31 -08:00
parent e2bc48c4cb
commit 63bb8fd9b4

View File

@ -16,7 +16,7 @@ if [[ -z "$REPO_LIST" ]]; then
exit 1
fi
echo "🔍 Fetching repositories with non-whitelisted collaborators..."
echo "🔍 Checking repositories for non-whitelisted collaborators..."
for REPO in $REPO_LIST; do
# 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')
@ -39,5 +39,24 @@ for REPO in $REPO_LIST; do
echo "❌ Non-Whitelisted Collaborators:"
printf '%s\n' "${NON_WHITELISTED_COLLABS[@]}"
echo "--------------------------------------------"
# Ask for confirmation and delete non-whitelisted collaborators
for USER in "${NON_WHITELISTED_COLLABS[@]}"; do
read -p "Do you want to remove collaborator '$USER' from '$REPO'? (yes/no): " CONFIRM
if [[ "$CONFIRM" == "yes" ]]; then
# API request to remove collaborator
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO/collaborators/$USER")
if [[ "$RESPONSE" -eq 204 ]]; then
echo "✅ Successfully removed $USER from $REPO."
else
echo "❌ Failed to remove $USER from $REPO (HTTP Status: $RESPONSE)"
fi
else
echo "🚫 Skipped removal of $USER from $REPO."
fi
done
echo "--------------------------------------------"
fi
done