1
0
mirror of https://github.com/captainark/github2email.git synced 2024-11-22 16:41:42 +01:00

GitHub API reponses can be on multiple pages...

This commit is contained in:
CaptainArk 2018-04-19 23:07:19 +02:00
parent 49b6187643
commit 4a2f3a48ba

View File

@ -10,10 +10,15 @@ if [[ -z ${UserName} ]] || [[ $UserName == "changemeplease" ]]; then
fi fi
GitHubApi="https://api.github.com/users/${UserName}/starred" 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 # 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..." echo "Something went wrong while fetching the project starred list for ${UserName}. Exiting..."
exit 2 exit 2
fi fi
@ -27,7 +32,7 @@ for Dependencies in curl jq r2e; do
done done
# Doing our magic stuff that does cool shit # Doing our magic stuff that does cool shit
for Star in ${StarredList}; do for Star in $(cat ${TempFile}); do
ProjectName=${Star%,*} ProjectName=${Star%,*}
ProjectUrl=${Star##*,} ProjectUrl=${Star##*,}
# Only add a project to r2e config if it does not already exist # 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 !" echo "Project ${ProjectName} has been added to rss2email configuration !"
fi fi
done done
[[ -f ${TempFile} ]] && rm ${TempFile}