Windows下的SVN通过blat(开源的)邮件通知

参考自:

http://bbs.iusesvn.com/viewthread.php?tid=2893&highlight=%2Bgo2cxg

 

有位大哥写了http://bbs.iusesvn.com/thread-662-1-1.html 实现邮件通知功能 配置比较麻烦
一切从简 往下看~!!
嘿嘿~!!为了打造一个全自动 超只能的SVN而不懈努力哈
一直在寻找好的邮件通知的工具和脚本。很辛苦~呵呵。找了很多,不凑效。
偶尔发现一款小工具blat,是一款开源软件,主页:http://www.blat.net/

下载地址:http://sourceforge.net/projects/blat/files/

 

解压缩后放到%windir%/system32的文件夹里面
就可以直接调用了
发送邮件的方式很简单
blat d:/body.txt -to ***@tom.com,***[email protected] -base64 -charset Gb2312 -subject "测试" -server smtp.***.com -u user -pw password
body.txt
邮件内容的文件。这个很有用。你可以把你需要发送的内容放到里面去

-to ***@tom.com
收件人列表,多个人用逗号隔开 当然可以加-cc抄送 -bcc 密送选项

-base64 -charset Gb2312
一些格式字符的配置 可以参见附件里面 很详细
-subject "测试"
邮件主题
-server smtp.***.com
smtp服务器的地址

-u user -pw password
需要登录用的用户名和密码 当然 如果公司服务器不需要验证 留空

 

 如果用visualSVN Server,post-commit脚本拷到如图这个位置:

Windows下的SVN通过blat(开源的)邮件通知_第1张图片

下面把我的post-commit.bat的内容贴出来
@echo onset REPOS=%1set REV=%2set RD=%RANDOM% 这个是产生随机数,为的是不要重复文件名。避免发生提交冲突C:/"Program Files (x86)"/"VisualSVN Server"/bin/svnlook info %REPOS% > D:/TempFIle/INFO_%RD%.txt获取执行提交的用户 时间 以及日志信息等等echo Following is the Commit COntent: >>D:/TempFIle/INFO_%RD%.txt 文本处理基本操作echo U means update_A means added new file_D means deleted>>D:/TempFIle/INFO_%RD%.txt 文本处理基本操作sed "1 i/Dear:" D:/TempFIle/INFO_%RD%.txt > D:/TempFIle/INFO_%RD%_1.txt 文本处理基本操作sed "3 i/COMMIT LOG MESSAGE :" D:/TempFIle/INFO_%RD%_1.txt > D:/TempFIle/INFO_%RD%_2.txt文本处理基本操作blat D:/TempFIle/INFO_%RD%_2.txt -to%user%@**.**.com -bcc *@*.*.com -cc *@*.*.com -base64 -charset Gb2312 -subject "Subversion_Notes_COmmit_User_%user%_Version_%REV%"-server *.*.*.com -u scm -****** -f[email=**@*.*.com]**@*.*.com[/email]del d:/tempfile/*%rd%*.txtexit 0

还有这里的sed命令是Linux下面的Shell命令
大家可以安装cygwin(http://www.cygwin.cn/site/install/),把%cygwin%/bin添加到%PATH%里面 就可以随意使用sed grep cut等灵活的Linux下面的命令了。

当然大家可以灵活修改这些脚本。可以实现锁定通知,解锁邮件通知等等功能。这些都是小Case了。

 

我的配置例子:

设置发送邮箱: blat -install smtp.163.com [email protected] -u mymailname -pwd mypassword 发邮件: blat d:/blat/body.txt -to [email protected] -base64 -charset utf-8 -subject "test" -server smtp.163.com -u bill -pw myPassword

 

bill的post-commit.bat的内容

@echo on

set REPOS=%1
set REV=%2
set RD=%RANDOM%
rem ::这个是产生随机数,为的是不要重复文件名。避免发生提交冲突
rem set COMMIT_USER_=echo C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook author %REPOS%

SET AUT_FILE=G:\blat\INFO_%RD%-AUTHOR-%REV%
C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook author -r %REV% %REPOS%>%AUT_FILE%
FOR /F %%A IN (%AUT_FILE%) DO SET AUTHOR=%%A

C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook info %REPOS% > G:\blat\INFO_%RD%.txt
rem ::获取执行提交的用户 时间 以及日志信息等等

echo. >>G:\blat\INFO_%RD%.txt
echo ********************以下是提交内容******************** >>G:\blat\INFO_%RD%.txt
rem ::文本处理基本操作
echo. >>G:\blat\INFO_%RD%.txt

echo ******************** 改变的文件 ******************** >>G:\blat\INFO_%RD%.txt
C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook changed %REPOS% >> G:\blat\INFO_%RD%.txt
rem ::获取执行提交的用户更改的文件
echo. >>G:\blat\INFO_%RD%.txt
echo ******************改变的代码请看附件****************** >>G:\blat\INFO_%RD%.txt

echo ******************** 改变的代码 ******************** >>G:\blat\INFO_%REV%_diff.txt
C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook diff %REPOS% >> G:\blat\INFO_%REV%_diff.txt
rem ::获取执行提交的用户更改的文件

rem rem c:\cygwin\bin\sed "1 i\Modified:" G:\blat\INFO_%RD%_1.txt >> G:\blat\INFO_%RD%.txt
rem ::文本处理基本操作

c:\cygwin\bin\unix2dos G:\blat\INFO_%REV%_diff.txt

rem ::sed "3 i\COMMIT LOG MESSAGE :" G:\blat\INFO_%RD%_1.txt > G:\blat\INFO_%RD%_2.txt ::文本处理基本操作

g:\blat\blat G:\blat\INFO_%RD%.txt -to [email protected],[email protected] -attach G:\blat\INFO_%REV%_diff.txt -base64 -charset Gb2312 -subject "Svn_T3_Commit_User_%AUTHOR%_Version_%REV%" -server smtp.163.com

del G:\blat\*%rd%*.txt
del G:\blat\*%REV%*.txt
del %AUT_FILE%

exit 0

 

高人的post-commit.bat的内容

@ECHO OFFSET REPOS=%1SET REV=%2SET SVNREP_DIR=C:/Documents and Settings/version_control/svn/sesameSET TRACDB_DIR=C:/Documents and Settings/version_control/trac/sesameSET PYTHON_DIR=C:/Python23SET SVN_DIR=C:/Program Files/SubversionSET HOOKS_DIR=%SVNREP_DIR%/hooksSET TRAC_ENV=%TRACDB_DIR%SET PYTHON="%PYTHON_DIR%/python.exe"SET SVN="%SVN_DIR%/bin/svn.exe"SET SVNADMIN="%SVN_DIR%/bin/svnadmin.exe"SET SVNLOOK="%SVN_DIR%/bin/svnlook.exe"::-----------------------------::Call the TRAC post-commit hook::SET TMP_LOG=%TEMP%./svnfileTMP-%REV%SET LOG_FILE=%TEMP%./svnfileR-%REV%svnlook log -r %REV% %REPOS%>%TMP_LOG%::napravi unicode cmd /c "type %TMP_LOG%>%LOG_FILE%"::type "%TMP_LOG%"SET AUT_FILE=%TEMP%./svnfileA-%REV%svnlook author -r %REV% %REPOS%>%AUT_FILE%:: SET THE AUTHOR FROM THE FILE. The file is expected to contain only one line with this valueFOR /F %%A IN (%AUT_FILE%) DO SET AUTHOR=%%A:: echo *** LOG FILE ***:: echo %REPOS%:%REV%>>log.txt:: echo %PYTHON% "%HOOKS_DIR%/trac-post-commit-hook" -p "%TRAC_ENV%" -r "%REV%" -u "%AUTHOR%" -m "file:%LOG_FILE%">>log.txttype %LOG_FILE%%PYTHON% "%HOOKS_DIR%/trac-post-commit-hook" -p "%TRAC_ENV%" -r "%REV%" -u "%AUTHOR%" -m "file:%LOG_FILE%"copy "%TMP_LOG%" "%HOOKS_DIR%"copy "%LOG_FILE%" "%HOOKS_DIR%"DEL %TMP_LOG%DEL %LOG_FILE%DEL %AUT_FILE%::::-----------------------------

 

在Dos测试方法(可以保存为bat批处理文件执行):

set REPOS=F:\Repositories\A10_4.0_v1.5
set REV=41
set RD=%RANDOM%
SET AUT_FILE=G:\blat\INFO_%RD%-AUTHOR-%REV%
C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook info %REPOS% > G:\blat\INFO_%RD%.txt
C:\"Program Files (x86)"\"VisualSVN Server"\bin\svnlook diff %REPOS% >> G:\blat\INFO_%REV%_diff.txt 
g:\blat\blat G:\blat\INFO_%RD%.txt -to 
liuyihui8@qq.com -attach G:\blat\INFO_%REV%_diff.txt -base64 -charset Gb2312 -subject "Svn_A10_4.0_v1.5_Commit_User_%AUTHOR%_Version_%REV%" -server smtp.163.com -u liuyihui8 -pwd password

   

你可能感兴趣的:(windows,SVN,python,File,subversion)