From 161b6e9be647f392d3d0596d5a1d13f529c3b522 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 30 Apr 2018 13:17:35 -0400 Subject: [PATCH] protect against missing labels on reviews Do not fail if gerrit does not report any Workflow or Code-Review data. Change-Id: I1e7fdc901db70766c3febb55263c1dac62c31676 Signed-off-by: Doug Hellmann --- goal_tools/gerrit.py | 49 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/goal_tools/gerrit.py b/goal_tools/gerrit.py index 9b3922c..72f0bdd 100644 --- a/goal_tools/gerrit.py +++ b/goal_tools/gerrit.py @@ -121,28 +121,33 @@ class Review: @property def reviewers(self): - for label in self._data['labels']['Code-Review']['all']: - if label['value'] not in (2, -1): - # Only report reviewers with negative reviews or - # approvals to avoid counting anyone who is just - # leaving lots of +1 votes without actually providing - # feedback. - continue - yield Participant( - 'reviewer', - label['name'], - label['email'], - _to_datetime(label['date']), - ) - for label in self._data['labels']['Workflow']['all']: - if label.get('value', 0) != 1: - continue - yield Participant( - 'approver', - label['name'], - label['email'], - _to_datetime(label['date']), - ) + labels = self._data['labels'] + + if 'Code-Review' in labels: + for label in labels['Code-Review']['all']: + if label['value'] not in (2, -1): + # Only report reviewers with negative reviews or + # approvals to avoid counting anyone who is just + # leaving lots of +1 votes without actually providing + # feedback. + continue + yield Participant( + 'reviewer', + label['name'], + label['email'], + _to_datetime(label['date']), + ) + + if 'Workflow' in labels: + for label in labels['Workflow']['all']: + if label.get('value', 0) != 1: + continue + yield Participant( + 'approver', + label['name'], + label['email'], + _to_datetime(label['date']), + ) def cache_review(review_id, data, cache):