26d45a2cd80aeb200bf7c8fd2bfbb04bff9da88d
[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 Details to follow
8 """
9
10 from bzrlib.config import option_registry
11 from bzrlib.lazy_import import lazy_import
12
13 # lazy_import so that it doesn't get loaded if it isn't used
14 # Approach borrowed from bzr-email
15 lazy_import(globals(), """\
16 from bzrlib.plugins.bzrirker import irkerhook as _irkerhook
17 """)
18
19
20
21 def branch_commit_hook(local, master, old_revno, old_revid,
22         new_revno, new_revid):
23     """This is the post_commit hook that runs after commit."""
24     if local is None:
25         _irkerhook.IrkerSender(master, new_revid,
26                 master.get_config_stack()).send()
27     else:
28         _irkerhook.IrkerSender(local, new_revid,
29                 master.get_config_stack()).send()
30
31
32 def branch_post_change_hook(params):
33     """This is the post_change_branch_tip hook."""
34     # (branch, old_revno, new_revno, old_revid, new_revid)
35     br = params.branch
36     revs = br._revision_history()[params.old_revno:params.new_revno]
37     for rev_id in revs:
38         _irkerhook.IrkerSender(br, rev_id, br.get_config_stack()).send()
39
40
41 def test_suite():
42     from unittest import TestSuite
43     import bzrlib.plugins.bzrirker.tests
44     result = TestSuite()
45     result.addTest(bzrlib.plugins.bzrirker.tests.test_suite())
46     return result
47
48
49 option_registry.register_lazy("irker_channels",
50     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_channels")
51 option_registry.register_lazy("irker_colours",
52     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_colours")
53 option_registry.register_lazy("irker_project",
54     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_project")
55
56 from bzrlib.hooks import install_lazy_named_hook
57 # This causes double commit messages - investigate what we need further
58 #install_lazy_named_hook("bzrlib.branch", "Branch.hooks", 'post_commit',
59 #        branch_commit_hook, 'bzr-irker')
60 install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
61         'post_change_branch_tip', branch_post_change_hook, 'bzr-irker')