|
Size: 2947
Comment:
|
← Revision 7 as of 2012-11-06 23:48:31 ⇥
Size: 0
Comment: has been marked for deletion since 2012-05-08
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| <<Include(A:delete)>> A nice thing to have, if you have an IRC channel for a project, is a bot that announces pushes. Making one is very simple using the hooks built into Mercurial, and an IRC bot framework of your choice (I used [[http://www.jibble.org/pircbot.php|Pircbot]]). Here's how it looks: {{{ #!irc [15:28] <@JavaMan> [ZoFreX] rev.15: Added SSLification in new command format [15:28] <@JavaMan> [ZoFreX] rev.16: Added SSL to command list }}} Don't worry if that's not quite to your liking, it's very easy to customise the output! There are three parts to this: The IRC bot, the hook in hgrc, and a python script that delivers the commit details to the IRC bot. === IRC Bot === This is probably the least interesting part. All you need is an IRC bot that listens on a socket, and says whatever it receives on it into your IRC channel. /!\ For security reasons you probably want to run this on the same machine that hosts the repository and limit connections to localhost only! If you don't have any kind of authentication in place, anyone could connect and tie-up the bot, or make it say mean things. This is the relevant part of my bot ([[http://redmine.zofrex.com/wiki/website/HGBot|full source]]): {{{#!java ServerSocket serverSocket = null; serverSocket = new ServerSocket(50005); while (true) { clientSocket = serverSocket.accept(); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println("Received: " + inputLine); bot.send(inputLine); } in.close(); clientSocket.close(); } }}} === HGRC hook === Hooks in Mercurial can either call native Python code or external programs (shell scripts, whatever). While the latter is easier, the former approach gives you much easier access to the details of the repository, such as the commit messages, because Mercurial will pass a repo object as one of the function arguments. For the python approach you'll want something like this in .hg/hgrc in your repo: {{{#!python [hooks] incoming.irc = python:myirchook.irc }}} This hook means anything pushed to the repo triggers myirchook.irc. Obviously you need a module called myirchook on the PYTHONPATH with a function named irc: === myirchook.py === {{{#!python import socket def irc(ui, repo, node=None, **kwargs): ctx = repo[node] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("localhost", 50005)) s.send("[%s] rev.%d: %s" % (ctx.user(), ctx.rev(), ctx.description())) s.close() }}} The important thing here if you want to customise is line 4. For a comprehensive list of methods you can access, see the [[http://www.selenic.com/mercurial/wiki/index.cgi/MercurialApi|Mercurial API]] (in particular section 5, "Change Contexts". ---- CategoryRecipe CategoryProposedDeletion |
