From ed51e565bb2b1cbbdf7897f6f5a0b90232896001 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Tue, 20 Aug 2013 13:40:35 +0400 Subject: [PATCH] Update records if user name changed in default data Closes bug 1214307 Change-Id: I809c320a186ff0c7408f67ad782c6ab3f12c5b13 --- stackalytics/processor/rcs.py | 5 +++- stackalytics/processor/record_processor.py | 4 ++- tests/unit/test_record_processor.py | 35 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/stackalytics/processor/rcs.py b/stackalytics/processor/rcs.py index e7e6388cf..b95c7741e 100644 --- a/stackalytics/processor/rcs.py +++ b/stackalytics/processor/rcs.py @@ -132,8 +132,11 @@ class Gerrit(Rcs): # poll open reviews from last_id down to bottom LOG.debug('Poll open reviews') + start_id = None + if last_id: + start_id = last_id + 1 # include the last review into query for review in self._poll_reviews(project_organization, module, branch, - start_id=last_id + 1, is_open=True): + start_id=start_id, is_open=True): yield review self.client.close() diff --git a/stackalytics/processor/record_processor.py b/stackalytics/processor/record_processor.py index 96b8bd170..ceeb3791d 100644 --- a/stackalytics/processor/record_processor.py +++ b/stackalytics/processor/record_processor.py @@ -235,11 +235,13 @@ class RecordProcessor(object): company_name = record['company_name'] user_id = record['user_id'] + author_name = record['author_name'] self._update_record_and_user(record) if ((record['company_name'] != company_name) or - (record['user_id'] != user_id)): + (record['user_id'] != user_id) or + (record['author_name'] != author_name)): need_update = True if record['primary_key'] in release_index: diff --git a/tests/unit/test_record_processor.py b/tests/unit/test_record_processor.py index 618ecddbf..c8e76a241 100644 --- a/tests/unit/test_record_processor.py +++ b/tests/unit/test_record_processor.py @@ -255,3 +255,38 @@ class TestRecordProcessor(testtools.TestCase): self.assertEquals(0, self.read_json.called) self.assertEquals('*independent', commit['company_name']) self.assertEquals(None, commit['launchpad_id']) + + def _generate_record_commit(self): + yield {'commit_id': u'0afdc64bfd041b03943ceda7849c4443940b6053', + 'lines_added': 9, + 'module': u'stackalytics', + 'record_type': 'commit', + 'message': u'Closes bug 1212953\n\nChange-Id: ' + u'I33f0f37b6460dc494abf2520dc109c9893ace9e6\n', + 'subject': u'Fixed affiliation of Edgar and Sumit', + 'loc': 10, + 'user_id': u'john_doe', + 'primary_key': u'0afdc64bfd041b03943ceda7849c4443940b6053', + 'author_email': u'jdoe@super.no', + 'company_name': u'SuperCompany', + 'record_id': 6, + 'lines_deleted': 1, + 'week': 2275, + 'blueprint_id': None, + 'bug_id': u'1212953', + 'files_changed': 1, + 'author_name': u'John Doe', + 'date': 1376737923, + 'launchpad_id': u'john_doe', + 'branches': set([u'master']), + 'change_id': u'I33f0f37b6460dc494abf2520dc109c9893ace9e6', + 'release': u'havana'} + + def test_update_record_no_changes(self): + commit_generator = self._generate_record_commit() + release_index = {'0afdc64bfd041b03943ceda7849c4443940b6053': 'havana'} + + updated = list(self.commit_processor.update(commit_generator, + release_index)) + + self.assertEquals(0, len(updated))