Project

General

Profile

pre-commit svn hook to check that the commit is being done by the task assignee

Added by Patrick Tyler over 4 years ago

Hi,

I have taken over administration of our Redmine server that has the pre-commit hook below. I would like to add a check to ensure that the person doing the commit is the same person that the task is assigned to...any help much appreciated!

Thanks,
Patrick

#!/bin/sh

  1. PRE-COMMIT HOOK

REPOS="$1"
TXN="$2"
SVNLOOK=/home/svn/csvn/bin/svnlook
ISSUE_PRESENT=0
MESSAGE_PRESENT=0
ISSUES_OPEN=1
MYSQL=mysql

MESSAGE=$($SVNLOOK log -t "$TXN" "$REPOS")
REGEX="^refs\s*#([0-9]+)"

for word in ${MESSAGE[@]}; do
if ${word} =~ "; #search string for an issue match of form #nnnn
then
#matched an issue# check it's valid and store the fact that we've found at least 1 issue#
ISSUE_PRESENT=1
REDMINE_ISSUE=${BASH_REMATCH1}
REDMINE_ISSUE_OPEN=$(${MYSQL} -u readonly -h whl-redmine3.mycompany.com -D redmine -sN -e "SELECT COUNT() FROM issues I INNER JOIN issue_statuses S ON S.id = I.status_id WHERE S.is_closed = 0 AND I.id = ${REDMINE_ISSUE};")
REDMINE_ISSUE_NEW=$(${MYSQL} -u readonly -h whl-redmine3.mycompany.com -D redmine -sN -e "SELECT COUNT(
) FROM issues WHERE status_id= 1 AND id = ${REDMINE_ISSUE};")

if [[ ${REDMINE_ISSUE_OPEN} -eq 0 ]];
then
ISSUES_OPEN=0
echo "Redmine issue #${REDMINE_ISSUE} is in a closed state." 1>&2;
fi
if [[ ${REDMINE_ISSUE_NEW} -eq 1 ]]; 
then
ISSUES_OPEN=0
echo "Redmine issue #${REDMINE_ISSUE} is in New state. Please refer to SCCB." 1>&2;
fi
else
MESSAGE_PRESENT=1 || $MESSAGE_PRESENT;
fi
done

if [ ${MESSAGE_PRESENT} -eq 0 ]
then
echo "No log message" 1>&2
fi
if [ ${ISSUE_PRESENT} -eq 0 ]
then
echo "No issue number" 1>&2
fi

if [ ${ISSUE_PRESENT} -eq 0 ] || [ ${MESSAGE_PRESENT} -eq 0 ] || [ ${ISSUES_OPEN} -eq 0 ]
then
exit 1
fi
exit 0