lint: Add checks for commit messages using gitlint.

Fixes #1131.
This commit is contained in:
Tommy Ip 2017-03-22 20:18:48 +00:00 committed by Tim Abbott
parent 7d8d9c1bf9
commit ec8e47192a
9 changed files with 61 additions and 4 deletions

11
.gitlint Normal file
View File

@ -0,0 +1,11 @@
[general]
ignore=title-trailing-punctuation, body-min-length, body-is-missing
[title-match-regex]
regex=^.+\.$
[title-max-length]
line-length=76
[body-max-line-length]
line-length=76

View File

@ -20,6 +20,7 @@ env:
- COVERALLS_SERVICE_NAME=travis-pro
- COVERALLS_REPO_TOKEN=hnXUEBKsORKHc8xIENGs9JjktlTb2HKlG
- BOTO_CONFIG=/tmp/nowhere
- UPSTREAM_MASTER=$(git ls-remote git://github.com/zulip/zulip.git refs/heads/master | cut -f 1)
language: python
matrix:
include:

View File

@ -21,6 +21,13 @@ pyflakes==1.5.0
# Needed to run tests in parallel
tblib==1.3.0
# Needed to lint Git commit messages
gitlint==0.8.1
# Needed for gitlint
arrow==0.10.0
sh==1.11
# Needed to sync translations from transifex
transifex-client==0.12.4

19
tools/commit-msg Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# This hook runs gitlint on your commit message.
# If your machine contains a provisioned Zulip development environment, the
# linter will be invoked through `vagrant ssh`.
lint_cmd="cd ~/zulip && cat \"$1\" | python -m gitlint.cli"
if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then
vagrant ssh -c "$lint_cmd"
else
$lint_cmd
fi
if [ $? -ne 0 ]; then
echo "WARNING: Your commit message does not match Zulip's style guide."
fi
exit 0

View File

@ -617,6 +617,9 @@ def run():
parser.add_option('--pep8',
action='store_true',
help='Run the pep8 checker')
parser.add_option('--no-gitlint',
action='store_true',
help='Disable gitlint')
parser.add_option('--modified', '-m',
action='store_true',
help='Only check modified files')
@ -687,6 +690,9 @@ def run():
external_linter('templates', ['tools/check-templates'], ['handlebars', 'html'])
external_linter('urls', ['tools/check-urls'])
if not options.no_gitlint:
external_linter('commit_messages', ['tools/lint-commits'])
@lint
def custom_py():
# type: () -> int

12
tools/lint-commits Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# Lints all commit messages that are newer than upstream/master.
# The rules can be found in /.gitlint
# If this script is running on TravisCI, $UPSTREAM_MASTER would be set to the
# latest HEAD in travis.yml
if [ ! $TRAVIS ]; then
UPSTREAM_MASTER=upstream/master
fi
gitlint --commits $UPSTREAM_MASTER...HEAD

View File

@ -16,10 +16,10 @@ if [ -z "$changed_files" ]; then
fi
if [ -z "$VIRTUAL_ENV" ] && `which vagrant > /dev/null` && [ -e .vagrant ]; then
vcmd="/srv/zulip/tools/lint-all --pep8 --force $changed_files || true"
vcmd="/srv/zulip/tools/lint-all --pep8 --no-gitlint --force $changed_files || true"
echo "Running lint-all using vagrant..."
vagrant ssh -c "$vcmd"
else
./tools/lint-all --pep8 --force $changed_files || true
./tools/lint-all --pep8 --no-gitlint --force $changed_files || true
fi
exit 0

View File

@ -6,6 +6,7 @@ if ! [ -d ".git/hooks/" ]; then
exit 1
fi
for hook in pre-commit; do
for hook in pre-commit commit-msg
do
ln -snf ../../tools/"$hook" .git/hooks/
done

View File

@ -1,2 +1,2 @@
ZULIP_VERSION = "1.5.1+git"
PROVISION_VERSION = '4.17'
PROVISION_VERSION = '4.18'