Handle failed lookups from the OSF member DB
If a lookup for a member find no matches (perhaps an incorrect email address) the resulting JSON has an empty 'data' element. The existing code assumed it would be missing altogether. So check for an item in the list before trying to index the data. While we're doing this, use the same code style for both get_fullname() and get_irc() to remove points of confusion. Change-Id: I4c899df5f93c27f5e5390c93e88741d24c0282d8
This commit is contained in:
parent
765bc0d976
commit
01c8307efc
@ -97,8 +97,11 @@ def get_gerrit_account(email):
|
||||
|
||||
|
||||
def get_irc(member, filepath=None):
|
||||
member_data = member.get('data', [{}])[0]
|
||||
return member_data.get('irc', '')
|
||||
irc = ''
|
||||
member_data = member.get('data', [])
|
||||
if member_data:
|
||||
irc = member_data[0].get('irc', '')
|
||||
return irc
|
||||
|
||||
|
||||
def get_fullname(member, filepath=None):
|
||||
@ -108,13 +111,13 @@ def get_fullname(member, filepath=None):
|
||||
if filepath and filepath in exceptions:
|
||||
return exceptions[filepath]
|
||||
|
||||
member_data = member.get('data', [{}])[0]
|
||||
try:
|
||||
full_name = '%(first_name)s %(last_name)s' % (member_data)
|
||||
except KeyError:
|
||||
print('[I] Unable to retrieve fullname from OSF member DB for %s' %
|
||||
(member))
|
||||
full_name = u''
|
||||
full_name = u''
|
||||
member_data = member.get('data', [])
|
||||
if member_data:
|
||||
first_name = member_data[0].get('first_name', '')
|
||||
last_name = member_data[0].get('last_name', '')
|
||||
if first_name or last_name:
|
||||
full_name = first_name + ' ' + last_name
|
||||
|
||||
return full_name
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user