Skip to content

Instantly share code, notes, and snippets.

@yamanyar
Created August 3, 2015 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamanyar/dfb411356104a5d2d7e6 to your computer and use it in GitHub Desktop.
Save yamanyar/dfb411356104a5d2d7e6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Pre recieve tests
NOREV=0000000000000000000000000000000000000000
while read oldsha newsha refname ; do
# deleting is always safe
if [[ $newsha == $NOREV ]]; then
continue
fi
# make log argument be "..$newsha" when creating new branch
if [[ $oldsha == $NOREV ]]; then
revs=$newsha
else
revs=$oldsha..$newsha
fi
echo $revs
########## Authentication Test Begins
# This test ensures that user's name (user.name config variable) and the user name used in http authentication are same.
commiter_names=$(git log --pretty=format:"%cn" $revs)
printf "$commiter_names\n" | while read name; do
if [[ $name != $GL_USER ]]; then
echo "Please configure your git name as $GL_USER . Now it is configured as $name !!!!"
exit 10
fi
done
[ "$?" -eq 10 ] && exit 10
########## Authentication Test Ends
########## Commit Message Test Begins
# This test updates JIRA with git commit messages accordingly.
# Expected commit message formats are such as follows :
#
# GIT-1 : Updates something --- adds comment to jira issue.
# GIT-1 resolve: Updates something -- resolves the issue and adds 'Updates something' as comment.
# GIT-1 reopen: Start working on something -- reopens the issue and adds 'Start working on something' as comment.
#
regex="^([A-Z]+-[0-9]+)\s(resolve|reopen)?:(.*)$"
commit_messages=$(git log --pretty=format:"%s" $revs)
printf "$commit_messages\n" | while read message; do
echo "Commenting $message"
#check whether commit message matches the expected message format
if [[ $message =~ $regex ]]; then
message_title="${message%%:*}"
message_comment="${message#*:}"
# get issue number
issue_number="${message_title% *}"
# get action to be executed (comment, resolve, reopen..)
action="${message_title#* }"
geera_show_output=`geera show $issue_number 2>&1`
if [[ "$geera_show_output" == *Exception* ]]; then
echo "The issue $issue_number does not exist or you don't have permission to view it."
exit 11
fi
if [[ "$action" == "" ]]; then
# add comment to the issue
geera_comment_output=`geera comment $issue_number -m "$message_comment" 2>&1`
if [[ "$geera_comment_output" != "" ]]; then
echo "$geera_comment_output"
exit 12
fi
elif [[ "$action" == "resolve" ]]; then
# resolve the issue
geera_output=`geera resolve $issue_number 2>&1`
if [[ "$geera_output" != "" ]]; then
echo "$geera_output"
exit 13
fi
geera_output=`geera comment $issue_number -m "$message_comment" 2>&1`
if [[ "$geera_output" != "" ]]; then
echo "$geera_output"
exit 14
fi
elif [[ "$action" == "reopen" ]]; then
# reopen the issue
geera_output=`geera reopen $issue_number 2>&1`
if [[ "$geera_output" != "" ]]; then
echo "$geera_output"
exit 15
fi
geera_output=`geera comment $issue_number -m "$message_comment" 2>&1`
if [[ "$geera_output" != "" ]]; then
echo "$geera_output"
exit 16
fi
fi
else
echo "Your commit message is not formatted correctly."
exit 17
fi
done
status_exit=$?
echo "Status Jira: $status_exit"
exit $status_exit
########## Commit Message Test Ends
done
status_exit=$?
echo "Status: $status_exit"
exit $status_exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment