commit 05bb181348e9a97ad131a1fefb51252a02c7d40b Author: CaptainArk Date: Thu Apr 19 20:57:13 2018 +0200 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..37ea590 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Github2eMail + +## What is it ? + +Github2eMail is a bash script that parses the GitHub API for projects you've starred and adds them to your rss2email configuration. + +## Dependencies + +- [curl](https://github.com/curl/curl) +- [rss2email](https://github.com/wking/rss2email) +- [jq](https://github.com/stedolan/jq) + +## How do I use it ? + +You need to have installed and configured rss2email first. + +Clone this repo. + +Edit the `config` file and modify the `UserName` variable to your GitHub username. + +Run the script. + +You're done ! + +You can also run the script periodically from cron if you want. + +## TODO + +Remove projects that were added by the script and are no longer starred by the user on GitHub from rss2email configuration. diff --git a/config b/config new file mode 100644 index 0000000..58b0c71 --- /dev/null +++ b/config @@ -0,0 +1,2 @@ +# Set this to your GitHub User Name +UserName="changemeplease" diff --git a/github2email.sh b/github2email.sh new file mode 100644 index 0000000..96eb186 --- /dev/null +++ b/github2email.sh @@ -0,0 +1,40 @@ +#!/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..." +fi + +GitHubApi="https://api.github.com/users/${UserName}/starred" +StarredList=$(curl -s ${GitHubApi} | jq -r '.[] | .name + "," + .html_url' | sed 's#$#/releases.atom#') + +# Checking for API request success +if [[ -z ${StarredList} ]]; then + 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 ${StarredList}; do + 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