Update to point at irker's new gitlab repo
[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     irker_server - Host for the irkerd server (localhost by default)
16     irker_port - port to connect to (6659 by default)
17 """
18
19 from bzrlib.config import option_registry
20 from bzrlib.lazy_import import lazy_import
21
22 # lazy_import so that it doesn't get loaded if it isn't used
23 # Approach borrowed from bzr-email
24 lazy_import(globals(), """\
25 from bzrlib.plugins.bzrirker import irkerhook as _irkerhook
26 """)
27
28
29 def branch_commit_hook(local, master, old_revno, old_revid,
30         new_revno, new_revid):
31     """This is the post_commit hook that runs after commit."""
32     if local is None:
33         _irkerhook.IrkerSender(master, new_revid,
34                 master.get_config_stack()).send()
35     else:
36         _irkerhook.IrkerSender(local, new_revid,
37                 master.get_config_stack()).send()
38
39
40 def branch_post_change_hook(params):
41     """This is the post_change_branch_tip hook."""
42     # (branch, old_revno, new_revno, old_revid, new_revid)
43     br = params.branch
44     revs = br._revision_history()[params.old_revno:params.new_revno]
45     for rev_id in revs:
46         _irkerhook.IrkerSender(br, rev_id, br.get_config_stack()).send()
47
48
49 def test_suite():
50     from unittest import TestSuite
51     import bzrlib.plugins.bzrirker.tests
52     result = TestSuite()
53     result.addTest(bzrlib.plugins.bzrirker.tests.test_suite())
54     return result
55
56
57 option_registry.register_lazy("irker_channels",
58     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_channels")
59 option_registry.register_lazy("irker_colours",
60     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_colours")
61 option_registry.register_lazy("irker_project",
62     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_project")
63 option_registry.register_lazy("irker_server",
64     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_server")
65 option_registry.register_lazy("irker_port",
66     "bzrlib.plugins.bzrirker.irkerhook", "opt_irker_port")
67
68 from bzrlib.hooks import install_lazy_named_hook
69 install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
70         'post_commit', branch_post_change_hook, 'bzr-irker')