VisualSvn Server的钩子脚本

VisualSvn Server是windows下免费的源代码控制管理工具,最近闲得蛋疼,特地写了如下钩子脚本,供大家使用.
#=================precommit===========================================
@echo off
setlocal
set REPOS=%1
set REV=%2
set svnlook="D:\Program Files\VisualSVN Server\bin\svnlook.exe"
rem check that logmessage contains at least 10 characters
%svnlook% log "%REPOS%" -t "%REV%" | findstr ".........." > nul
if %errorlevel% gtr 0 goto err
echo 提交的log信息要大于10个字符,请重新提交! 1>&2
exit 0
:err
echo 提交被阻止,请填写关于此次修改的log信息(需大于10个字符),然后再重新提交! 1>&2
exit 1
#=================post commit==============================================
@echo off
setlocal
set REPOS=%1
set REV=%2
set [email protected]
set [email protected]
set mailServer=smtp-server svr557hp380.cn1.global.ctrip.com
"%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
commit-notification "%REPOS%" -r "%REV%" ^
--from %poster% --to %accepter% ^
--%mailServer% ^
--encoding utf-8

#=================pre-revision property-change==============================================
@ECHO OFF
REM 限制日志文件的个数采用修改项目属性的tsvn:logminsize,不在脚本中限制
REM 参数
set REPOS=%1
set REV=%2
set USER=%3
set PROPNAME=%4
set ACTION=%5
set svnlook="D:\Program Files\VisualSVN Server\bin\svnlook.exe"
REM 设置超级用户,超级用户可以修改其他人的日志,其他人只能修改自己的日志
set superUser=yfzheng
REM 只允许日志svn:log的修改
if /I not '%PROPNAME%'=='svn:log' goto ERROR_PROPNAME
REM 只允许修改日志,增加、删除等操作不允许
if /I not '%ACTION%'=='M' goto ERROR_ACTION
REM 只允许用户修改自己的日志
for /f  "usebackq" %%k in   (`%svnlook% author %REPOS% -r %REV%`) do @set var=%%k
set rightUser=0
if "%USER%" == "%superUser%"  set rightUser=1
if "%USER%" == "%var%" set rightUser=1
if %rightUser% == 0 goto ERROR_USER
goto :SUCCESS_EXIT
:ERROR_USER
echo 只允许用户修改自己的日志 >&2
goto ERROR_EXIT
:ERROR_PROPNAME
echo 只有日志信息能被修改 >&2
goto ERROR_EXIT
:ERROR_ACTION
echo 只允许修改日志,不允许增加、删除等操作 >&2
goto ERROR_EXIT
:ERROR_EXIT
exit 1
:SUCCESS_EXIT
exit 0
#=================post-revision property-change==============================================
@echo off
setlocal
set REPOS=%1
set REV=%2
set USER=%3
set PROPNAME=%4
set ACTION=%5
set poster=%USER%
set [email protected]
set mailServer=smtp-server svr557hp380.cn1.global.ctrip.com
"%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
commit-notification "%REPOS%" -r "%REV%" -m %PROPNAME% ^
--from %poster% --to %accepter% ^
--%mailServer% ^
--encoding utf-8

linux下的SVN钩子
#========pre-commit==用纯shell方法================


#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[^[:space:]]" | wc -c`
if [ "$LOGMSG" -lt 5 ];
then
  echo "Log message cann't be empty! you must input more than 5 chars as comment!." 1>&2
  exit 1
fi
exit 0
#=======post-commit====================


#!/bin/bash
REPOS=$1
REV=$2
[email protected]
[email protected]
LIMITDIFF=200
CHANGELOG=`svnlook log -r $REV $REPOS`
AUTHOR=`svnlook author -r $REV $REPOS`
CHANGED=`svnlook changed -r $REV $REPOS`
DIFF=`svnlook diff -r $REV $REPOS | head --lines=$LIMITDIFF`
DATE=`date`
TMPFILE=/tmp/svn$REV-$RANDOM.message
SUBJECT="SVNCommit ($AUTHOR) $REPOS [$REV]"
echo "-------------------- SVN Commit Notification --------------------
Repository: $REPOS
Revision:   $REV
Author:     $AUTHOR
Date:       $DATE
Log Message:
$CHANGELOG
Changes:
-----------------------------------------------------------------
$CHANGED
-----------------------------------------------------------------
Diff: (only first $LIMITDIFF lines shown)
-----------------------------------------------------------------
$DIFF
" > $TMPFILE
# Send email
cat $TMPFILE | mail -a "From: $SENDFROM" -s "$SUBJECT" "$SENDTO"
# Cleanup
rm $TMPFILE

#=======post-commit======用svnnotify方法===============


REPOS="$1"
REV="$2"

/usr/bin/svnnotify --repos-path "$REPOS" \
        --revision $REV \
        -f "[email protected]" \
        -t "[email protected]" \
        --smtp "smtp.163.com" \
        --smtp-user "[email protected]" \
        --smtp-pass "" \
        --smtp-authtype "LOGIN PLAIN"

你可能感兴趣的:(server)