Skip to content

Instantly share code, notes, and snippets.

@joest67
Created December 11, 2014 03:06
Show Gist options
  • Save joest67/b69f31275772d164d476 to your computer and use it in GitHub Desktop.
Save joest67/b69f31275772d164d476 to your computer and use it in GitHub Desktop.
Nofify us when we receive a pull-request by hipchat
#!/bin/sh
# Source config file
# should contains follows variables:
# AUTH_TOKEN
# ROOM_ID
source config.sh
my_func() {
return 1
}
my_func || RST=$?
############## HipChat Notify ####################
hipchat_notify() {
URL="https://api.hipchat.com/v1/rooms/message"
AUTH_TOKEN="$AUTH_TOKEN"
MSG_FORMAT="text"
if [ $# -eq 4 ]; then
ROOM_ID=$1
MESSAGE=$2
FROM=$3
COLOR=$4
else
exit 1
fi
# api version1
curl -X POST \
$URL \
--data-urlencode "color=$COLOR" \
--data-urlencode "notify=1" \
--data-urlencode "room_id=$ROOM_ID" \
--data-urlencode "message_format=$MSG_FORMAT" \
--data-urlencode "auth_token=$AUTH_TOKEN" \
--data-urlencode "from=$FROM" \
--data-urlencode "message=$MESSAGE"
if [[ ${RST+1} -eq 1 ]]; then
return $RST
else
return 0
fi
}
# notify room name/id
ROOM_ID=$ROOM_ID
# content
AUTHOR="$(echo $ghprbActualCommitAuthor | tr '[A-Z]' '[a-z]')"
CI_LINK="ci: $BUILD_URL"
PR_LINK="pr: $ghprbPullLink"
MESSAGE="@$AUTHOR send a pull-request"
# from
FROM="Pull Request"
# color
if [[ ${RST+1} && $RST -ne 0 ]]; then
LINKS="($PR_LINK, $CI_LINK)"
MESSAGE="$MESSAGE FAIL $LINKS"
COLOR="red"
else
LINKS="($PR_LINK)"
MESSAGE="$MESSAGE SUCCESS $LINKS"
COLOR="green"
fi
hipchat_notify "$ROOM_ID" "$MESSAGE" "$FROM" "$COLOR"
############## End HipChat Notify ####################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment