Skip to content

Instantly share code, notes, and snippets.

@kenichi-shibata
Created March 1, 2022 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenichi-shibata/afbc167c38f27e821d8ffe660349ec56 to your computer and use it in GitHub Desktop.
Save kenichi-shibata/afbc167c38f27e821d8ffe660349ec56 to your computer and use it in GitHub Desktop.
get last page of github list repos
# 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