星期三, 十月 22, 2008

修改Bazaar的bzr-email成Server-side hook.

bzr用插件来实现Hook的功能,用起来实在是不方便。为了在每次提交的时候都有邮件通知,从Lunchpad上下在bzr-email插件。

bzr co lp:bzr-email
cd bzr-email
./setup.py install
这样可以安装到系统级别,如果只是自己用的话,安装到~/.bazaar/plugins(WINDows是另外的目录)。

在要使用这个插件的分支的.bzr/branch/branch.conf文件里加入配置参数

post_commit_to = someone@example.com
post_commit_sender = bzr@example.com
post_commit_mailer = smtplib
smtp_server = mail.example.com

发现本地提交的时候能发送邮件,但是远程通过bzr+ssh提交是不能触发。而且这个只是post_commit的Hook,在PUSH的时候恐怕也不会触发。
一通搜索发现,bzr的文档实在是不完整,很多新功能没有好的文档。还好找到了一个BUG日志

有查看了branch.py的源代码。
把bzr-email的__init__.py按如下patch修改。

=== modified file '__init__.py'
--- __init__.py 2008-08-05 21:51:27 +0000
+++ __init__.py 2008-10-22 09:38:12 +0000
@@ -86,16 +86,19 @@
_emailer.EmailSender(master, new_revid, master.get_config(),
local_branch=local).send_maybe()

+def post_change_branch_tip_hook(params):
+ """Hook for email. """
+ _emailer.EmailSender(params.branch, params.new_revid, params.branch.get_config()).send_maybe()

def install_hooks():
"""Install CommitSender to send after commits with bzr >= 0.15 """
install_named_hook = getattr(Branch.hooks, 'install_named_hook', None)
if install_named_hook is not None:
- install_named_hook('post_commit', branch_commit_hook, 'bzr-email')
+ install_named_hook('post_change_branch_tip', post_change_branch_tip_hook, 'bzr-email')
else:
- Branch.hooks.install_hook('post_commit', branch_commit_hook)
+ Branch.hooks.install_hook('post_change_branch_tip', post_change_branch_tip_hook)
if getattr(Branch.hooks, 'name_hook', None) is not None:
- Branch.hooks.name_hook(branch_commit_hook, "bzr-email")
+ Branch.hooks.name_hook(post_change_branch_tip_hook, "bzr-email")


def test_suite():


改完之后的bzr-email可以作为server-side的hook使用。而且push和commit的时候都可以触发发送邮件。

没有评论:

发表评论