diff --git a/openstack_election/cmds/check_all_candidacies.py b/openstack_election/cmds/check_all_candidacies.py index 2bbb4724..6584308c 100755 --- a/openstack_election/cmds/check_all_candidacies.py +++ b/openstack_election/cmds/check_all_candidacies.py @@ -15,10 +15,13 @@ from __future__ import print_function from __future__ import unicode_literals import argparse +import os -from openstack_election import check_candidacy +from openstack_election.cmds import ci_check_all_candidate_files as checks from openstack_election import utils +results = [] + def get_reviews(): return utils.get_reviews('is:open project:%s file:^%s/%s/.*' % @@ -26,9 +29,16 @@ def get_reviews(): utils.conf['release'])) +def print_member(filepath): + email = utils.get_email(filepath) + member = utils.lookup_member(email) + member_id = member.get('data', [{}])[0].get('id') + base = 'https://www.openstack.org/community/members/profile' + print('OSF member profile: %s/%s' % (base, member_id)) + + def main(): - description = ('Check if the owner of open changes are valid candidates as' - ' described in the change') + description = ('Check all open reviews for candidacies') parser = argparse.ArgumentParser(description) parser.add_argument('--limit', dest='limit', type=int, default=1, help=('How many validating changes to report. ' @@ -39,30 +49,50 @@ def main(): 'Default: %(default)s')) args = parser.parse_args() + projects = utils.get_projects(tag=args.tag, fallback_to_master=True) + for review in get_reviews(): if review['status'] != 'NEW': continue - print('Checking %s/%d' % - (utils.GERRIT_BASE, review['_number'])) + review_url = '%s/%d' % (utils.GERRIT_BASE, review['_number']) + print('Checking %s' % (review_url)) - if not len(utils.candidate_files(review)): - print("[E] No candidacy added") - continue + for filepath in utils.candidate_files(review): + email = utils.get_email(filepath) + team = os.path.basename(os.path.dirname(filepath)) - owner = review.get('owner', {}) - try: - found = check_candidacy.check_candidacy_review(review['change_id'], - tag=args.tag, - limit=args.limit, - review=review) - except Exception as exc: - print("[E] %s\n\n" % (exc)) - else: - if found: - print('SUCESS: %s is a valid candidate\n\n' % - (owner['email'])) + # Some kind souls remove the .placeholder file when they upload + # a candidacy + if email == '.placeholder': + continue + + candiate_ok = checks.validate_filename(filepath) + if candiate_ok: + candiate_ok = checks.validate_member(filepath) + + if candiate_ok: + if utils.is_tc_election: + candiate_ok = checks.check_for_changes(projects, filepath, + args.limit) + print_member(filepath) + else: + print('Not checking for changes as this is a TC election') else: - print('[E]: %s is not a valid candidate\n\n' % - (owner['email'])) + print('Not checking for changes as %s doesn\'t seem to ' + 'describe a valid candidacy' % (filepath)) + + results.append((review_url, email, team, candiate_ok)) + + print('\n\n\n') + print('*' * 80) + for result in results: + (review_url, email, team, candiate_ok) = result + print(review_url) + if candiate_ok: + print(' SUCCESS: %s is a valid candidate for %s' % (email, team)) + else: + print(' ERROR: Candidate %s is not valid, please review ' + 'previous messages for details.' % (email)) + print('*' * 80) return 0