diff --git a/openstack_election/cmds/ci_check_all_candidate_files.py b/openstack_election/cmds/ci_check_all_candidate_files.py index 56c25f09..b3a7cc07 100755 --- a/openstack_election/cmds/ci_check_all_candidate_files.py +++ b/openstack_election/cmds/ci_check_all_candidate_files.py @@ -73,6 +73,18 @@ def validate_member(filepath, verbose=0): return is_valid +# NOTE(tonyb): Currently verbose isn't used but it's included to keep +# the interface the same as the validate_*() functions. +def show_affiliation(filepath, verbose=0): + print('Show member affiliation if available') + print('------------------------------------') + + email = utils.get_email(filepath) + member = utils.lookup_member(email) + + print('Affiliation: %s' % (utils.current_member_affiliation(member))) + + def check_for_changes(projects, filepath, limit, verbose=0): print('Looking for validating changes') print('------------------------------') @@ -165,6 +177,7 @@ def main(): candidate_ok &= validate_filename(filepath) candidate_ok &= validate_project(filepath, projects) candidate_ok &= validate_member(filepath, verbose=args.verbose) + show_affiliation(filepath, verbose=args.verbose) if candidate_ok: if (election_type == 'ptl' diff --git a/openstack_election/utils.py b/openstack_election/utils.py index 55416b35..d37f30a4 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -133,6 +133,15 @@ def lookup_osf(email, group_slug=None, verbose=0): return result +def current_member_affiliation(member): + organization = "" + if member.get('data'): + for affiliation in member["data"][0].get("all_affiliations", []): + if affiliation.get("is_current", False): + organization = affiliation.get("organization", {}).get("name") + return organization + + def lookup_member(email, verbose=0): """Lookup profiles of OSF members"""