Add check-manual for checking a candidate *without* an open review

Change-Id: I869aa412e90170fe5cc7d317c081fd19d38b5989
This commit is contained in:
Tony Breeds 2016-09-12 15:11:04 +10:00 committed by Tristan Cacqueray
parent 0a135cbe56
commit 437e0d19fc
5 changed files with 113 additions and 48 deletions

View File

@ -23,28 +23,16 @@ from openstack_election import utils
# FIXME: Printing from library function isn't great.
# change API to return the messages and let the consumer decide what to
# do with them
def check_candidacy(change_id, limit=1, tag=utils.PROJECTS_TAG, review=None):
def check_candidate(project_name, email, projects, limit=1):
def pretty_datetime(dt_str):
dt = datetime.datetime.strptime(dt_str.split('.')[0],
'%Y-%m-%d %H:%M:%S')
return dt.strftime('%Y-%m-%d')
projects = utils.get_projects(tag=tag)
# If there is more than one review that matches this change_id then all
# bets are off
review = review or utils.get_reviews(change_id)[0]
owner = review.get('owner', {})
found = 0
branch = None
for filename in utils.candidate_files(review):
_, series, project_name, candidate_file = filename.split(os.sep)
if project_name != 'TC':
project_name = utils.dir2name(project_name, projects)
if project_name == 'Stable branch maintenance':
if project_name in ['Stable branch maintenance']:
project_list = projects.values()
branch = '^stable/.*'
else:
@ -52,12 +40,11 @@ def check_candidacy(change_id, limit=1, tag=utils.PROJECTS_TAG, review=None):
for project in project_list:
for atc in project.get('extra-atcs', []):
if (atc['email'] == owner['email'] and
utils.check_atc_date(atc)):
print("Valid extra ATC record:\n\t%s" % (atc))
if (atc['email'] == email and utils.check_atc_date(atc)):
print("%2d: Valid extra ATC record:\n\t%s" % (found, atc))
found += 1
if found >= limit:
return True
return found
for deliverable in project['deliverables'].values():
for repo_name in deliverable["repos"]:
@ -65,11 +52,11 @@ def check_candidacy(change_id, limit=1, tag=utils.PROJECTS_TAG, review=None):
'owner:%s project:%s' %
(utils.gerrit_datetime(utils.PERIOD_START),
utils.gerrit_datetime(utils.PERIOD_END),
owner['email'], repo_name))
email, repo_name))
if branch:
query += (' branch:%s' % (branch))
print('Checking %s for merged changes by %s' %
(repo_name, owner['email']))
(repo_name, email))
for review in utils.get_reviews(query):
url = ('%s/#/q/%s' %
(utils.GERRIT_BASE, review['change_id']))
@ -77,6 +64,28 @@ def check_candidacy(change_id, limit=1, tag=utils.PROJECTS_TAG, review=None):
(found, pretty_datetime(review['submitted']),
url))
found += 1
if found >= limit:
return found
return found
def check_candidacy_review(change_id, limit=1, tag=utils.PROJECTS_TAG,
review=None):
projects = utils.get_projects(tag=tag)
# If there is more than one review that matches this change_id then all
# bets are off
review = review or utils.get_reviews(change_id)[0]
email = review.get('owner', {}).get('email')
found = 0
for filename in utils.candidate_files(review):
_, series, project_name, candidate_file = filename.split(os.sep)
if project_name != 'TC':
project_name = utils.dir2name(project_name, projects)
found += check_candidate(project_name, email, projects,
limit=(limit-found))
if found >= limit:
return True
return found > 0

View File

@ -48,7 +48,7 @@ def main():
owner = review.get('owner', {})
try:
found = check_candidacy.check_candidacy(review['change_id'],
found = check_candidacy.check_candidacy_review(review['change_id'],
tag=args.tag,
review=review)
except Exception as exc:

View File

@ -40,7 +40,7 @@ def main():
args.limit = 100
try:
found = check_candidacy.check_candidacy(review['change_id'],
found = check_candidacy.check_candidacy_review(review['change_id'],
tag=args.tag,
review=review)
except Exception as exc:

View File

@ -0,0 +1,55 @@
# 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.
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import argparse
from openstack_election import check_candidacy
from openstack_election import utils
def main():
description = ('Check thath the email address is a valid candidate for '
' the specified project')
parser = argparse.ArgumentParser(description)
parser.add_argument(dest='project_name',
help=('The Project the candidate is applying for'))
parser.add_argument(dest='email',
help=('An email address registered to the candidate'))
parser.add_argument('--limit', dest='limit', type=int, default=1,
help=('How many validating changes to report. '
'A negative value means report many. '
'Default: %(default)s'))
parser.add_argument('--tag', dest='tag', default=utils.PROJECTS_TAG,
help=('The governance tag to validate against. '
'Default: %(default)s'))
args = parser.parse_args()
if args.limit < 0:
args.limit = 100
projects = utils.get_projects(tag=args.tag)
if args.project_name not in projects.keys():
print('[E]: %s not found in: %s' %
(args.project_name, ','.join(projects.keys())))
return 1
if check_candidacy.check_candidate(args.project_name, args.email,
projects, limit=args.limit):
print('SUCESS: %s is a valid candidate\n\n' % (args.email))
return 0
else:
print('[E]: %s is not a valid candidate\n\n' % (args.email))
return 1

View File

@ -22,6 +22,7 @@ packages = openstack_election
console_scripts =
check-all-candidacies = openstack_election.cmds.check_all_candidacies:check_reviews
check-candidacy = openstack_election.cmds.check_candidacy:main
check-candidacy-manual = openstack_election.cmds.check_manual:main
[build_sphinx]