Skip to content

Commit c11fa2b

Browse files
committed
Reduce complexity
1 parent 5876fa5 commit c11fa2b

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

sonar/projects.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,28 @@ def __get_branch_export(self, export_settings: types.ConfigSettings) -> Optional
987987
return None
988988
return util.remove_nones(branch_data)
989989

990+
def migration_export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr:
991+
"""Produces the data that is exported for SQ to SC migration"""
992+
json_data = super().migration_export(export_settings)
993+
json_data["detectedCi"] = self.ci()
994+
json_data["revision"] = self.revision()
995+
last_task = self.last_task()
996+
json_data["backgroundTasks"] = {}
997+
if last_task:
998+
ctxt = last_task.scanner_context()
999+
if ctxt:
1000+
ctxt = {k: v for k, v in ctxt.items() if k not in _UNNEEDED_CONTEXT_DATA}
1001+
t_hist = []
1002+
for t in self.task_history():
1003+
t_hist.append({k: v for k, v in t._json.items() if k not in _UNNEEDED_TASK_DATA})
1004+
json_data["backgroundTasks"] = {
1005+
"lastTaskScannerContext": ctxt,
1006+
# "lastTaskWarnings": last_task.warnings(),
1007+
"taskHistory": t_hist,
1008+
}
1009+
return json_data
1010+
1011+
9901012
def export(self, export_settings: types.ConfigSettings, settings_list: dict[str, str] = None) -> types.ObjectJsonRepr:
9911013
"""Exports the entire project configuration as JSON
9921014
@@ -1018,22 +1040,6 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
10181040

10191041
if export_settings.get("MODE", "") == "MIGRATION":
10201042
json_data.update(self.migration_export(export_settings))
1021-
json_data["detectedCi"] = self.ci()
1022-
json_data["revision"] = self.revision()
1023-
last_task = self.last_task()
1024-
json_data["backgroundTasks"] = {}
1025-
if last_task:
1026-
ctxt = last_task.scanner_context()
1027-
if ctxt:
1028-
ctxt = {k: v for k, v in ctxt.items() if k not in _UNNEEDED_CONTEXT_DATA}
1029-
t_hist = []
1030-
for t in self.task_history():
1031-
t_hist.append({k: v for k, v in t._json.items() if k not in _UNNEEDED_TASK_DATA})
1032-
json_data["backgroundTasks"] = {
1033-
"lastTaskScannerContext": ctxt,
1034-
# "lastTaskWarnings": last_task.warnings(),
1035-
"taskHistory": t_hist,
1036-
}
10371043

10381044
settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False)
10391045
# json_data.update({s.to_json() for s in settings_dict.values() if include_inherited or not s.inherited})

0 commit comments

Comments
 (0)