Skip to content

Commit eaa075b

Browse files
committed
Add --sonar-json CLI flag; deprecate existing sonar flags
1 parent 47680c3 commit eaa075b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/codemodder/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ def parse_args(argv, codemod_registry: CodemodRegistry):
174174
action=CsvListAction,
175175
help="Comma-separated set of path(s) to Sonar hotspots JSON file(s) to feed to the codemods",
176176
)
177+
parser.add_argument(
178+
"--sonar-json",
179+
action=CsvListAction,
180+
help="Comma-separated set of path(s) to Sonar JSON file(s) to feed to the codemods",
181+
)
177182
parser.add_argument(
178183
"--defectdojo-findings-json",
179184
action=CsvListAction,

src/codemodder/codemodder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,20 @@ def _run_cli(original_args) -> int:
239239
logger.error(err)
240240
return 1
241241

242+
if argv.sonar_issues_json:
243+
print(
244+
"NOTE: --sonar-issues-json is deprecated, use --sonar-json instead",
245+
file=sys.stderr,
246+
)
247+
if argv.sonar_hotspots_json:
248+
print(
249+
"NOTE: --sonar-hotspots-json is deprecated, use --sonar-json instead",
250+
file=sys.stderr,
251+
)
252+
242253
tool_result_files_map["sonar"].extend(argv.sonar_issues_json or [])
243254
tool_result_files_map["sonar"].extend(argv.sonar_hotspots_json or [])
255+
tool_result_files_map["sonar"].extend(argv.sonar_json or [])
244256
tool_result_files_map["defectdojo"].extend(argv.defectdojo_findings_json or [])
245257

246258
logger.info("command: %s %s", Path(sys.argv[0]).name, " ".join(original_args))

tests/test_sonar_results.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from pathlib import Path
23

34
from core_codemods.sonar.results import SonarResult, SonarResultSet
@@ -45,6 +46,17 @@ def test_parse_hotspots_json():
4546
assert len(results) == 2
4647

4748

49+
def test_combined_json(tmpdir):
50+
issues = json.loads(SAMPLE_DIR.joinpath("sonar_issues.json").read_text())
51+
hotspots = json.loads(SAMPLE_DIR.joinpath("sonar_hotspots.json").read_text())
52+
Path(tmpdir).joinpath("combined.json").write_text(
53+
json.dumps({"issues": issues["issues"] + hotspots["hotspots"]})
54+
)
55+
56+
results = SonarResultSet.from_json(Path(tmpdir).joinpath("combined.json"))
57+
assert len(results) == 36
58+
59+
4860
def test_empty_issues(tmpdir, caplog):
4961
empty_json = tmpdir / "empty.json"
5062
empty_json.write_text('{"issues": []}', encoding="utf-8")

0 commit comments

Comments
 (0)