Skip to content

Instantly share code, notes, and snippets.

@Gems
Created March 20, 2014 14:50
Show Gist options
  • Save Gems/9665537 to your computer and use it in GitHub Desktop.
Save Gems/9665537 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
for param in "$@"
do case $param in
--server=*)
server="${param#*=}"
;;
--token=*)
token="${param#*=}"
;;
--repo=*)
repo="${param#*=}"
;;
--sha=*)
sha="${param#*=}"
;;
--status=*)
status="${param#*=}"
;;
--url=*)
url="${param#*=}"
;;
--description=*)
description="${param#*=}"
;;
esac
done
# The state of the status. Can be one of pending, success, error, or failure.
status="{ \"state\": \"$status\", \"target_url\": \"$url\", \"description\": \"$description\" }"
if [[ "$repo" =~ ssh://* ]]; then
server=$(echo $repo | sed -E 's/^ssh:\/\/([a-zA-Z]+@)?//;s/\/.+$//')
repo=$(echo $repo | sed -E 's/^ssh:\/\/[^\/]+\///;s/\.git$//')
fi
if [ -z "$server" ] || [ -z "$token" ] || [ -z "$repo" ] || [ -z "$sha" ]; then
echo "Usage:"
echo "github-status.sh --server=github.com --token=lkjLjlkj234jlkadsf --repo=co/repo --sha=ef782784f009cc7b5c46886d790d84a843144973 --status=success --url='https://go.inn.ru/pipe...' --description='Greetings to Github from Go'"
echo ""
echo "You can omit --server param in case of SSH URL specified in --repo."
exit 1
fi
curl -H "Content-Type: application/vnd.github+json" -H "Authorization: token $token" -vsfL --data-ascii "${status}" "https://$server/api/v3/repos/$repo/statuses/$sha" 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment