37 lines
1.3 KiB
Bash
37 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
# 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")
|
|
|
|
# Extract repository names
|
|
REPO_LIST=$(echo "$REPO_DATA" | jq -r '.[].name')
|
|
|
|
# Exit if no repositories found
|
|
if [[ -z "$REPO_LIST" ]]; then
|
|
echo "❌ No private repositories found or token is missing the 'repo' scope."
|
|
exit 1
|
|
fi
|
|
|
|
echo "🔍 Fetching collaborators for all private repositories..."
|
|
for REPO in $REPO_LIST; do
|
|
# Determine the actual owner (useful for org-owned repos)
|
|
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')
|
|
|
|
# Display collaborators or notify if none found
|
|
if [[ -z "$COLLABORATORS" ]]; then
|
|
echo "🚫 No collaborators found."
|
|
else
|
|
echo "👥 Collaborators:"
|
|
echo "$COLLABORATORS"
|
|
fi
|
|
|
|
echo "--------------------------------------------"
|
|
done
|