Allow to override id of organization's module group
By default module group is created with the same id as the name of organization. However this doesn't work for case when module name is the same as organization (e.g. kubernetes/kubernetes). With this patch it is possible to override module group id and make it different to organization name. Change-Id: I3f57ac1edc0a140aac93fedfaa0c7aa84d728749
This commit is contained in:
parent
2c5047b3e6
commit
8b6157c716
|
@ -179,6 +179,9 @@
|
||||||
},
|
},
|
||||||
"default_branch": {
|
"default_branch": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"module_group_id": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["organization"],
|
"required": ["organization"],
|
||||||
|
|
|
@ -127,15 +127,24 @@ def _create_module_groups_for_project_sources(project_sources, repos):
|
||||||
for repo in repos:
|
for repo in repos:
|
||||||
organizations[repo['organization']].append(repo['module'])
|
organizations[repo['organization']].append(repo['module'])
|
||||||
|
|
||||||
ps_organizations = dict([(ps.get('organization'),
|
# organization -> (module_group_id, module_group_name)
|
||||||
ps.get('module_group_name') or
|
ps_organizations = dict(
|
||||||
ps.get('organization'))
|
[(ps.get('organization'),
|
||||||
for ps in project_sources])
|
(ps.get('module_group_id') or ps.get('organization'),
|
||||||
|
ps.get('module_group_name') or ps.get('organization')))
|
||||||
|
for ps in project_sources])
|
||||||
|
|
||||||
module_groups = []
|
module_groups = []
|
||||||
for ogn, modules in six.iteritems(organizations):
|
for ogn, modules in six.iteritems(organizations):
|
||||||
|
module_group_id = ogn
|
||||||
|
module_group_name = ogn
|
||||||
|
|
||||||
|
if ogn in ps_organizations:
|
||||||
|
module_group_id = ps_organizations[ogn][0]
|
||||||
|
module_group_name = ps_organizations[ogn][1]
|
||||||
|
|
||||||
module_groups.append(utils.make_module_group(
|
module_groups.append(utils.make_module_group(
|
||||||
ogn, name=ps_organizations.get(ogn, ogn), modules=modules,
|
module_group_id, name=module_group_name, modules=modules,
|
||||||
tag='organization'))
|
tag='organization'))
|
||||||
|
|
||||||
return module_groups
|
return module_groups
|
||||||
|
|
|
@ -103,6 +103,36 @@ class TestDefaultDataProcessor(testtools.TestCase):
|
||||||
'modules': ['tux'],
|
'modules': ['tux'],
|
||||||
'tag': 'organization'}, dd['module_groups'])
|
'tag': 'organization'}, dd['module_groups'])
|
||||||
|
|
||||||
|
def test_update_project_list_ext_project_source(self):
|
||||||
|
with mock.patch('stackalytics.processor.default_data_processor.'
|
||||||
|
'_retrieve_project_list_from_github') as retriever:
|
||||||
|
retriever.return_value = [
|
||||||
|
{'module': 'kubernetes',
|
||||||
|
'uri': 'git://github.com/kubernetes/kubernetes',
|
||||||
|
'organization': 'kubernetes'},
|
||||||
|
]
|
||||||
|
dd = {
|
||||||
|
'repos': [],
|
||||||
|
'project_sources': [
|
||||||
|
{'organization': 'kubernetes',
|
||||||
|
'uri': 'github://',
|
||||||
|
'module_group_id': 'kubernetes-group'},
|
||||||
|
],
|
||||||
|
'module_groups': [],
|
||||||
|
}
|
||||||
|
|
||||||
|
default_data_processor._update_project_list(dd)
|
||||||
|
|
||||||
|
self.assertEqual(1, len(dd['repos']))
|
||||||
|
self.assertIn('kubernetes',
|
||||||
|
set([r['module'] for r in dd['repos']]))
|
||||||
|
|
||||||
|
self.assertEqual(1, len(dd['module_groups']))
|
||||||
|
self.assertIn({'id': 'kubernetes-group',
|
||||||
|
'module_group_name': 'kubernetes',
|
||||||
|
'modules': ['kubernetes'],
|
||||||
|
'tag': 'organization'}, dd['module_groups'])
|
||||||
|
|
||||||
@mock.patch('stackalytics.processor.utils.read_json_from_uri')
|
@mock.patch('stackalytics.processor.utils.read_json_from_uri')
|
||||||
def test_update_with_driverlog(self, mock_read_from_json):
|
def test_update_with_driverlog(self, mock_read_from_json):
|
||||||
default_data = {'repos': [{'module': 'cinder', }], 'users': []}
|
default_data = {'repos': [{'module': 'cinder', }], 'users': []}
|
||||||
|
|
Loading…
Reference in New Issue