summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2012-07-18 15:22:09 -0700
committerJoe Gordon <jogo@cloudscaling.com>2012-07-20 15:19:15 -0700
commit7a376fa48b8230b8cfebafeaf28ca879216d42a9 (patch)
tree2a7ac7d3f5e43a6ee861d71d3567e1692304aa62
parent5ac7076255946caf59e5d0410e47841b38ceadc3 (diff)
downloadnova-7a376fa48b8230b8cfebafeaf28ca879216d42a9.tar.gz
nova-7a376fa48b8230b8cfebafeaf28ca879216d42a9.tar.xz
nova-7a376fa48b8230b8cfebafeaf28ca879216d42a9.zip
Add git commit message validation to hacking.py
Adds N801: git commit title should provide a description Change-Id: Ic6334b20f5f06631b7a5579a4d1b2303685463eb
-rwxr-xr-xtools/hacking.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tools/hacking.py b/tools/hacking.py
index 2d8ce92bc..3f876b747 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -25,6 +25,7 @@ import inspect
import logging
import os
import re
+import subprocess
import sys
import tokenize
import warnings
@@ -39,8 +40,9 @@ logging.disable('LOG')
#N3xx imports
#N4xx docstrings
#N5xx dictionaries/lists
-#N6xx Calling methods
+#N6xx calling methods
#N7xx localization
+#N8xx git commit messages
IMPORT_EXCEPTIONS = ['sqlalchemy', 'migrate', 'nova.db.sqlalchemy.session']
DOCSTRING_TRIPLE = ['"""', "'''"]
@@ -375,9 +377,35 @@ def add_nova():
if args and name.startswith("nova"):
exec("pep8.%s = %s" % (name, name))
+
+def once_git_check_commit_title():
+ """Check git commit messages.
+
+ nova HACKING recommends not referencing a bug or blueprint in first line,
+ it should provide an accurate description of the change
+ N801
+ """
+ #Get title of most recent commit
+ title = subprocess.check_output('git log --pretty=%s -1', shell=True)
+ #From https://github.com/openstack/openstack-ci-puppet
+ # /blob/master/modules/gerrit/manifests/init.pp#L74
+ #Changeid|bug|blueprint
+ git_keywords = (r'(I[0-9a-f]{8,40})|'
+ '([Bb]ug|[Ll][Pp])[\s\#:]*(\d+)|'
+ '([Bb]lue[Pp]rint|[Bb][Pp])[\s\#:]*([A-Za-z0-9\\-]+)')
+ GIT_REGEX = re.compile(git_keywords)
+
+ #NOTE(jogo) if match regex but over 3 words, acceptable title
+ if GIT_REGEX.search(title) is not None and len(title.split()) <= 3:
+ print ("N801: git commit title ('%s') should provide an accurate "
+ "description of the change, not just a reference to a bug "
+ "or blueprint" % title.strip())
+
if __name__ == "__main__":
#include nova path
sys.path.append(os.getcwd())
+ #Run once tests (not per line)
+ once_git_check_commit_title()
#NOVA error codes start with an N
pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}')
add_nova()