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
5 changes: 5 additions & 0 deletions src/codemodder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def parse_args(argv, codemod_registry: CodemodRegistry):
action=CsvListAction,
help="Comma-separated set of path(s) to Sonar hotspots JSON file(s) to feed to the codemods",
)
parser.add_argument(
"--sonar-json",
action=CsvListAction,
help="Comma-separated set of path(s) to Sonar JSON file(s) to feed to the codemods",
)
parser.add_argument(
"--defectdojo-findings-json",
action=CsvListAction,
Expand Down
12 changes: 12 additions & 0 deletions src/codemodder/codemodder.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,20 @@ def _run_cli(original_args) -> int:
logger.error(err)
return 1

if argv.sonar_issues_json:
print(
"NOTE: --sonar-issues-json is deprecated, use --sonar-json instead",
file=sys.stderr,
)
if argv.sonar_hotspots_json:
print(
"NOTE: --sonar-hotspots-json is deprecated, use --sonar-json instead",
file=sys.stderr,
)

tool_result_files_map["sonar"].extend(argv.sonar_issues_json or [])
tool_result_files_map["sonar"].extend(argv.sonar_hotspots_json or [])
tool_result_files_map["sonar"].extend(argv.sonar_json or [])
tool_result_files_map["defectdojo"].extend(argv.defectdojo_findings_json or [])

logger.info("command: %s %s", Path(sys.argv[0]).name, " ".join(original_args))
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sonar_results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path

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


def test_combined_json(tmpdir):
issues = json.loads(SAMPLE_DIR.joinpath("sonar_issues.json").read_text())
hotspots = json.loads(SAMPLE_DIR.joinpath("sonar_hotspots.json").read_text())
Path(tmpdir).joinpath("combined.json").write_text(
json.dumps({"issues": issues["issues"] + hotspots["hotspots"]})
)

results = SonarResultSet.from_json(Path(tmpdir).joinpath("combined.json"))
assert len(results) == 36


def test_empty_issues(tmpdir, caplog):
empty_json = tmpdir / "empty.json"
empty_json.write_text('{"issues": []}', encoding="utf-8")
Expand Down
Loading