1
0
mirror of https://github.com/captainark/github2email.git synced 2024-11-14 21:47:39 +01:00
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)"
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
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
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}