Created
March 1, 2022 11:04
-
-
Save kenichi-shibata/afbc167c38f27e821d8ffe660349ec56 to your computer and use it in GitHub Desktop.
get last page of github list repos
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
# https://www.middlewareinventory.com/blog/github-list-all-repositories-using-rest-api/ | |
# get last page of github list repos | |
set -euo pipefail | |
export ORG= "" your orgname | |
export BASEURL="https://api.github.com/orgs/$ORG/repos" | |
export USERNAME="" # your username | |
export TOKEN="" # your github token | |
export PER_PAGE=100 | |
export LAST_PAGE=`curl -I -i -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s ${BASEURL}\?per_page\=${PERPAGE} | grep -i link: 2>/dev/null|sed 's/link: //g'|awk -F',' -v ORS='\n' '{ for (i = 1; i <= NF; i++) print $i }'|grep -i last|awk '{print $1}' | tr -d '\<\>' | tr '\?\&' ' '|awk '{print $3}'| tr -d '=;page'` | |
echo $LAST_PAGE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment