Browse Source

Merge "Add _get_username method to discover username"

changes/66/286366/5
Zuul 1 year ago
parent
commit
f32d742eff
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      gerritbot/bot.py

+ 10
- 1
gerritbot/bot.py View File

@@ -186,9 +186,18 @@ class Gerrit(threading.Thread):
186 186
             # Delay before attempting again.
187 187
             time.sleep(1)
188 188
 
189
+    @staticmethod
190
+    def _get_username(patchset):
191
+        # Try to find username
192
+        for key in ('name', 'username', 'email'):
193
+            username = patchset['uploader'].get(key)
194
+            if username:
195
+                return username
196
+        return "UNKNOWN USER"
197
+
189 198
     def patchset_created(self, channel, data):
190 199
         msg = '%s proposed %s %s: %s  %s' % (
191
-            data['patchSet']['uploader']['name'],
200
+            self._get_username(data['patchSet']),
192 201
             data['change']['project'],
193 202
             data['change']['branch'],
194 203
             data['change']['subject'],

Loading…
Cancel
Save