在我的公司,开发人员可能会使用togoise svn或eclipse svn或任何svn客户端,所以无论他们使用什么我想强制执行它们来提供一些提交消息和jira id。所以,我在hooks文件夹中的svn服务器中使用了下面的预提交shell脚本,并用乌龟测试,它不起作用。有人能帮我吗?
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
CURL=/usr/bin/curl
JIRAURL=http://our.jira.url:8080/rest/api/latest/issue
# Make sure that the log message contains some text.
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS")
echo ${LOGMSG} | grep "[a-zA-Z0-9]" > /dev/null || exit 1
check that log message starts with a JIRA ticket
should have format 'FOO-123: my commit message' or 'FOO-123 my commit message'
JIRAID=$(expr "${LOGMSG}" : '^\([A-Z]*-[0-9]*\)[: ].*')
if [[ "$JIRAID" == "" ]]
then
echo "No JIRA id found in log message \"${LOGMSG}\"" >&2
echo "Please use log message of the form \"JIRA-ID: My message\"" >&2
exit 1
fi
JIRAISSUE=$(${CURL} ${JIRAURL}/${JIRAID})
if [[ "${JIRAISSUE}" =~ "Issue Does Not Exist" ]]
then
echo "The JIRA id ${JIRAID} was not found" >&2
echo "Please use log message of the form \"JIRA-ID: My message\"" >&2
exit 1
fi
答案 0 :(得分:0)
这是一个简单的预提交钩子,只允许提交注释。
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[A-Z]*-[0-9]" > /dev/null
GREP_STATUS=$?
if [ $GREP_STATUS -ne 0 ]
then
echo "Commit denied" 1>&2
echo "Please write a comment to do the commit like" 1>&2
echo "JIRA-TICKET: Message" 1>&2
echo "Eg: FOO-123: Fix login bug" 1>&2
exit 1
fi
exit 0