From 409edf902f8ce93f6b1bb48234ca2bed252e075a Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Fri, 17 Jul 2015 19:15:21 +0000 Subject: [PATCH] improve SHA detection Be more explicit about how we check for a SHA, instead of just checking a few commonly used names. Change-Id: I3878159f45d40bb0291a8352c0e6485a84a165e0 --- tools/validate.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/validate.py b/tools/validate.py index cc3bb10d61..73608580f3 100755 --- a/tools/validate.py +++ b/tools/validate.py @@ -22,6 +22,7 @@ from __future__ import print_function import argparse import glob +import re import subprocess import sys @@ -36,13 +37,6 @@ DEFAULT_RELEASE = 'liberty' CGIT_TEMPLATE = 'http://git.openstack.org/cgit/%s/commit/?id=%s' -COMMON_NAMES = set([ - 'master', - 'HEAD', - 'origin/master', - 'gerrit/master', -]) - def find_modified_deliverable_files(): "Return a list of files modified by the most recent commit." @@ -57,6 +51,11 @@ def find_modified_deliverable_files(): return filenames +def is_a_hash(val): + "Return bool indicating if val looks like a valid hash." + return re.search('^[a-f0-9]{40}$', val, re.I) is not None + + def main(): parser = argparse.ArgumentParser() parser.add_argument( @@ -102,7 +101,7 @@ def main(): project['hash']), end='') - if project['hash'] in COMMON_NAMES: + if not is_a_hash(project['hash']): print('NOT A SHA HASH') num_errors += 1 else: