bytelyst-devops-tools/list_all_public_repos.sh

40 lines
1.4 KiB
Bash

#!/bin/bash
# Load environment variables
GITHUB_TOKEN="${GITHUB_TOKEN:?❌ Error: GITHUB_TOKEN is not set in ~/.zshrc}"
echo "🔍 Fetching all public repositories owned by user..."
USER_PUBLIC_REPOS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/user/repos?per_page=100&type=public" | jq -r '.[].full_name')
if [[ -z "$USER_PUBLIC_REPOS" ]]; then
echo "❌ No public repositories found for user."
else
echo "📂 Public Repositories (User-Owned):"
echo "$USER_PUBLIC_REPOS"
echo "--------------------------------------------"
fi
echo "🔍 Fetching organizations..."
ORG_LIST=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/user/orgs" | jq -r '.[].login')
if [[ -z "$ORG_LIST" ]]; then
echo "❌ No organizations found for user."
exit 1
fi
echo "🔍 Fetching all public repositories under organizations..."
for ORG in $ORG_LIST; do
ORG_PUBLIC_REPOS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/orgs/$ORG/repos?per_page=100&type=public" | jq -r '.[].full_name')
if [[ -z "$ORG_PUBLIC_REPOS" ]]; then
echo "🚫 No public repositories found in organization: $ORG"
else
echo "📂 Public Repositories ($ORG):"
echo "$ORG_PUBLIC_REPOS"
fi
echo "--------------------------------------------"
done