feat: colloborators
This commit is contained in:
parent
fe40d1be7f
commit
3bd5260fc3
@ -1,33 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Fetch all private repositories where you are an owner or collaborator
|
||||
REPOS_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
|
||||
# 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
|
||||
REPOS=$(echo "$REPOS_DATA" | jq -r '.[].name')
|
||||
REPO_LIST=$(echo "$REPO_DATA" | jq -r '.[].name')
|
||||
|
||||
if [[ -z "$REPOS" ]]; then
|
||||
echo "❌ No private repositories found or token missing 'repo' scope."
|
||||
# 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 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 "🔍 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 "🔍 Scanning $REPO (Owner: $OWNER)..."
|
||||
echo "📂 Repository: $REPO (Owner: $REPO_OWNER)"
|
||||
|
||||
# List contributors
|
||||
CONTRIBUTORS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
|
||||
"https://api.github.com/repos/$OWNER/$REPO/contributors" | jq -r '.[].login')
|
||||
# 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')
|
||||
|
||||
if [[ -z "$CONTRIBUTORS" ]]; then
|
||||
echo "🚫 No contributors found. (Owner: $OWNER)"
|
||||
# Display collaborators or notify if none found
|
||||
if [[ -z "$COLLABORATORS" ]]; then
|
||||
echo "🚫 No collaborators found."
|
||||
else
|
||||
echo "📌 Owner: $OWNER"
|
||||
echo "$CONTRIBUTORS"
|
||||
echo "👥 Collaborators:"
|
||||
echo "$COLLABORATORS"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "--------------------------------------------"
|
||||
done
|
||||
|
||||
Loading…
Reference in New Issue
Block a user