summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Cacqueray <tdecacqu@redhat.com>2016-05-18 09:40:09 -0400
committerTristan Cacqueray <tdecacqu@redhat.com>2017-03-15 02:09:49 +0000
commit2240fc3450654fdb3a91e83a86c96d304d259943 (patch)
tree1c62ab61bae389210b320172fced0e1bbf1b03f0
parent033a83b870dcd2f31d557f514b31e60a073b4945 (diff)
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
Notes
Notes (review): Code-Review+1: John L. Villalovos <openstack.org@sodarock.com> Code-Review+2: Joshua Hesketh <josh@nitrotech.org> Code-Review+2: Jeremy Stanley <fungi@yuggoth.org> Workflow+1: Jeremy Stanley <fungi@yuggoth.org> Code-Review+1: Vabada <d.abad@cern.ch> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 21 Feb 2018 17:25:20 +0000 Reviewed-on: https://review.openstack.org/318096 Project: openstack-infra/gerritbot Branch: refs/heads/master
-rwxr-xr-xgerritbot/bot.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/gerritbot/bot.py b/gerritbot/bot.py
index 6db4462..25d0e03 100755
--- a/gerritbot/bot.py
+++ b/gerritbot/bot.py
@@ -182,9 +182,18 @@ class Gerrit(threading.Thread):
182 # Delay before attempting again. 182 # Delay before attempting again.
183 time.sleep(1) 183 time.sleep(1)
184 184
185 @staticmethod
186 def _get_username(patchset):
187 # Try to find username
188 for key in ('name', 'username', 'email'):
189 username = patchset['uploader'].get(key)
190 if username:
191 return username
192 return "UNKNOWN USER"
193
185 def patchset_created(self, channel, data): 194 def patchset_created(self, channel, data):
186 msg = '%s proposed %s %s: %s %s' % ( 195 msg = '%s proposed %s %s: %s %s' % (
187 data['patchSet']['uploader']['name'], 196 self._get_username(data['patchSet']),
188 data['change']['project'], 197 data['change']['project'],
189 data['change']['branch'], 198 data['change']['branch'],
190 data['change']['subject'], 199 data['change']['subject'],