Last active
August 12, 2017 09:12
-
-
Save xu3352/82c843e88101fd889dcd6a3e2f1c245e to your computer and use it in GitHub Desktop.
SVN:pre-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#author:[email protected] | |
#desc:check commit message length | |
REPOS="$1" | |
TXN="$2" | |
SVNLOOK=/usr/local/bin/svnlook | |
TIME=`date "+%Y-%m-%d %H:%M:%S"` | |
# env setting | |
envSetting="env LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8" | |
# commit message content | |
MSG=`$envSetting $SVNLOOK log -t "$TXN" "$REPOS"` | |
# chars length | |
# MSG_LEN=`echo $MSG | wc -m` | |
MSG_LEN=`python -c "import sys; print len(sys.argv[1].decode(\"UTF-8\"))" "$MSG"` | |
echo "$TIME - pre-commit - REPOS:$REPOS TXN:$TXN MSG_LENGTH:$MSG_LEN - MSG:$MSG" >> /tmp/svn-pre-commit.log | |
# message content must greater than 20 chars | |
if [ "$MSG_LEN" -lt 20 ]; | |
then | |
echo -e "\"$MSG\" 不能少于 20 个字!" 1>&2 | |
exit 1 | |
fi | |
# message content must matching target chars | |
JIRA_NUM=`echo "$MSG" | grep "\(WX\|SD\|YD\|INTERFACE\)-[0-9]\+" | wc -m` | |
if [ "$JIRA_NUM" -lt 2 ]; | |
then | |
echo -e "\"$MSG\" 没有对应项目的 JIRA 编号!" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment