gerrit: add a key existence check for gerrit search queries
BUG=chromium:890109
TEST=manually tested with previously failing query
Change-Id: Ibeb793f8d51eba214661f5b43711e42fd38c75d4
Reviewed-on: https://chromium-review.googlesource.com/1249668
Commit-Ready: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/gerrit.py b/scripts/gerrit.py
index b859e40..16c00e4 100644
--- a/scripts/gerrit.py
+++ b/scripts/gerrit.py
@@ -106,23 +106,22 @@
def GetApprovalSummary(_opts, cls):
"""Return a dict of the most important approvals"""
approvs = dict([(x, '') for x in GERRIT_SUMMARY_CATS])
- if 'approvals' in cls['currentPatchSet']:
- for approver in cls['currentPatchSet']['approvals']:
- cats = GERRIT_APPROVAL_MAP.get(approver['type'])
- if not cats:
- logging.warning('unknown gerrit approval type: %s', approver['type'])
- continue
- cat = cats[0].strip()
- val = int(approver['value'])
- if not cat in approvs:
- # Ignore the extended categories in the summary view.
- continue
- elif approvs[cat] == '':
- approvs[cat] = val
- elif val < 0:
- approvs[cat] = min(approvs[cat], val)
- else:
- approvs[cat] = max(approvs[cat], val)
+ for approver in cls.get('currentPatchSet', {}).get('approvals', []):
+ cats = GERRIT_APPROVAL_MAP.get(approver['type'])
+ if not cats:
+ logging.warning('unknown gerrit approval type: %s', approver['type'])
+ continue
+ cat = cats[0].strip()
+ val = int(approver['value'])
+ if not cat in approvs:
+ # Ignore the extended categories in the summary view.
+ continue
+ elif approvs[cat] == '':
+ approvs[cat] = val
+ elif val < 0:
+ approvs[cat] = min(approvs[cat], val)
+ else:
+ approvs[cat] = max(approvs[cat], val)
return approvs