Skip to content

Commit

Permalink
[cmd] Add support for sarif export in parser cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
tgagneret-embedded committed Aug 26, 2024
1 parent b843db0 commit 54a5582
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 54a5582

Please sign in to comment.