Skip to content

Instantly share code, notes, and snippets.

@ToniRib
Last active March 15, 2018 19:24
Show Gist options
  • Save ToniRib/48bc0910168e5368b047490266f30648 to your computer and use it in GitHub Desktop.
Save ToniRib/48bc0910168e5368b047490266f30648 to your computer and use it in GitHub Desktop.
Checks for PRs with 'review requested' label and pops up a notification

Actions

  • Gets PRs from the main GSC repo (github.com/gospotcheck/gospotcheck) that have a review requested label applied to them
  • If you have at least 1 PR to review, it pops open a Mac notifier message that tells you how many PRs are in the review requested state
  • Allows you to click the notification to go straight to the pull requests page

Usage:

get_review_requested_pull_requests

Requirements

  • Requires jq to be installed via homebrew
  • Requires the terminal-notifier ruby gem

This requires that you have the following variables in your fish config:

  • GITHUB_API_TOKEN created and obtained on GitHub in your personal account

Place the following code in in ~/.config/fish/functions/get_review_requested_pull_requests.fish

function get_review_requested_pull_requests
  set -l needs_review_count (curl -H "Authorization: bearer $GITHUB_API_TOKEN" -X GET https://api.github.com/repos/gospotcheck/gospotcheck/pulls | jq '.[] | {url, labels: [.labels[]]}' | jq 'select(contains({labels: [{name: "review requested"}]}))' | jq '.url' | wc -l | awk '{$1=$1};1')

  if [ $needs_review_count != "0" ]
    set -l pr_text "PRs"

    if [ $needs_review_count = "1" ]
      set pr_text "PR"
    end

    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
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment