So you've got the party rabbit for the day, huh? It's time to party!
- Requires you to have the ruby gem
terminal-notifier
installed - Requires you to have an environment variable
GITHUB_API_TOKEN
set in your.bash_profile
- This is a crontab requirement as it does not have access to all of the environment variables that your normal shell session has.
- If you are using fish and this is in your
config.fish
, you MUST copy it into your.bash_profile
. - If you are using zsh and your environment variables are exported in a
.zshrc
file, that's fine, just change line 4 of the snippet below to besource $HOME/.zshrc
.
Feel free to take these instructions less literally if you have a different place that you like to store your executable functions. The overall goal is to get an executable bash script that crontab will be able to pick up and run.
-
Navigate to
cd /usr/local/bin
-
touch check_reviewable_pull_requests.sh
-
Open that file
-
Paste in the following code and save the file:
#!/bin/bash PATH=/usr/bin:/bin:/usr/local/bin source $HOME/.bash_profile curl=`curl -H "Authorization: bearer $GITHUB_API_TOKEN" -X GET https://api.github.com/repos/gospotcheck/gospotcheck/pulls` needs_review_count=`echo $curl | grep -c "review requested"` if [ $needs_review_count != "0" ]; then pr_text="PRs" if [ $needs_review_count = "1" ]; then pr_text="PR" fi terminal-notifier -message "You have $needs_review_count new $pr_text to review. Click to go to GitHub." -title "Time to party!" -open https://github.com/gospotcheck/gospotcheck/pulls fi
-
Make it executable with
chmod u+x check_reviewable_pull_requests.sh
Add the following fish function that will trigger crontab to run the script above every hour.
- If you want to test this at first by running it every minute, change the first
0
to a*
. - If you put your executable script at a different path, make sure you reflect that here
- The
>/dev/null 2>&1
ensure that you won't get any terminal mail created when this runs
function party_on
echo "0 * * * * /usr/local/bin/check_reviewable_pull_requests.sh >/dev/null 2>&1" | crontab
end
This function will turn it off again:
function party_off
crontab -r
end
If you use zsh or bash, the only difference is how you define the function, such as:
function party_on() {
echo "0 * * * * /usr/local/bin/check_reviewable_pull_requests.sh" | crontab
}
If you're on duty with the Party Rabbit, run party_on
at the beginning of the day. Every hour, on the hour, you will receive a Mac notification only if there are pull requests with the review requested
label applied. When the notification pops you, you can click it to be taken to the pull requests page on GitHub. At the end of the day, run party_off
to turn the notifications off!