svn hook+python实现commit后自动发送邮件

post by rocdk890 / 2019-1-3 15:45 Thursday linux技术
    最近开发人员负责人要求他们开发提交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.
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-751.html

标签: svn 邮件 提交 python commit smtp mailer

  1. 2022-06-28 09:58
    @milton010:不好意思,你这个问题我没遇到,但看你的报错信息是mailer.py这个脚本在报错,建议你检查下python环境.
  1. gravatar milton010
    2022-06-24 15:05
    请教一下,配置完成测试出现如下问题,谢谢!
    环境:
    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)

评论: