github2email/github2email.sh

49 lines
1.5 KiB
Bash
Raw Normal View History

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..."
exit 2
2018-04-19 20:57:13 +02:00
fi
GitHubApi="https://api.github.com/users/${UserName}/starred"
LastPage="$(curl -I ${GitHubApi} | grep -Eo 'page=[[:digit:]]+' | tail -n1)"
2018-04-19 23:13:45 +02:00
TempFile=$(mktemp -t github2email.sh.XXXXXXXXXX)
# 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
for StarPages in $(seq 1 ${LastPage#*=}); do
2018-04-19 23:13:45 +02:00
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
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
# Doing our magic stuff that does cool shit
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
[[ -f ${TempFile} ]] && rm ${TempFile}