From 4a2f3a48ba2d3d7188bf916efbb2737b86d3cecf Mon Sep 17 00:00:00 2001 From: CaptainArk Date: Thu, 19 Apr 2018 23:07:19 +0200 Subject: [PATCH] GitHub API reponses can be on multiple pages... --- github2email.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/github2email.sh b/github2email.sh index b24ef88..75b4649 100755 --- a/github2email.sh +++ b/github2email.sh @@ -10,10 +10,15 @@ if [[ -z ${UserName} ]] || [[ $UserName == "changemeplease" ]]; then fi GitHubApi="https://api.github.com/users/${UserName}/starred" -StarredList=$(curl -s ${GitHubApi} | jq -r '.[] | .name + "," + .html_url' | sed 's#$#/releases.atom#') +LastPage="$(curl -I ${GitHubApi} | grep -Eo 'page=[[:digit:]]+' | tail -n1)" +TempFile=$(mktemp -t $0) + +for StarPages in $(seq 1 ${LastPage#*=}); do + curl -s "${GitHubApi}&page=${StarPages}" | jq -r '.[] | .name + "," + .html_url' | sed 's#$#/releases.atom#' >> ${TempFile} +done # Checking for API request success -if [[ -z ${StarredList} ]]; then +if [[ ! -s ${TempFile} ]]; then echo "Something went wrong while fetching the project starred list for ${UserName}. Exiting..." exit 2 fi @@ -27,7 +32,7 @@ for Dependencies in curl jq r2e; do done # Doing our magic stuff that does cool shit -for Star in ${StarredList}; do +for Star in $(cat ${TempFile}); do ProjectName=${Star%,*} ProjectUrl=${Star##*,} # Only add a project to r2e config if it does not already exist @@ -39,3 +44,5 @@ for Star in ${StarredList}; do echo "Project ${ProjectName} has been added to rss2email configuration !" fi done + +[[ -f ${TempFile} ]] && rm ${TempFile}