Add _get_username method to discover username
This change mitigate this exception: File "gerritbot/bot.py", line 154, in change_created data['patchSet']['uploader']['name'], KeyError: 'name' Change-Id: Ia1f394d6ff0e158df16461cf3150761f6ec12f29
This commit is contained in:
parent
033a83b870
commit
2240fc3450
|
@ -182,9 +182,18 @@ class Gerrit(threading.Thread):
|
|||
# Delay before attempting again.
|
||||
time.sleep(1)
|
||||
|
||||
@staticmethod
|
||||
def _get_username(patchset):
|
||||
# Try to find username
|
||||
for key in ('name', 'username', 'email'):
|
||||
username = patchset['uploader'].get(key)
|
||||
if username:
|
||||
return username
|
||||
return "UNKNOWN USER"
|
||||
|
||||
def patchset_created(self, channel, data):
|
||||
msg = '%s proposed %s %s: %s %s' % (
|
||||
data['patchSet']['uploader']['name'],
|
||||
self._get_username(data['patchSet']),
|
||||
data['change']['project'],
|
||||
data['change']['branch'],
|
||||
data['change']['subject'],
|
||||
|
|
Loading…
Reference in New Issue