]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add N802 rule to hacking.py
authorSteven Dake <sdake@redhat.com>
Thu, 28 Feb 2013 21:42:00 +0000 (14:42 -0700)
committerSteven Dake <sdake@redhat.com>
Mon, 4 Mar 2013 18:20:31 +0000 (11:20 -0700)
Gate on commit headers < 50 characters

Change-Id: Ia6a616d8a9b0eabca05a23476e284f261108b43a
Fixes: Bug #1136386
HACKING.rst
tools/hacking.py

index 2692e7af5ff67284a648d2729e18cf83840edac7..41dc8cbba6bc6edff697b1aca118d51bacd281df 100644 (file)
@@ -271,8 +271,7 @@ Commit Messages
 Using a common format for commit messages will help keep our git history
 readable. Follow these guidelines:
 
-  First, provide a brief summary (it is recommended to keep the commit title
-  under 50 chars).
+  First, provide a brief summary 72 characters in length or less.
 
   The first line of the commit message should provide an accurate
   description of the change, not just a reference to a bug or
index 04a412e98afd9f440b731e8b78df85ad0c85770f..c64f86c7b4a0c95b6e2cba833721babc4bdfea6d 100755 (executable)
@@ -559,6 +559,43 @@ def add_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
+    N802 Title limited to 72 chars
+    """
+    #Get title of most recent commit
+
+    subp = subprocess.Popen(['git', 'log', '--no-merges', '--pretty=%s', '-1'],
+            stdout=subprocess.PIPE)
+    title = subp.communicate()[0]
+    if subp.returncode:
+        raise Exception("git log failed with code %s" % subp.returncode)
+
+    #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)
+
+    error = False
+    #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())
+        error = True
+    if len(title.decode('utf-8')) > 72:
+        print ("N802: git commit title ('%s') should be under 72 chars"
+                % title.strip())
+        error = True
+    return error
+
 imports_on_separate_lines_N301_compliant = r"""
     Imports should usually be on separate lines.
 
@@ -576,6 +613,7 @@ if __name__ == "__main__":
     #include nova path
     sys.path.append(os.getcwd())
     #Run once tests (not per line)
+    once_error = once_git_check_commit_title()
     #NOVA error codes start with an N
     pep8.SELFTEST_REGEX = re.compile(r'(Okay|[EWN]\d{3}):\s(.*)')
     pep8.ERRORCODE_REGEX = re.compile(r'[EWN]\d{3}')
@@ -590,6 +628,7 @@ if __name__ == "__main__":
 
     try:
         pep8._main()
+        sys.exit(once_error)
     finally:
         if len(_missingImport) > 0:
             print >> sys.stderr, ("%i imports missing in this test environment"