Windows

windows post-commit blat

Naan 2013. 2. 26. 22:05
반응형

이번엔 blat 를 사용하는 방법으로 post-commit 하는 방법이다.

http://www.blat.net/

사이트에서 파일 다운로드 후 c:\blat 폴더에 푼다

압축 풀어보면 blat310\full\blat.exe 파일이 보일것이다. 이것을 이용한 방법이다.

post-commit.bat 파일을 만든다. 아래 내용을 넣고 자기 환경에 맞춰서 수정하면 된다.(빨간부분과 자기 입맛에 맞춰서 수정하면 된다.)

사용하다 보니.. blat 큰 단점이 있다. 메일 발송시 엄청난 딜레이가 생긴다 10~12초

sendEmail.exe 을 사용하면 4~5초대로 메일 발송이 가능하다.

맨 마지막줄 수정하면 된다.

"%emailDir%sendemail.exe" -o message-file=%tmpFile% -f %sendFrom% -t %sendTo% -u "%subject%" -s %emailServer%:%emailPort% -xu %emailUid% -xp %emailPwd%


ECHO OFF REM ===================================================================================== REM Copyright 2011 Weizh Chang REM REM This program is free software: you can redistribute it and/or modify REM it under the terms of the GNU General Public License as published by REM the Free Software Foundation, either version 3 of the License, or REM (at your option) any later version. REM REM This program is distributed in the hope that it will be useful, REM but WITHOUT ANY WARRANTY; without even the implied warranty of REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the REM GNU General Public License for more details. REM REM You should have received a copy of the GNU General Public License REM along with this program. If not, see <http://www.gnu.org/licenses/>. REM REM REM This script is inspired by 'SVN Post-Commit Automatic Email' by Andrew Farley REM (andrewfarley.com/sysadmin/svn-commit-automatic-email). REM ===================================================================================== REM ===================================================================================== REM Program : Weizh SVN Post-Commit Email Batch Script REM File : weizh-post-commit-email.bat REM Version : 1.0.0.0 REM URL : simpcode.blogspot.com REM Description: REM REM Please change the settings in the Begin/End Settings section below. REM REM This script requires: REM - post-commit.bat (the caller). REM - blat emailer tool (www.blat.net). REM - usermap (optional - see below). REM REM Features: REM - Sends SVN post commit email notification. REM - Allows multiple common email recipients for all repositories. REM - Allows multiple custom email recipients for each repository. REM - Option to include the SVN Diff in the email. REM - Option to skip sending email using the 'no email' tag in the log. REM - Option to use usermap (see below). REM REM REM usermap: REM This script is able to read the authorized svn users from conf\authz, and map to REM the users' emails in a 'usermap' file. These emails will be used as part of REM the receiver emails. This feature can be disabled by changing the REM Settings' usermap to empty. REM REM The following example shows how a 'usermap' file content may look like: REM REM harry=name=Harry Smith REM harry=email=harry@example.com REM REM sally=name=Sally Anderson REM sally=email=sally@example.com,sally@example2.com REM ===================================================================================== ECHO ON SET repos=%1 SET rev=%2 SET reposName=%3 SET sendTo=%4 SET sendToCc=%5 REM ================ Begin Settings ==================== REM ==== Set email settings SET emailServer=mail.example.com SET emailPort=25 SET emailUid=admin@example.com SET emailPwd=adminPassw0rd SET sendFrom=admin@example.com SET sendTry=5 REM ==== Set common receiver/cc email (comma separated, without quotes and spaces) SET sendToCommon=michelle@example.com,alex@example.com SET sendToCcCommon= REM ==== Set the blat exe directory SET emailDir=C:\blat\full\ REM ==== Set the SVN bin directory SET svnDir=C:\svnserve\bin\ REM ==== Set the SVN Diff line limit (-1 to not show any) SET limitDiff=-1 REM ==== Set the usermap file location (leave empty if not using usermap) SET usermap=D:\svn_repos\scripts\usermap REM ==== Set no email tag. If this tag exists at the beginning of a line in the log, REM ==== no email will be sent (leave empty if not using this feature) SET noEmailTag=[noemail] REM ================ End Settings ====================== REM ==== Remove surrounding quotes SET repos=%repos:"=% SET rev=%rev:"=% SET reposName=%reposName:"=% SET sendTo=%sendTo:"=% SET sendToCc=%sendToCc:"=% REM ==== Set reposName to repos if empty IF "%reposName%"=="" SET reposName=%repos% REM ==== Get svn author FOR /F "tokens=*" %%R IN ('"%svnDir%svnlook.exe" author -r %rev% %repos%') DO SET author=%%R SET authorName= REM ==== Set email temp file SET tmpFile=%~dp0svn-email-%rev%-%RANDOM%.tmp REM ================ Begin Read Usermap ================ REM ==== Skip if usermap not exist IF "%usermap%"=="" GOTO SendEmail IF NOT EXIST %usermap% GOTO SendEmail SETLOCAL ENABLEDELAYEDEXPANSION REM ==== Set authz file SET reposAuthz=%repos:/=\%\conf\authz SET sendToMap= SET authorName= FOR /F "tokens=1,2,3 delims==" %%A IN (%usermap%) DO ( IF NOT "%%%A:~0,1%"=="#" ( IF "%%B"=="email" ( IF NOT "%%C"=="" ( SET count=0                 REM ==== If user exists in authz, append the emails to sendToMap FOR /F "tokens=1 delims==" %%U IN ('FINDSTR /I /B "%%A.*\=.*r" %reposAuthz%') DO (                     REM ==== Remove any spaces FOR /F "tokens=1 delims= " %%Y IN ("%%U") DO ( IF "%%Y"=="%%A" ( IF !count!==0 ( IF NOT "!sendToMap!"=="" SET sendToMap=!sendToMap!, SET sendToMap=!sendToMap!%%C SET count=1 ) ) ) ) ) ) ELSE ( IF "%%B"=="name" ( IF "%%A"=="%author%" SET authorName=%%C ) ) ) ) SET mapReturns=^ SET sendToMap=%sendToMap%^&^ SET authorName=%authorName% ENDLOCAL & %mapReturns% REM ==== Append to the existing sendTo IF NOT "%sendToMap%"=="" ( IF NOT "%sendTo%"=="" SET sendTo=%sendTo%, ) SET sendTo=%sendTo%%sendToMap% REM ================ End Read Usermap ================== :SendEmail REM ==== Append any common emails IF NOT "%sendToCommon%"=="" ( IF NOT "%sendTo%"=="" SET sendTo=%sendTo%, ) SET sendTo=%sendTo%%sendToCommon% IF NOT "%sendToCcCommon%"=="" ( IF NOT "%sendToCc%"=="" SET sendToCc=%sendToCc%, ) SET sendToCc=%sendToCc%%sendToCcCommon% REM ==== Exit if sendTo is empty IF "%sendTo%"=="" GOTO Finish REM ==== Set sendTo with surrounding quotes SET sendTo="%sendTo%" REM ==== Set sendToCc with argument switch and surrounding quotes IF NOT "%sendToCc%"=="" SET sendToCc=-cc "%sendToCc%" REM ==== Get svn date and time FOR /F "tokens=1,2" %%R IN ('"%svnDir%svnlook.exe" date -r %rev% %repos%') DO ( SET svnDate=%%R SET svnTime=%%S ) REM ==== Set email subject SET subject=[%reposName%] SVNCommit (%author%) Rev: %rev% REM ==== Set email body ( ECHO Dear Developers, ECHO. IF NOT "%authorName%"=="" ( ECHO There is an SVN Commit on [ %reposName% ] by %authorName% ^(%author%^). ) ELSE ( ECHO There is an SVN Commit on [ %reposName% ] by %author%. ) ECHO Please SVN Update your working copy. ECHO. ECHO. ECHO -------------------- SVN Commit Notification -------------------- ECHO Repository: %reposName% ECHO Revision: %rev% ECHO Author: %author% ECHO Date: %svnDate% Time: %svnTime% ECHO. ECHO ----------------------------------------------------------------- ECHO Log Message: ECHO ----------------------------------------------------------------- ) >%tmpFile% REM ==== Get svn log FOR /F "tokens=*" %%R IN ('"%svnDir%svnlook.exe" log -r %rev% %repos%') DO ECHO %%R >>%tmpFile% REM ==== If the 'no email tag' exists in the log, exit without sending email IF NOT "%noEmailTag%"=="" ( FOR /F "tokens=*" %%E IN ('FINDSTR /I /B /C:"%noEmailTag%" %tmpFile%') DO GOTO Finish ) ( ECHO. ECHO ----------------------------------------------------------------- ECHO Changes: ECHO ----------------------------------------------------------------- ) >>%tmpFile% REM ==== Get svn changed FOR /F "tokens=*" %%R IN ('"%svnDir%svnlook.exe" changed -r %rev% %repos%') DO ECHO %%R >>%tmpFile% IF NOT "%limitDiff%"=="-1" ( ( ECHO. ECHO ----------------------------------------------------------------- ECHO Diff: ^(only first %limitDiff% lines shown^) ECHO ----------------------------------------------------------------- ) >>%tmpFile% REM ==== Get svn diff FOR /F "tokens=*" %%R IN ('"%svnDir%svnlook.exe" diff -r %rev% %repos% ^| head --lines=%limitDiff%') DO ECHO %%R >>%tmpFile% ) ( ECHO. ECHO. ECHO Regards, ECHO SVN Server Admin ) >>%tmpFile% REM ==== Send email "%emailDir%blat.exe" %tmpFile% -server %emailServer%:%emailPort% -f %emailUid% -u %emailUid% -pw %emailPwd% -from %sendFrom% -to %sendTo% %sendToCc% -subject "%subject%" -try %sendTry% :Finish REM ==== Cleanup IF EXIST %tmpFile% DEL /Q %tmpFile%


post-commit hook 에 아래 내용 추가

SET repos=%1 SET rev=%2 REM ==== Set repository name for display only, if empty will be same as repos SET reposName= REM ==== Set receiver/cc email (comma separated, without quotes and spaces) SET sendTo= SET sendToCc= D:\svn_repos\scripts\post-commit.bat.bat "%repos%" "%rev%" "%reposName%" "%sendTo%" "%sendToCc%"



http://simpcode.blogspot.kr/2011/10/subversion-post-commit-email.html 출처

반응형