From 54a558204f05a0f07927dde6f10e0cf3e9711aa0 Mon Sep 17 00:00:00 2001 From: Thomas Gagneret Date: Mon, 26 Aug 2024 09:39:00 +0200 Subject: [PATCH] [cmd] Add support for sarif export in parser cmd --- analyzer/codechecker_analyzer/cmd/parse.py | 7 +++++-- .../codechecker_report_converter/report/output/sarif.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tools/report-converter/codechecker_report_converter/report/output/sarif.py diff --git a/analyzer/codechecker_analyzer/cmd/parse.py b/analyzer/codechecker_analyzer/cmd/parse.py index 5c0124aaa5..c0fb770817 100644 --- a/analyzer/codechecker_analyzer/cmd/parse.py +++ b/analyzer/codechecker_analyzer/cmd/parse.py @@ -21,7 +21,7 @@ from codechecker_report_converter.report import report_file, \ reports as reports_helper from codechecker_report_converter.report.output import baseline, codeclimate, \ - gerrit, json as report_to_json, plaintext + gerrit, sarif, json as report_to_json, plaintext from codechecker_report_converter.report.output.html import \ html as report_to_html from codechecker_report_converter.report.statistics import Statistics @@ -47,7 +47,7 @@ def init_logger(level, stream=None, logger_name='system'): LOG = logger.get_logger(logger_name) -EXPORT_TYPES = ['html', 'json', 'codeclimate', 'gerrit', 'baseline'] +EXPORT_TYPES = ['html', 'json', 'codeclimate', 'gerrit', 'baseline', 'sarif'] EPILOG_ENV_VAR = """ CC_CHANGED_FILES Path of changed files json from Gerrit. Use it when @@ -492,6 +492,9 @@ def get_output_file_path(default_file_name: str) -> Optional[str]: elif export == 'gerrit': data = gerrit.convert(all_reports) dump_json_output(data, get_output_file_path("reports.json")) + elif export == 'sarif': + data = sarif.convert(all_reports) + dump_json_output(data, get_output_file_path("reports.json")) elif export == 'baseline': data = baseline.convert(all_reports) output_path = get_output_file_path("reports.baseline") diff --git a/tools/report-converter/codechecker_report_converter/report/output/sarif.py b/tools/report-converter/codechecker_report_converter/report/output/sarif.py new file mode 100644 index 0000000000..1c566a54a9 --- /dev/null +++ b/tools/report-converter/codechecker_report_converter/report/output/sarif.py @@ -0,0 +1,8 @@ +from typing import Dict, List + +from codechecker_report_converter.report import Report +from codechecker_report_converter.report.parser import sarif + +def convert(reports: List[Report]) -> Dict: + sarif_parser = sarif.Parser() + return sarif_parser.convert(reports)