bytelyst-devops-tools/list_repos_contributors_by_user.sh

34 lines
1.1 KiB
Bash

#!/bin/bash
# Fetch all private repositories where you are an owner or collaborator
REPOS_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
REPOS=$(echo "$REPOS_DATA" | jq -r '.[].name')
if [[ -z "$REPOS" ]]; then
echo "❌ No private repositories found or token missing 'repo' scope."
exit 1
fi
echo "Fetching contributors and owners from all private repositories..."
for REPO in $REPOS; do
# Extract the repo owner (useful if it belongs to an org)
OWNER=$(echo "$REPOS_DATA" | jq -r --arg REPO "$REPO" '.[] | select(.name==$REPO) | .owner.login')
echo "🔍 Scanning $REPO (Owner: $OWNER)..."
# List contributors
CONTRIBUTORS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/contributors" | jq -r '.[].login')
if [[ -z "$CONTRIBUTORS" ]]; then
echo "🚫 No contributors found. (Owner: $OWNER)"
else
echo "📌 Owner: $OWNER"
echo "$CONTRIBUTORS"
fi
done