Last active
June 27, 2018 08:42
-
-
Save blomquisg/c9e247641f2791a2c841cb47aa58b907 to your computer and use it in GitHub Desktop.
Script to find Github PRs to review in various repos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Open a series of web browsers with the list of PRs slated to review in various Github repositories. | |
# See _main function at the end. | |
CLIENT_KEY= | |
CLIENT_SECRET= | |
function get_command() | |
{ | |
local command=`which $1 2>/dev/null` | |
if [ $? -ne 0 ]; then | |
echo "Command not found: $1" | |
exit 1 | |
fi | |
echo "$command" | |
} | |
BROWSER=$(get_command "google-chrome") | |
CURL=$(get_command "curl") | |
JQ=$(get_command "jq") | |
function open_url() | |
{ | |
url=$1 | |
message=$2 | |
echo "$message" | |
$BROWSER "$url" &>/dev/null | |
} | |
function get_open_pr_count() | |
{ | |
repo="$1" | |
review_type="$2" | |
extra_args="$3" | |
creds="client_id=$CLIENT_KEY&client_secret=$CLIENT_SECRET" | |
url="https://api.github.com/search/issues?q=repo:ManageIQ/$repo+${review_type}:blomquisg+is:pr+is:open+${extra_args}&per_page=1&$creds" | |
$CURL -s "$url" | $JQ '.["total_count"]' | |
} | |
function open_browser_for_repo_and_review_type() | |
{ | |
repo="$1" | |
review_type="$2" | |
extra_args="$3" | |
pr_count=`get_open_pr_count "$repo" "$review_type" "$extra_args"` | |
if [ $pr_count -gt 0 ]; then | |
github="https://github.com" | |
org="ManageIQ" | |
uri="pulls?utf8=✓&q=is:open+is:pr+${review_type}:blomquisg+${extra_args}" | |
url="$github/$org/$repo/$uri" | |
open_url "$url" "As $review_type: $repo ($url)" | |
else | |
echo " Skipping $repo for $review_type." | |
fi | |
} | |
function open_browsers_for_repo() | |
{ | |
repo="$1" | |
open_browser_for_repo_and_review_type "$repo" "assignee" "-label:wip+-label:unmergeable" | |
open_browser_for_repo_and_review_type "$repo" "review-requested" | |
} | |
function _main() | |
{ | |
repos=("$@") | |
for repo in "${repos[@]}"; do | |
open_browsers_for_repo "$repo" | |
done | |
} | |
REPOS=( manageiq \ | |
manageiq-providers-amazon \ | |
manageiq-providers-azure \ | |
manageiq-providers-lenovo \ | |
manageiq-providers-vmware \ | |
manageiq-providers-openstack \ | |
manageiq-providers-ovirt \ | |
manageiq-providers-hawkular \ | |
manageiq-providers-kubernetes \ | |
manageiq-providers-openshift \ | |
manageiq-gems-pending \ | |
) | |
_main "${REPOS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment