NEWS: fix minor typo
[buildbot.git] / contrib / hg_buildbot.py
blobc7190f73c25b188f24408f58222078bbc92c83f9
1 #! /usr/bin/python
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
7 # repository:
9 # [hooks]
10 # incoming.buildbot = /PATH/TO/hg_buildbot.py BUILDMASTER:PORT
12 # Note that both Buildbot and Mercurial must be installed on the repository
13 # machine.
15 import os, sys, commands
16 from StringIO import StringIO
17 from buildbot.scripts import runner
19 MASTER = sys.argv[1]
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 log -r %s --template '{author}\n{files}\n{desc}'" % CHANGESET_ID)
27 s = StringIO(out)
28 user = s.readline().strip()
29 # NOTE: this fail when filenames contain spaces. I cannot find a way to get
30 # hg to use some other filename separator.
31 files = s.readline().strip().split()
32 comments = "".join(s.readlines())
34 change = {
35 'master': MASTER,
36 # note: this is more likely to be a full email address, which would make
37 # the left-hand "Changes" column kind of wide. The buildmaster should
38 # probably be improved to display an abbreviation of the username.
39 'username': user,
40 'revision': CHANGESET_ID,
41 'comments': comments,
42 'files': files,
45 runner.sendchange(change, True)