#!/bin/bash
# Yes, this script can be improved immensly...
cd ..
result=0
echo "No subjects are of invalid size
" > too_long_subjects.txt
echo "No subjects with leading lower case characters
" > leading_lowercases.txt
echo "No subjects with trailing periods
" > trailing_periods.txt
echo "No body lines are too wide
" > too_long_body_lines.txt
too_long_subjects=`awk 'length > 50' subjects.txt`
if [ -n "$too_long_subjects" ]; then
echo "Commit subjects that are too wide (>50 characters):" > too_long_subjects.txt
echo "$too_long_subjects" >> too_long_subjects.txt
sed -i -e 's/$/
/' too_long_subjects.txt
result=1
fi
leading_lowercases=`awk '/^[[:lower:][:punct:]]/' subjects.txt`
if [ -n "$leading_lowercases" ]; then
echo "Commit subjects with leading lowercase characters:" > leading_lowercases.txt
echo "$leading_lowercases" >> leading_lowercases.txt
sed -i -e 's/$/
/' leading_lowercases.txt
result=1
fi
trailing_periods=`awk '/(\.)$/' subjects.txt`
if [ -n "$trailing_periods" ]; then
echo "Commit subjects with trailing periods:" > trailing_periods.txt
echo "$trailing_periods" >> trailing_periods.txt
sed -i -e 's/$/
/' trailing_periods.txt
result=1
fi
too_long_body_lines=`awk 'length > 72' bodies.txt`
if [ -n "$too_long_body_lines" ]; then
echo "Body lines that are too wide (>72 characters):" > too_long_body_lines.txt
echo "$too_long_body_lines" >> too_long_body_lines.txt
sed -i -e 's/$/
/' too_long_body_lines.txt
result=1
fi
printf "%s" "" > gitler.html
awk 'FNR==1{print "
"}1' too_long_subjects.txt leading_lowercases.txt trailing_periods.txt too_long_body_lines.txt >> gitler.html
echo "
" >> gitler.html
if [ $result -ne 0 ]; then
echo "You should follow this guide when writing your commit messages.
" >> gitler.html
echo "
" >> gitler.html
echo "To change the commit message for a single-commit pull request:
" >> gitler.html
echo "git checkout <your_branch>
" >> gitler.html
echo "git commit --amend
" >> gitler.html
echo "git push origin HEAD:<your_branch_on_github> -f
" >> gitler.html
echo "
" >> gitler.html
echo "To change the commit messages for a multiple-commit pull request:
" >> gitler.html
echo "git checkout <your_branch>
" >> gitler.html
echo "git rebase -i <sha_of_parent_to_the_earliest_commit_you_want_to_change>
" >> gitler.html
echo "Replace \"pick\" with \"r\" or \"reword\" on the commits you need to change message for
" >> gitler.html
echo "git push origin HEAD:<your_branch_on_github> -f
" >> gitler.html
echo "
" >> gitler.html
fi
# Evaluate coding style
astyle --options=.mystools/astyle/config/style.cfg -nq --recursive "*.h" "*.c" "*.cpp"
git diff > restyling.patch
if [ -s restyling.patch ]; then
echo "This commit is not meeting the coding standards, a mail with a patch has been sent to you that if applied to your PR, will make it meet the coding standards.
" >> gitler.html
echo "You apply the patch using:
" >> gitler.html
echo "git apply restyling.patch
" >> gitler.html
echo "
" >> gitler.html
result=1
else
echo "This commit is meeting the coding standards, congratulations!
" >> gitler.html
echo "
" >> gitler.html
rm restyling.patch
fi
# Evaluate if there exists booleans in the code tree (not counting this file)
if git grep -q boolean -- `git ls-files | grep -v gitler.sh`
then
echo "This repository currently contain the boolean keyword. This should be avoided.
" >> gitler.html
echo "
" >> gitler.html
result=1
else
echo "This repository does not contain any boolean keywords. This is good.
" >> gitler.html
echo "
" >> gitler.html
fi
if [ $result -ne 0 ]; then
echo "If you disagree to this, please discuss it in the GitHub pull request thread.
" >> gitler.html
echo "
" >> gitler.html
fi
echo "Yours sincerely, Gitler, on behalf of Jenkins
" >> gitler.html
printf "%s" "" >> gitler.html
exit $result