Created
November 26, 2021 20:41
-
-
Save houstondapaz/db9bb00de81ce090ea0a1391b9745054 to your computer and use it in GitHub Desktop.
get all org repos and main branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GITHUB_USERNAME= | |
GIT_TOKEN= | |
GITHUB_ORG_NAME= | |
declare repositories=(` | |
for ((i=0; ; i++)); do | |
current_repositories=$(curl -u ${GITHUB_USERNAME}:${GIT_TOKEN} https://api.github.com/orgs/${GITHUB_ORG_NAME}/repos\?page\=$i\&per_page\=100\&type\=private | jq -c 'map( { "name": .name , "main_branch": .default_branch } )') | |
length=$(jq length <<< $current_repositories) | |
if [ $length -lt 1 ]; then | |
break; | |
fi | |
echo $current_repositories | |
done | |
`) | |
repositories_concatenated='[]' | |
for line in ${repositories[@]}; do | |
repositories_concatenated=`jq --argjson arr1 "$repositories_concatenated" --argjson arr2 "$line" -n '$arr1 + $arr2 | group_by(.name) | map(.[-1])'` | |
done | |
echo "Total Repositories => `jq length <<< $repositories_concatenated`" | |
jq -c '.[]' <<< $repositories_concatenated | while read repository; do | |
repo_name=$(jq -r '.name' <<< $repository) | |
main_branch=$(jq -r '.main_branch' <<< $repository) | |
echo "REPOSITORY=$repo_name MAIN_BRANCH=$main_branch" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment