From 5cb88ff9bf09201e76574ef946cdfc1d96b12c13 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Thu, 19 Jan 2017 07:24:30 +0000 Subject: [PATCH] Fix get_fullname to support multiple account This change fixes the get_fullname logic to use a gerrit query instead of a direct account lookup. This makes the method work when a candidate has multiple accounts using a single mail address, e.g.: https://review.openstack.org/accounts/eric.guo@easystack.cn doesn't work https://review.openstack.org//accounts/?q=eric.guo@easystack.cn works Change-Id: I92e68a30533f3e93edce8902f17690243499b5ca --- openstack_election/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/openstack_election/utils.py b/openstack_election/utils.py index 00fa1d86..a67dcdb3 100644 --- a/openstack_election/utils.py +++ b/openstack_election/utils.py @@ -81,6 +81,16 @@ def get_email(filepath): return git.stdout.readlines()[-1][:-1] +def get_gerrit_account(email): + url = '%s/accounts/?q=%s' % (GERRIT_BASE, email) + accounts = gerrit_query(url) + if not accounts: + raise ValueError("Couldn't find gerrit account with '%s'" % email) + if len(accounts) != 1: + print("[I] %s has multiple account: %s" % (email, accounts)) + return accounts[0] + + def get_fullname(filepath): # Check if filepath is an exception if exceptions is None: @@ -90,8 +100,7 @@ def get_fullname(filepath): # Otherwise query gerrit using git log email email = get_email(filepath) - url = '%s/accounts/%s' % (GERRIT_BASE, email) - fullname = gerrit_query(url)['name'] + fullname = get_gerrit_account(email)['name'] # Remove parenthesis content fullname = re.sub(r"\([^)]*\)", "", fullname)