Last active
March 9, 2016 09:02
-
-
Save sfai05/1d170f1d6d3f32722bcb to your computer and use it in GitHub Desktop.
Script that fetches numbers of open pull requests from GitHub
This file contains hidden or 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 | |
| # Requires: jq, curl | |
| # | |
| # | |
| # Simple script that fetches list of open pull requests from GitHub | |
| # Author: Fai | |
| # | |
| export PATH='/usr/local/bin:/usr/bin:$PATH' | |
| # API base path | |
| GITHUB_REPO_API="https://api.github.com/repos" | |
| # User with permission to the repository | |
| GITHUB_USER="" | |
| # GitHub API access token (can be generated via github website) | |
| GITHUB_ACCESS_TOKEN="" | |
| # Name of the repository to fetch pull requests for | |
| GITHUB_REPO="lifehack-core" | |
| # Owner of the repository | |
| GITHUB_REPO_OWNER="stepcase" | |
| # Fetch and parse open pull request from GitHub | |
| PULLS=`curl -s -u $GITHUB_USER:$GITHUB_ACCESS_TOKEN $GITHUB_REPO_API/$GITHUB_REPO_OWNER/$GITHUB_REPO/pulls | jq '.[]|[.milestone, .assignee, .html_url, .title]|[.[0].title, .[1].login, .[2], .[3]]'` | |
| RTD=`echo $PULLS | jq '. | select( select(.[0] != null) | .[0] | contains("Ready to Deploy") )'` | |
| TEST=`echo $PULLS | jq '. | select( select(.[0] != null) | .[0] | contains("Test") ) | select(.[1] == "'$GITHUB_USER'")'` | |
| CR=`echo $PULLS | jq '. | select( select(.[0] != null) | .[0] | contains("Code Review") ) | select(.[1] == "'$GITHUB_USER'")'` | |
| INCOMPLETE=`echo $PULLS | jq '. | select( select(.[0] != null) | .[0] | contains("Incomplete") ) | select(.[1] == "'$GITHUB_USER'")'` | |
| RTDCOUNT=`echo $RTD | jq '. | .[1]' | wc -l | xargs` | |
| CRCOUNT=`echo $CR | jq '. | .[1]' | wc -l | xargs` | |
| echo "CR : $CRCOUNT / RTD : $RTDCOUNT" | |
| echo "---" | |
| echo "Incomplete" | |
| echo $INCOMPLETE | jq -r '.[3] + " | href=" + .[2]' | |
| echo "Code Review" | |
| echo $CR | jq -r '.[3] + " | href=" + .[2]' | |
| echo "Test" | |
| echo $TEST | jq -r '.[3] + " | href=" + .[2]' | |
| echo "Ready To Deploy" | |
| echo $RTD | jq -r '.[3] + " | href=" + .[2]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment