Merge "Add _get_username method to discover username"

This commit is contained in:
Zuul 2018-02-21 17:25:20 +00:00 committed by Gerrit Code Review
commit f32d742eff
1 changed files with 10 additions and 1 deletions

View File

@ -186,9 +186,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'],