Skip to content

Instantly share code, notes, and snippets.

@barend
Last active June 3, 2016 11:04
Show Gist options
  • Save barend/0c4403178b6a681b3338c96f0f90228c to your computer and use it in GitHub Desktop.
Save barend/0c4403178b6a681b3338c96f0f90228c to your computer and use it in GitHub Desktop.
Get GitHub status update for all repo's checked out of a GitHub org.
#!/bin/bash
# Does a fetch --prune of all repositories and lists all open pull requests
#
# Usage:
# `hello <github org>`
#
# Prep steps:
# 1) Ensure your git clones are in a subdirectory that matches your github org name
# 2) install jq from https://stedolan.github.io/jq/ (brew install jq)
# 3a) Create a GitHub Personal OAuth token on https://github.com/settings/tokens/new (with "repo" access)
# 3b) Store this token in the Login keychain with "gh-oauth" as the Account Name and whatever as the KeyChain item name
#
# Notes:
# 1) Only tested with one level of nesting and simple filenames
# 2) The `security find-generic-password` command is OS X specific. Modify as needed to get your access token into the OAUTH variable.
#
set -e
PROGNAME="${0##*/}"
PROGDIR="${0%/*}"
ORG="$1"
if [ "" = "$ORG" ]; then
echo >&2 "Usage: $PROGNAME <github org>"
exit 1
fi
if [ ! -d "$PROGDIR/$ORG" ]; then
echo >&2 "Directory not found: $PROGDIR/$ORG"
exit 1
fi
OAUTH=$(security find-generic-password -ga gh-oauth 2>&1 >/dev/null | awk '/^password/{ print substr($2, 2, 40) }')
if [ "" = "$OAUTH" ]; then
echo >&2 "Warning: GitHub OAuth key not found; not listing PR's"
fi
for repo in $(find "$PROGDIR/$ORG" -type d -and -name '.git' | xargs -n1 dirname | xargs -n1 basename)
do
cdir="$PROGDIR/$ORG/$repo"
if $(git -C $cdir remote get-url origin 2>/dev/null | fgrep -q "$ORG"); then
echo -e "\033[92m$repo\033[0m"
GITRESULT=$(git -C $cdir remote -v | wc -l)
if [ "$GITRESULT" != "0" ]; then
git -C $cdir fetch --prune
if [ "" != "$OAUTH" ]; then
curl -fsS -H "Authorization: token $OAUTH" "https://api.github.com/repos/$ORG/$repo/pulls" | jq -r '.[] | "#\(.number) - \(.title)"'
fi
fi
git -C $cdir status --branch --short --porcelain | head -n1
echo ''
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment