Update commit records with module aliases

When repos are renamed, commit records with the old name remain and are
not counted for the new repo name.
During post-process, rename the module name of all commits with the old
name, to be the new name.

Change-Id: I8684c5a1949ea916768bce9441d011325d079ad4
Closes-Bug: #1674092
This commit is contained in:
Yuval Brik 2017-03-20 17:52:07 +02:00
parent c2946165f8
commit 57de5f7ba3
2 changed files with 51 additions and 0 deletions

View File

@ -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,

View File

@ -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):