From 6ee2f2234f3f50793190aa822f8d8a3f1190a436 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Wed, 3 Dec 2014 13:36:13 +0100 Subject: [PATCH] Check for valid entries in gerrit/projects.yaml Rename check_upstream_url_scheme.py to check_valid_gerrit_projects.py and extend the check so that: * It shows all errors, not only the first one * It checks that the keywords are valid This was triggered by seen twice in a week the keyword "description" misspelled. Script now outputs in error case: Error: Upstream URLs should use a scheme in ['https://', 'http://', 'git://'], found git@://github.com/emonty/cookiecutter-openstack.git in openstack-dev/cookiecutter Error: Unknown keyword 'decription' in project stackforge/ec2-driver Found 2 error(s) in /tmp/projects.yaml Also add the usual license header. Change-Id: I334dcadc6fd4472fb28d379aec317c1a16dee2e2 --- tools/check_upstream_url_scheme.py | 45 ---------------- tools/check_valid_gerrit_projects.py | 76 ++++++++++++++++++++++++++++ tox.ini | 2 +- 3 files changed, 77 insertions(+), 46 deletions(-) delete mode 100755 tools/check_upstream_url_scheme.py create mode 100755 tools/check_valid_gerrit_projects.py diff --git a/tools/check_upstream_url_scheme.py b/tools/check_upstream_url_scheme.py deleted file mode 100755 index 7ee54a6a15..0000000000 --- a/tools/check_upstream_url_scheme.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python -""" -Allow git:// and https:// URLs for importing upstream repositories, -but not git@ -""" - -import argparse - -import yaml - - -parser = argparse.ArgumentParser() -parser.add_argument('-v', '--verbose', - dest='verbose', - default=False, - action='store_true', - ) -parser.add_argument( - 'infile', - help='path to review.projects.yaml', -) -args = parser.parse_args() - -projects = yaml.load(open(args.infile, 'r')) - -VALID_SCHEMES = ['https://', 'http://', 'git://'] - -for p in projects: - name = p.get('project') - if not name: - # not a project - continue - upstream = p.get('upstream') - if args.verbose: - print 'Checking %s: %r' % (name, upstream) - if not upstream: - continue - for prefix in VALID_SCHEMES: - if upstream.startswith(prefix): - break - else: - raise ValueError( - 'Upstream URLs should use a scheme in %s, found %s' % - (VALID_SCHEMES, p['project']) - ) diff --git a/tools/check_valid_gerrit_projects.py b/tools/check_valid_gerrit_projects.py new file mode 100755 index 0000000000..5ac806e526 --- /dev/null +++ b/tools/check_valid_gerrit_projects.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# +# Check that gerrit/projects.yaml contains valid entries. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import sys +import yaml + + +parser = argparse.ArgumentParser() +parser.add_argument('-v', '--verbose', + dest='verbose', + default=False, + action='store_true', + ) +parser.add_argument( + 'infile', + help='Path to gerrit/projects.yaml', +) +args = parser.parse_args() + +projects = yaml.load(open(args.infile, 'r')) + +VALID_LABELS = ["acl-config", "description", "docimpact-group", + "groups", "homepage", "options", "project", + "upstream", "upstream-prefix", "use-storyboard"] +VALID_SCHEMES = ['https://', 'http://', 'git://'] + +found_errors = 0 +for p in projects: + name = p.get('project') + if not name: + # not a project + found_errors += 1 + print("Error: Entry is not a project %s" % p) + continue + if args.verbose: + print 'Checking %s' % (name) + # Check upstream URL + # Allow git:// and https:// URLs for importing upstream repositories, + # but not git@ + upstream = p.get('upstream') + if not upstream: + continue + for prefix in VALID_SCHEMES: + if upstream.startswith(prefix): + break + else: + found_errors += 1 + print('Error: Upstream URLs should use a scheme in %s, ' + 'found %s in %s' % + (VALID_SCHEMES, p['upstream'], name)) + # Check for any wrong entries + for entry in p: + for label in VALID_LABELS: + if entry == label: + break + else: + found_errors += 1 + print("Error: Unknown keyword '%s' in project %s" % (entry, name)) + +if found_errors: + print("Found %d error(s) in %s" % (found_errors, args.infile)) + sys.exit(1) diff --git a/tox.ini b/tox.ini index e8dc76a091..b36f7692cc 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ commands = flake8 [testenv:projects] deps = PyYAML commands = - {toxinidir}/tools/check_upstream_url_scheme.py gerrit/projects.yaml + {toxinidir}/tools/check_valid_gerrit_projects.py gerrit/projects.yaml {toxinidir}/tools/check_projects_yaml_alphabetized.sh gerrit/projects.yaml [testenv:venv]