Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Created January 30, 2014 23:36
Show Gist options
  • Save lukebakken/8722493 to your computer and use it in GitHub Desktop.
Save lukebakken/8722493 to your computer and use it in GitHub Desktop.
#!/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