diff --git a/stackalytics/processor/record_processor.py b/stackalytics/processor/record_processor.py index 24df772a3..9f139dd4d 100644 --- a/stackalytics/processor/record_processor.py +++ b/stackalytics/processor/record_processor.py @@ -901,12 +901,29 @@ class RecordProcessor(object): yield record_handler + def _update_commits_with_module_alias(self): + LOG.info('Update record with aliases') + + modules, alias_module_map = self._get_modules() + + def record_handler(record): + if record['record_type'] != 'commit': + return + + rec_module = record.get('module', None) + if rec_module and rec_module in alias_module_map: + record['module'] = alias_module_map[rec_module] + yield record + + yield record_handler + def post_processing(self, release_index): processors = [ self._update_records_with_user_info, self._update_commits_with_merge_date, functools.partial(self._update_records_with_releases, release_index), + self._update_commits_with_module_alias, self._update_blueprints_with_mention_info, self._determine_core_contributors, self._update_members_company_name, diff --git a/stackalytics/tests/unit/test_record_processor.py b/stackalytics/tests/unit/test_record_processor.py index ce7903e95..91d33cca7 100644 --- a/stackalytics/tests/unit/test_record_processor.py +++ b/stackalytics/tests/unit/test_record_processor.py @@ -1326,6 +1326,7 @@ class TestRecordProcessor(testtools.TestCase): 'date': 1234567890, 'lines_added': 25, 'lines_deleted': 9, + 'module': u'stackalytics', 'release_name': 'havana'}, {'record_type': 'review', 'id': 'I104573', @@ -1343,6 +1344,39 @@ class TestRecordProcessor(testtools.TestCase): commit = runtime_storage_inst.get_by_primary_key('de7e8f2') self.assertEqual(1385490000, commit['date']) + def test_commit_module_alias(self): + record_processor_inst = self.make_record_processor() + runtime_storage_inst = record_processor_inst.runtime_storage_inst + + with mock.patch('stackalytics.processor.utils.load_repos') as patch: + patch.return_value = [{'module': 'sahara', 'aliases': ['savanna']}] + runtime_storage_inst.set_records(record_processor_inst.process([ + {'record_type': 'commit', + 'commit_id': 'de7e8f2', + 'change_id': ['I104573'], + 'author_name': 'John Doe', + 'author_email': 'john_doe@gmail.com', + 'date': 1234567890, + 'lines_added': 25, + 'lines_deleted': 9, + 'module': u'savanna', + 'release_name': 'havana'}, + {'record_type': 'review', + 'id': 'I104573', + 'subject': 'Fix AttributeError in Keypair._add_details()', + 'owner': {'name': 'John Doe', + 'email': 'john_doe@gmail.com', + 'username': 'john_doe'}, + 'createdOn': 1385478465, + 'lastUpdated': 1385490000, + 'status': 'MERGED', + 'module': 'nova', 'branch': 'master'}, + ])) + record_processor_inst.post_processing({}) + + commit = runtime_storage_inst.get_by_primary_key('de7e8f2') + self.assertEqual('sahara', commit['module']) + # update records def _generate_record_commit(self):