Skip to content

Instantly share code, notes, and snippets.

@sridharavinash
Last active March 30, 2017 01:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sridharavinash/7317567bcff33027942f363ff1727b89 to your computer and use it in GitHub Desktop.
Save sridharavinash/7317567bcff33027942f363ff1727b89 to your computer and use it in GitHub Desktop.
Branch build status on command line
#!/bin/bash
#
# Export $GITHUB_TOKEN with your access token
#
function get_build_status(){
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
repo=$(git config --get remote.origin.url | egrep -Eo '/(\w+)' | cut -d '/' -f 2)
status=$(curl -s -u "$GITHUB_TOKEN:x-oauth-basic" https://api.github.com/repos/github/$repo/commits/$branch/status | jq '.state' | tr -d '"')
case $status in
"success")
echo -e " \xE2\x9C\x85 "
;;
"failure")
echo -e "\xE2\x9D\x8C "
;;
"pending")
echo -e "\xE2\x97\x94"
;;
*)
echo ""
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment