Mercurial hook for

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 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):

incoming.notifyio = /path/to/script

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


# User data (change this)


# Work out api url to send to.

emailhash=`echo -n $email | md5sum | cut -f 1 -d" "`

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

# 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"

# 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`

#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.

Published in: on February 7, 2010 at 1:06 pm  Comments Off on Mercurial hook for  
%d bloggers like this: