Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Add support for sarif export in parser cmd #4327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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,9 @@
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)