svn hook+python实现commit后自动发送邮件
最近开发人员负责人要求他们开发提交svn的时候,可以发送份邮件给他,这样好知道哪些人修改了什么,svn上有什么变更他好随时了解.
系统:centos 7(64位)
1.下载mailer配置和脚本
我们假设svn项目库为:/data/repos
wget http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/mailer/mailer.py
wget http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/mailer/mailer.conf.example
cp mailer.py /data/repos/hooks/
cp mailer.conf.example /data/repos/hooks/mailer.conf
2.修改svn hook
cd /data/repos/hooks/
cp post-commit.tmpl post-commit
vim post-commit
#!/bin/sh
export LANG=zh_CN.UTF-8
logfile="/var/log/svn.log"
REPOS="$1"
REV="$2"
/data/repos/hooks/mailer.py commit "$REPOS" "$REV" /data/repos/hooks/mailer.conf
3.配置mailer.conf
vim /data/repos/hooks/mailer.conf
[general]
smtp_hostname = smtp.xxxx.com:465 #邮件服务器地址
smtp_username = systemmonitor@xxxxx.com #svn使用这个账号发信.
smtp_password = xxxxxxx
smtp_ssl = yes
[defaults]
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
commit_subject_prefix = [SVN-Commit]
propchange_subject_prefix =
lock_subject_prefix =
unlock_subject_prefix =
from_addr = systemmonitor@xxxxx.com
to_addr = svn@xxxxxx.com slogra@xxxx.com #需要收信的人,多人以空格隔开.
reply_to = systemmonitor@xxxxx.com #这里可以填,或者不填.
generate_diffs = none
show_nonmatching_paths = yes
只需要改以上这些参数就可以了.
ps:
mailer.py使用方法:
./mailer.py --help
USAGE: mailer.py commit REPOS REVISION [CONFIG-FILE]
mailer.py propchange REPOS REVISION AUTHOR REVPROPNAME [CONFIG-FILE]
mailer.py propchange2 REPOS REVISION AUTHOR REVPROPNAME ACTION [CONFIG-FILE]
mailer.py lock REPOS AUTHOR [CONFIG-FILE]
mailer.py unlock REPOS AUTHOR [CONFIG-FILE]
If no CONFIG-FILE is provided, the script will first search for a mailer.conf
file in REPOS/conf/. Failing that, it will search the directory in which
the script itself resides.
环境:
CentOS Linux release 7.9.2009
subversion-devel-1.7.14-16.el7.x86_64
Python 2.7.5
报错:
Traceback (most recent call last):
File "/svnroot/demo/hooks/mailer/mailer.py", line 1444, in <module>
sys.argv[3:3+expected_args])
File "/usr/lib64/python2.7/site-packages/svn/core.py", line 307, in run_app
return func(application_pool, *args, **kw)
File "/svnroot/demo/hooks/mailer/mailer.py", line 103, in main
'repos_basename': os.path.basename(repos.repos_dir)
File "/svnroot/demo/hooks/mailer/mailer.py", line 1184, in __init__
self._prep_maps()
File "/svnroot/demo/hooks/mailer/mailer.py", line 1268, in _prep_maps
raise UnknownMappingSpec(mapvalue)