Merge "Check for valid upstream git projects"

This commit is contained in:
Jenkins
2015-10-22 09:08:04 +00:00
committed by Gerrit Code Review
2 changed files with 128 additions and 77 deletions

View File

@@ -15,17 +15,60 @@
# limitations under the License. # limitations under the License.
import argparse import argparse
import contextlib
import git
import re import re
import shutil
import sys import sys
import tempfile
import yaml import yaml
found_errors = 0
@contextlib.contextmanager
def tempdir():
try:
reqroot = tempfile.mkdtemp()
yield reqroot
finally:
shutil.rmtree(reqroot)
def check_repo(repo_path):
global found_errors
print("Checking git repo '%s':" % repo_path)
with tempdir() as repopath:
repo = git.Repo.clone_from(repo_path, repopath)
remotes = repo.git.branch('--remote')
branches = [r.strip() for r in remotes.splitlines() if r.strip()]
print (" Remote branches:")
for r in branches:
print(" %s" % r)
if 'origin/master' in branches:
print(" Master branch exists.")
else:
found_errors += 1
print(" Error: No master branch exists")
if repo.tags:
print(" Found the following tags:")
for tag in repo.tags:
print(" %s" % tag)
else:
print(" Found no tags.")
# Just an empty line for nicer formatting
print("")
def main():
global found_errors
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', parser.add_argument('-v', '--verbose',
dest='verbose', dest='verbose',
default=False, default=False,
action='store_true', action='store_true')
)
parser.add_argument( parser.add_argument(
'infile', 'infile',
help='Path to gerrit/projects.yaml', help='Path to gerrit/projects.yaml',
@@ -41,7 +84,6 @@ VALID_SCHEMES = ['https://', 'http://', 'git://']
DESCRIPTION_REQUIRED = ['openstack', 'openstack-infra', 'openstack-dev', DESCRIPTION_REQUIRED = ['openstack', 'openstack-infra', 'openstack-dev',
'stackforge'] 'stackforge']
found_errors = 0
for p in projects: for p in projects:
name = p.get('project') name = p.get('project')
repo_group = name.split('/')[0] repo_group = name.split('/')[0]
@@ -69,7 +111,8 @@ for p in projects:
# sort of job-description (e.g. "foo-devstack-bar") or # sort of job-description (e.g. "foo-devstack-bar") or
# a url ("foo.openstack.org") # a url ("foo.openstack.org")
if re.search(r'(?<![-.])\b%s\b' % word, description): if re.search(r'(?<![-.])\b%s\b' % word, description):
print "Error: %s: should be %s" % (description, should_be) print("Error: %s: should be %s" %
(description, should_be))
found_errors += 1 found_errors += 1
if not description and repo_group in DESCRIPTION_REQUIRED: if not description and repo_group in DESCRIPTION_REQUIRED:
@@ -80,6 +123,8 @@ for p in projects:
# Allow git:// and https:// URLs for importing upstream repositories, # Allow git:// and https:// URLs for importing upstream repositories,
# but not git@ # but not git@
upstream = p.get('upstream') upstream = p.get('upstream')
if upstream and 'track-upstream' not in p.get('options', []):
check_repo(upstream)
if upstream: if upstream:
for prefix in VALID_SCHEMES: for prefix in VALID_SCHEMES:
if upstream.startswith(prefix): if upstream.startswith(prefix):
@@ -96,8 +141,13 @@ for p in projects:
break break
else: else:
found_errors += 1 found_errors += 1
print("Error: Unknown keyword '%s' in project %s" % (entry, name)) print("Error: Unknown keyword '%s' in project %s" %
(entry, name))
if found_errors: if found_errors:
print("Found %d error(s) in %s" % (found_errors, args.infile)) print("Found %d error(s) in %s" % (found_errors, args.infile))
sys.exit(1) sys.exit(1)
if __name__ == '__main__':
main()

View File

@@ -17,6 +17,7 @@ commands =
[testenv:projects] [testenv:projects]
deps = PyYAML deps = PyYAML
GitPython
commands = commands =
{toxinidir}/tools/check_valid_gerrit_projects.py gerrit/projects.yaml {toxinidir}/tools/check_valid_gerrit_projects.py gerrit/projects.yaml
{toxinidir}/tools/check_projects_yaml_alphabetized.sh gerrit/projects.yaml {toxinidir}/tools/check_projects_yaml_alphabetized.sh gerrit/projects.yaml