Skip to content

Instantly share code, notes, and snippets.

@bauerpl
Created September 18, 2023 18:18
Show Gist options
  • Save bauerpl/39a84d519903a28e4cefeb07f0c4d6fe to your computer and use it in GitHub Desktop.
Save bauerpl/39a84d519903a28e4cefeb07f0c4d6fe to your computer and use it in GitHub Desktop.
This script is designed to audit and display repository access for specified GitHub users across multiple GitHub organizations.
# Define the users and organizations arrays
USERS=()
ORG_NAMES=()
# Loop through organizations
for ORG in "${ORG_NAMES[@]}"; do
echo "Checking organization: $ORG"
# Fetch all repositories in the current organization
REPOS=($(gh repo list $ORG --limit 100 --json nameWithOwner -q '.[].nameWithOwner'))
# Loop through the fetched repositories
for repo in "${REPOS[@]}"; do
# Print a dot for progress indication
printf "."
# Check for each user
for USER in "${USERS[@]}"; do
if gh api repos/$repo/collaborators/$USER &>/dev/null; then
echo -e "\n -> $USER has access to $repo"
fi
done
done
# Add a newline for clear separation between organizations
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment