Mention INSTALL in README
[bzrirker.git] / __init__.py
1 # -*- coding: utf-8 -*-
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
3 # Copyright 2012 Neil Muller
4 # GPL 2+ - see COPYING for details
5 """Sending irker notifications for commits and branch changes.
6
7 This will talk to an irkerd (currently assumed to be running on localhost)
8 and post commit logs.
9
10 Useful configuration settings:
11     irker_project - The name of the project used in announcements
12     irker_channels - The irc channels to post announcements to
13     irker_colours - Settings for using colours in the announcements (ANSI or
14         mIRC)
15 """
16
17 from bzrlib.config import option_registry
18 from bzrlib.lazy_import import lazy_import
19
20 # lazy_import so that it doesn't get loaded if it isn't used
21 # Approach borrowed from bzr-email
22 lazy_import(globals(), """\
23 from bzrlib.plugins.bzrirker import irkerhook as _irkerhook
24 """)
25
26
27 def branch_commit_hook(local, master, old_revno, old_revid,
28         new_revno, new_revid):
29     """This is the post_commit hook that runs after commit."""
30     if local is None:
31         _irkerhook.IrkerSender(master, new_revid,
32                 master.get_config_stack()).send()
33     else:
34         _irkerhook.IrkerSender(local, new_revid,
35                 master.get_config_stack()).send()
36
37
38 def branch_post_change_hook(params):
39     """This is the post_change_branch_tip hook."""
40     # (branch, old_revno, new_revno, old_revid, new_revid)
41     br = params.branch
42     revs = br._revision_history()[params.old_revno:params.new_revno]
43     for rev_id in revs:
44         _irkerhook.IrkerSender(br, rev_id, br.get_config_stack()).send()
45
46
47 def test_suite():
48     from unittest import TestSuite
49     import bzrlib.plugins.bzrirker.tests
50     result = TestSuite()
51     result.addTest(bzrlib.plugins.bzrirker.tests.test_suite())
52     return result
53
54
55 option_registry.register_lazy("irker_channels",
56     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_channels")
57 option_registry.register_lazy("irker_colours",
58     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_colours")
59 option_registry.register_lazy("irker_project",
60     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_project")
61
62 from bzrlib.hooks import install_lazy_named_hook
63 # This causes double commit messages - investigate what we need further
64 #install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'post_commit',
65 #        branch_commit_hook, 'bzr-irker')
66 install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
67         'post_change_branch_tip', branch_post_change_hook, 'bzr-irker')