3 # This is a script which delivers Change events from Mercurial to the
4 # buildmaster each time a changeset is pushed into a repository. Add it to
5 # the 'incoming' commit hook on your canonical "central" repository, by
6 # putting something like the following in the .hg/hgrc file of that
10 # incoming.buildbot = /PATH/TO/hg_buildbot.py BUILDMASTER:PORT
12 # Note that both Buildbot and Mercurial must be installed on the repository
15 import os
, sys
, commands
16 from StringIO
import StringIO
17 from buildbot
.scripts
import runner
21 CHANGESET_ID
= os
.environ
["HG_NODE"]
23 # TODO: consider doing 'import mercurial.hg' and extract this information
24 # using the native python
25 out
= commands
.getoutput("hg -v log -r %s" % CHANGESET_ID
)
26 # TODO: or maybe use --template instead of trying hard to parse everything
27 #out = commands.getoutput("hg --template SOMETHING log -r %s" % CHANGESET_ID)
34 if line
.startswith("user:"):
35 user
= line
[line
.find(":")+1:].strip()
36 elif line
.startswith("files:"):
37 files
= line
[line
.find(":")+1:].strip().split()
38 elif line
.startswith("description:"):
39 comments
= "".join(s
.readlines())
40 if comments
[-1] == "\n":
41 # this removes the additional newline that hg emits
42 comments
= comments
[:-1]
47 # note: this is more likely to be a full email address, which would make
48 # the left-hand "Changes" column kind of wide. The buildmaster should
49 # probably be improved to display an abbreviation of the username.
51 'revision': CHANGESET_ID
,
56 runner
.sendchange(c
, True)