Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created April 9, 2023 19:12
Show Gist options
  • Save KyMidd/052b43a1b1ca2fe0c63dcd986a4f43f1 to your computer and use it in GitHub Desktop.
Save KyMidd/052b43a1b1ca2fe0c63dcd986a4f43f1 to your computer and use it in GitHub Desktop.
# Get all repos
for PAGE_NUMBER in $(seq $PAGES_NEEDED); do
echo "Getting repos page $PAGE_NUMBER of $PAGES_NEEDED"
# Could replace this with graphql call (would likely be faster, more efficient), but this works for now
PAGINATED_REPOS=$(curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/$GH_ORG/repos?per_page=$REPOS_PER_PAGE&sort=pushed&page=$PAGE_NUMBER" | jq -r '.[].name')
# Combine all pages of repos into one variable
# Extra return added since last item in list doesn't have newline (would otherwise combine two repos on one line)
ALL_REPOS="${ALL_REPOS}"$'\n'"${PAGINATED_REPOS}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment