Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def __prep_json_for_write(json_data: types.ObjectJsonRepr, export_settings: type
json_data = utilities.remove_nones(json_data)
if not export_settings.get(EXPORT_EMPTY, False):
log.debug("Removing empties")
json_data = utilities.clean_data(json_data, remove_empty=True)
json_data = utilities.clean_data(json_data, remove_empty=False)
return json_data


Expand Down
15 changes: 12 additions & 3 deletions sonar/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,18 @@ def search_by_name(endpoint: pf.Platform, name: str) -> dict[str, Application]:
def convert_app_json(old_app_json: dict[str, Any]) -> dict[str, Any]:
"""Converts sonar-config old JSON report format to new format for a single application"""
new_json = common_json_helper.convert_common_fields(old_app_json.copy())
if "branches" in old_app_json:
new_json["branches"] = util.dict_to_list(old_app_json["branches"], "name")
return new_json
if "branches" not in new_json:
return new_json
for br, data in new_json["branches"].items():
if "projects" not in data:
continue
new_json["branches"][br] = util.order_dict(data, ["name", "isMain", "projects"])
new_json["branches"][br]["projects"] = util.dict_to_list(new_json["branches"][br]["projects"], "key", "branch")
for proj_data in new_json["branches"][br]["projects"]:
if proj_data.get("branch", None) in ("__default__", c.DEFAULT_BRANCH):
proj_data.pop("branch")
new_json["branches"] = util.sort_list_by_key(util.dict_to_list(new_json["branches"], "name"), "name", "isMain")
return util.order_dict(new_json, ["key", "name", "visibility", "tags", "branches", "permissions"])


def convert_apps_json(old_json: dict[str, Any]) -> dict[str, Any]:
Expand Down
31 changes: 31 additions & 0 deletions sonar/util/portfolio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from typing import Any
from sonar import utilities as util
from sonar.util import constants as c
from sonar.util import common_json_helper


Expand All @@ -29,11 +30,41 @@ def convert_portfolio_json(old_json: dict[str, Any]) -> dict[str, Any]:
new_json = common_json_helper.convert_common_fields(old_json.copy())
if "projects" in new_json:
new_json["projects"] = common_json_helper.convert_common_fields(new_json["projects"])
if "manual" in new_json["projects"]:
projs = {}
for k, v in new_json["projects"]["manual"].items():
projs[k] = {"key": k, "branches": sorted(["" if e == c.DEFAULT_BRANCH else e for e in util.csv_to_list(v)])}
if projs[k]["branches"] == [""]:
projs[k].pop("branches", None)
new_json["projectSelection"] = {"manual": new_json["projects"]}
new_json["projectSelection"]["manual"] = util.dict_to_list(projs, "key", "branches")
elif "regexp" in new_json["projects"]:
new_json["projectSelection"] = "regexp"
new_json["projectSelection"] = {"regexp": new_json["projects"]["regexp"]}
if new_json["projects"].get("branch", c.DEFAULT_BRANCH) != c.DEFAULT_BRANCH:
new_json["projectSelection"]["branch"] = new_json["projects"]["branch"]
elif "tags" in new_json["projects"]:
new_json["projectSelection"] = {"tags": new_json["projects"]["tags"]}
if new_json["projects"].get("branch", c.DEFAULT_BRANCH) != c.DEFAULT_BRANCH:
new_json["projectSelection"]["branch"] = new_json["projects"]["branch"]
elif "rest" in new_json["projects"]:
new_json["projectSelection"] = {"rest": True}
if new_json["projects"].get("branch", c.DEFAULT_BRANCH) != c.DEFAULT_BRANCH:
new_json["projectSelection"]["branch"] = new_json["projects"]["branch"]
new_json.pop("projects")
if "applications" in new_json:
for k, v in new_json["applications"].items():
new_json["applications"][k] = {"key": k, "branches": sorted(["" if e == c.DEFAULT_BRANCH else e for e in util.csv_to_list(v)])}
if new_json["applications"][k]["branches"] == [""]:
new_json["applications"][k].pop("branches", None)
new_json["applications"] = util.dict_to_list(new_json["applications"], "key", "branches")

for key in "children", "portfolios":
if key in new_json:
new_json[key] = convert_portfolios_json(new_json[key])
if "branches" in old_json:
new_json["branches"] = util.dict_to_list(old_json["branches"], "name")
new_json = util.order_keys(new_json, "key", "name", "visibility", "projectSelection", "applications", "portfolios", "permissions")
return new_json


Expand Down