From: Steven Dake Date: Thu, 28 Feb 2013 21:42:00 +0000 (-0700) Subject: Add N802 rule to hacking.py X-Git-Tag: 2014.1~817^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=137f9c0ad2b7c8d542c051ece2527b4c9d182817;p=openstack-build%2Fheat-build.git Add N802 rule to hacking.py Gate on commit headers < 50 characters Change-Id: Ia6a616d8a9b0eabca05a23476e284f261108b43a Fixes: Bug #1136386 --- diff --git a/HACKING.rst b/HACKING.rst index 2692e7af..41dc8cbb 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 diff --git a/tools/hacking.py b/tools/hacking.py index 04a412e9..c64f86c7 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -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"