diff --git a/goal_tools/gerrit.py b/goal_tools/gerrit.py index 72f0bdd..a45457c 100644 --- a/goal_tools/gerrit.py +++ b/goal_tools/gerrit.py @@ -108,6 +108,7 @@ class Review: def participants(self): yield self.owner yield from self.reviewers + yield from self.uploaders @property def owner(self): @@ -119,6 +120,39 @@ class Review: self.created, ) + @property + def uploaders(self): + known_uploaders = set() + + # Record the owner of the patch as a known uploader so we do + # not emit their information again. This means someone with + # the "uploader" role can be counted as someone taking over a + # patch created by someone else to fix it in some way. + owner_email = self._data['owner']['email'] + known_uploaders.add(owner_email) + + # The revision data is stored in a mapping keyed by the SHA, + # so in order to be consistent with how we return the + # uploaders we sort the revisions based on the number before + # we process them. + revisions = sorted( + self._data['revisions'].values(), + key=lambda x: x['_number'], + ) + + for revision in revisions: + uploader = revision['uploader'] + if uploader['email'] in known_uploaders: + # Ignore duplicates + continue + known_uploaders.add(uploader['email']) + yield Participant( + 'uploader', + uploader['name'], + uploader['email'], + _to_datetime(revision['created']), + ) + @property def reviewers(self): labels = self._data['labels'] diff --git a/goal_tools/tests/test_gerrit.py b/goal_tools/tests/test_gerrit.py index bd6679d..4a64f26 100644 --- a/goal_tools/tests/test_gerrit.py +++ b/goal_tools/tests/test_gerrit.py @@ -133,6 +133,24 @@ class TestReview(base.TestCase): ] self.assertEqual(expected, reviewers) + def test_uploaders(self): + uploaders = list(self.rev.uploaders) + expected = [ + gerrit.Participant( + role='uploader', + name='Hiroaki Kobayashi', + email='kobayashi.hiroaki@lab.ntt.co.jp', + date=datetime.datetime(2018, 4, 10, 6, 7, 47), + ), + gerrit.Participant( + role='uploader', + name='Akihiro Motoki', + email='amotoki@gmail.com', + date=datetime.datetime(2018, 4, 22, 2, 28, 56), + ), + ] + self.assertEqual(expected, uploaders) + class TestFetchReview(base.TestCase):