2018-04-19 20:57:13 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# shellcheck source=config
|
|
|
|
source "$(dirname $0)/config"
|
|
|
|
|
|
|
|
# Checking if UserName has been defined
|
|
|
|
if [[ -z ${UserName} ]] || [[ $UserName == "changemeplease" ]]; then
|
|
|
|
echo "GitHub username is incorrect of undefined in config file. Exiting..."
|
2018-04-19 21:00:23 +02:00
|
|
|
exit 2
|
2018-04-19 20:57:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
GitHubApi="https://api.github.com/users/${UserName}/starred"
|
2018-04-19 23:07:19 +02:00
|
|
|
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
|
2018-04-19 20:57:13 +02:00
|
|
|
|
|
|
|
# Checking for API request success
|
2018-04-19 23:07:19 +02:00
|
|
|
if [[ ! -s ${TempFile} ]]; then
|
2018-04-19 20:57:13 +02:00
|
|
|
echo "Something went wrong while fetching the project starred list for ${UserName}. Exiting..."
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Checking for dependencies
|
|
|
|
for Dependencies in curl jq r2e; do
|
|
|
|
if [[ ! -x $(which ${Dependencies}) ]]; then
|
|
|
|
echo "${Dependencies} is required to run to script. Exiting..."
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Doing our magic stuff that does cool shit
|
2018-04-19 23:07:19 +02:00
|
|
|
for Star in $(cat ${TempFile}); do
|
2018-04-19 20:57:13 +02:00
|
|
|
ProjectName=${Star%,*}
|
|
|
|
ProjectUrl=${Star##*,}
|
|
|
|
# Only add a project to r2e config if it does not already exist
|
|
|
|
IsDeclaredProject="$(r2e list | grep ${ProjectUrl})"
|
|
|
|
if [[ -z ${IsDeclaredProject} ]]; then
|
|
|
|
r2e add ${ProjectName} ${ProjectUrl}
|
|
|
|
# We only want to be informed of future releases
|
|
|
|
r2e run --no-send ${ProjectName}
|
|
|
|
echo "Project ${ProjectName} has been added to rss2email configuration !"
|
|
|
|
fi
|
|
|
|
done
|
2018-04-19 23:07:19 +02:00
|
|
|
|
|
|
|
[[ -f ${TempFile} ]] && rm ${TempFile}
|