Created
January 30, 2014 23:36
-
-
Save lukebakken/8722493 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
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
tmpfile='' | |
function onexit | |
{ | |
if [[ -f $tmpfile ]] | |
then | |
rm -f $tmpfile | |
fi | |
} | |
trap onexit EXIT | |
function errexit | |
{ | |
echo "error: $@" 1>&2 | |
exit 1 | |
} | |
api_token='' | |
if [[ -s $HOME/.hcapi ]] | |
then | |
api_token=$(< $HOME/.hcapi) | |
else | |
errexit "must create $HOME/.hcapi with your API token." | |
fi | |
declare -i ticket="${1-0}" | |
if (( ticket <= 0 )) | |
then | |
errexit 'first arg must be ticket number.' | |
fi | |
response_file="$2" | |
if [[ ! -s $response_file ]] | |
then | |
echo 'second argument must be file containing text to be reviewed.' | |
fi | |
summary="$3" | |
tmpfile=$(mktemp -t hipchat-review-$ticket) | |
echo -n "{\"message\":\"ticket #$ticket - $summary\\n\\n" > $tmpfile | |
perl -pe's/\n/\\n/;s/"/\\"/g' $response_file >> $tmpfile | |
echo -n '","message_format":"text","color":"yellow"}' >> $tmpfile | |
curl -H 'Content-Type: application/json' \ | |
-H "Authorization: Bearer $api_token" \ | |
-XPOST \ | |
--data @$tmpfile \ | |
'https://api.hipchat.com/v2/room/61640/notification' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment