Skip to content

Commit 951be41

Browse files
committed
Add portfolios JSON conversion to new format
1 parent 1620adf commit 951be41

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sonar/portfolios.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,22 @@ def get_api_branch(branch: str) -> str:
850850
def clear_cache(endpoint: pf.Platform) -> None:
851851
"""Clears the cache of an endpoint"""
852852
Portfolio.clear_cache(endpoint)
853+
854+
855+
def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
856+
new_json = old_json.copy()
857+
for key in "children", "portfolios":
858+
if key in new_json:
859+
new_json[key] = old_to_new_json(new_json[key])
860+
if "permissions" in old_json:
861+
new_json["permissions"] = util.perms_to_list(old_json["permissions"])
862+
if "branches" in old_json:
863+
new_json["branches"] = util.dict_to_list(old_json["branches"], "name")
864+
return new_json
865+
866+
867+
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
868+
new_json = old_json.copy()
869+
for k, v in new_json.items():
870+
new_json[k] = old_to_new_json_one(v)
871+
return util.dict_to_list(new_json, "key")

0 commit comments

Comments
 (0)