Mercurial hook for notify.io

Sun 07 February 2010 by Peter Ward

Update (9/2/10): Fixed bug when pushing multiple commits at once, silenced wget's output.

Here is a Mercurial hook to send notifications to notify.io whenever it gets new changesets pushed to it. It requires python, wget, bash, mercurial, internet access and an uncommon sense of humour (the latter is only needed for bug reports).

To use, put something like this into your hgrc (either for a specific repo, or user or system-wide):

[hooks]
incoming.notifyio = /path/to/script

And then put this into a shell script, where you referenced /path/to/script before:

#!/bin/bash

# User data (change this)

email="YOUREMAILHERE"
apikey="YOURAPIKEYHERE"

# Work out api url to send to.

emailhash=`echo -n $email | md5sum | cut -f 1 -d" "`
url="http://api.notify.io/v1/notify/$emailhash"

# Quotes urls.
alias quote='python -c "import urllib, sys; print urllib.quote_plus(sys.stdin.read())"'

# Get repo information
desc=`hg log -r $HG_NODE --template "{desc}"`
author=`hg log -r $HG_NODE --template "{author}" | sed 's/ <.*//'`
text="$desc ($author)"

name=`pwd | awk 'BEGIN{FS="/"}{print $NF}'`

title="Mercurial changeset added"
if [ -n $name ]; then
 title="$title in $name"
fi

# text - The notification text. Only required field.
# title - The title or subject of the notification.
# icon - The URL for an icon to use for the notification.
# link - The URL for a link you want to associate with a notification.
# sticky - Set this to 'true' if you want the notification to be sticky.
# api_key - If you don't want to set it in the query string

text=`echo -n $text | quote`
title=`echo -n $title | quote`

data="text=$text&title=$title&api_key=$apikey"
#echo wget -O - --post-data $data $url
wget -q -O - --post-data $data $url

I take no responsibility for any loss of life, possessions or injuries sustained through the use of this hack. Please direct correspondence, thanks and hate mail to B.Posters, Devilish Lane, Cranbrook.


Comments