Skip to content

Commit b91471c

Browse files
committed
Quality pass
1 parent 951be41 commit b91471c

File tree

9 files changed

+22
-11
lines changed

9 files changed

+22
-11
lines changed

cli/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def __import_config(endpoint: platform.Platform, what: list[str], **kwargs) -> N
305305

306306

307307
def convert_json(**kwargs) -> dict[str, Any]:
308+
"""Converts a sonar-config report from the old to the new JSON format"""
308309
with open(kwargs["convertFrom"], encoding="utf-8") as fd:
309310
old_json = json.loads(fd.read())
310311
mapping = {
@@ -334,7 +335,7 @@ def main() -> None:
334335
start_time = utilities.start_clock()
335336
try:
336337
kwargs = utilities.convert_args(__parse_args("Extract SonarQube Server or Cloud platform configuration"))
337-
if kwargs["convertFrom"] != None:
338+
if kwargs["convertFrom"] is not None:
338339
convert_json(**kwargs)
339340
utilities.final_exit(errcodes.OK, "", start_time)
340341
endpoint = platform.Platform(**kwargs)

sonar/applications.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,18 @@ def search_by_name(endpoint: pf.Platform, name: str) -> dict[str, Application]:
600600
return data
601601

602602

603-
def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
604-
new_json = old_json.copy()
605-
if "permissions" in old_json:
606-
new_json["permissions"] = util.perms_to_list(old_json["permissions"])
607-
if "branches" in old_json:
608-
new_json["branches"] = util.dict_to_list(old_json["branches"], "name")
603+
def old_to_new_json_one(old_app_json: dict[str, Any]) -> dict[str, Any]:
604+
"""Converts sonar-config old JSON report format to new format for a single application"""
605+
new_json = old_app_json.copy()
606+
if "permissions" in old_app_json:
607+
new_json["permissions"] = util.perms_to_list(old_app_json["permissions"])
608+
if "branches" in old_app_json:
609+
new_json["branches"] = util.dict_to_list(old_app_json["branches"], "name")
609610
return new_json
610611

611612

612613
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
614+
"""Converts sonar-config old JSON report format to new format"""
613615
new_json = old_json.copy()
614616
for k, v in new_json.items():
615617
new_json[k] = old_to_new_json_one(v)

sonar/groups.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,5 @@ def exists(endpoint: pf.Platform, name: str) -> bool:
435435

436436

437437
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
438+
"""Converts sonar-config old groups JSON report format to new format"""
438439
return util.dict_to_list(old_json, "name", "description")

sonar/platform.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,14 @@ def audit(endpoint: Platform, audit_settings: types.ConfigSettings, **kwargs) ->
977977

978978

979979
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
980-
new_json = {}
980+
"""Converts sonar-config "plaform" section old JSON report format to new format"""
981981
if "plugins" in old_json:
982-
new_json["plugins"] = util.dict_to_list(old_json["plugins"], "key")
983-
return new_json
982+
old_json["plugins"] = util.dict_to_list(old_json["plugins"], "key")
983+
return old_json
984984

985985

986986
def global_settings_old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
987+
"""Converts sonar-config "globalSettings" section old JSON report format to new format"""
987988
new_json = {}
988989
special_categories = (settings.LANGUAGES_SETTINGS, settings.DEVOPS_INTEGRATION, "permissions", "permissionTemplates")
989990
for categ in [cat for cat in settings.CATEGORIES if cat not in special_categories]:

sonar/portfolios.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ def clear_cache(endpoint: pf.Platform) -> None:
853853

854854

855855
def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
856+
"""Converts the sonar-config old JSON report format for a single portfolio to the new one"""
856857
new_json = old_json.copy()
857858
for key in "children", "portfolios":
858859
if key in new_json:
@@ -865,6 +866,7 @@ def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
865866

866867

867868
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
869+
"""Converts the sonar-config portfolios old JSON report format to the new one"""
868870
new_json = old_json.copy()
869871
for k, v in new_json.items():
870872
new_json[k] = old_to_new_json_one(v)

sonar/projects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,7 @@ def import_zips(endpoint: pf.Platform, project_list: list[str], threads: int = 2
16991699

17001700

17011701
def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
1702+
"""Converts the sonar-config projects old JSON report format for a single project to the new one"""
17021703
new_json = old_json.copy()
17031704
if "permissions" in old_json:
17041705
new_json["permissions"] = util.perms_to_list(old_json["permissions"])
@@ -1710,8 +1711,8 @@ def old_to_new_json_one(old_json: dict[str, Any]) -> dict[str, Any]:
17101711

17111712

17121713
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
1714+
"""Converts the sonar-config projects old JSON report format to the new one"""
17131715
new_json = old_json.copy()
17141716
for k, v in new_json.items():
1715-
log.info("Convert %s %s", k, v)
17161717
new_json[k] = old_to_new_json_one(v)
17171718
return util.dict_to_list(new_json, "key")

sonar/qualitygates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,5 @@ def search_by_name(endpoint: pf.Platform, name: str) -> dict[str, QualityGate]:
564564

565565

566566
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
567+
"""Converts the sonar-config quality gates old JSON report format to the new one"""
567568
return util.dict_to_list(old_json, "name")

sonar/rules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ def severities(endpoint: platform.Platform, json_data: dict[str, any]) -> Option
582582

583583

584584
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
585+
"""Converts the sonar-config rules old JSON report format to the new one"""
585586
new_json = {}
586587
for k in ("instantiated", "extended", "standard", "thirdParty"):
587588
if k in old_json:

sonar/users.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,5 @@ def exists(endpoint: pf.Platform, login: str) -> bool:
571571

572572

573573
def old_to_new_json(old_json: dict[str, Any]) -> dict[str, Any]:
574+
"""Converts the sonar-config users old JSON report format to the new one"""
574575
return util.dict_to_list(old_json, "login")

0 commit comments

Comments
 (0)