Last active
September 20, 2018 14:30
-
-
Save timlevett/54e989a01e8b235c6c263f89e18538be to your computer and use it in GitHub Desktop.
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 | |
if [ $# -lt 4 ]; then | |
echo "USAGE : ./github-fetch-all-teams-open-pr.sh <org> <auth-key> <team name> <temp_dir abs path>" | |
exit -1; | |
fi | |
ORG=$1 | |
AUTH_KEY=$2 | |
TEAM=$3 | |
TEMP_DIR=$4 | |
SILENT="-s" #remove -s for curl noise | |
rm -rf $TEMP_DIR | |
mkdir -p $TEMP_DIR | |
# get team id | |
TEAM_ID=`curl ${SILENT} -H "Authorization: token $AUTH_KEY" https://api.github.com/orgs/$ORG/teams | jq ".[] | select(.name == ${TEAM}) | .id"` | |
#echo "Team ID for $TEAM is $TEAM_ID" | |
# pull repos for team, total hack to get around paging | |
REPOS1=`curl ${SILENT} -H "Authorization: token $AUTH_KEY" "https://api.github.com/teams/${TEAM_ID}/repos?per_page=100&page=1" | jq ".[] | .pulls_url"` | |
REPOS2=`curl ${SILENT} -H "Authorization: token $AUTH_KEY" "https://api.github.com/teams/${TEAM_ID}/repos?per_page=100&page=2" | jq ".[] | .pulls_url"` | |
REPOS="$REPOS1 $REPOS2" | |
echo "$TEAM PRS; Scanning `echo $REPOS | grep -o " " | wc -l` repos." | |
# pull pull requests that are open for each project | |
for REPO in $REPOS; do | |
PULL_URL=`echo $REPO | cut -f1 -d"{" | cut -f2 -d"\""` | |
#echo $PULL_URL | |
REPO_OPEN_PRS=`curl ${SILENT} -H "Authorization: token $AUTH_KEY" $PULL_URL?state=open | jq ".[] | [{ url: .html_url , created: .created_at , user: .user.login, title: .title }]"` | |
if [ "" != "$REPO_OPEN_PRS" ]; then | |
echo $REPO_OPEN_PRS > $TEMP_DIR/`echo ${REPO:42} | cut -f1 -d"/"`.json | |
# echo $REPO_OPEN_PRS | |
fi | |
done | |
jq -s '[.[]]|flatten' $TEMP_DIR/*.json | jq 'sort_by(.created)' | jq '.[] | "• " + .user + " " + .title + " (" + .url + ")"' | cut -f2 -d"\"" | cut -f1 -d"\"" | |
rm -rf $TEMP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment