在svn服务端版本库找到 hooks文件夹

svn提交事务完成后触发,将commit内容提交到外部api

mv post-commit.tmpl post-commit
#!/bin/sh
export LANG=en_US.UTF-8

REPOS="$1"
REV="$2"
TXN_NAME="$3"

SVN=/usr/bin/svn
SVNLOOK=/usr/bin/svnlook
NEW_VER=`$SVNLOOK youngest $REPOS`

# 修改文件
changeFile=$($SVNLOOK changed  -r $NEW_VER $REPOS)
# 操作人
author=$($SVNLOOK author -r $NEW_VER $REPOS)
# commit
commit=$($SVNLOOK log $REPOS)

param="changeFile=$changeFile&author=$author&commit=$commit"

curl -X POST -d "$param" http://127.0.0.1/hook-svn

svn提交事务开始,验证commit内容格式

mv pre-commit.tmpl pre-commit
#!/bin/sh
export LANG=en_US.UTF-8

REPOS="$1"
TXN="$2"

# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook

COMMIT=`$SVNLOOK log -t "$TXN" "$REPOS"`

COMMIT=$(echo $COMMIT | sed 's/ //g')

# 验证内容是否为空
if [ -z $COMMIT ]; then
  echo '提交的注释不能为空' 1>&2
  exit 1
fi

num=`echo ${COMMIT}|egrep -c '(bug|task|story)-view-[0-9]+'`

if [ $num -eq 0 ];then
    echo "[$COMMIT]-未包l关键字,格式应为:(story|task|bug)-view-"'${id}' 1>&2
    exit 1
fi

# Exit on all errors.
set -e

# All checks passed, so allow the commit.
exit 0

svn命令参考