Skip to content

Commit

Permalink
Add severity to CodeClimate export
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarno Malmari committed Jun 11, 2021
1 parent fad91e1 commit 45dfd69
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ def parse_convert_reports(input_dirs: List[str],

number_of_reports = len(all_reports)
if out_format == "codeclimate":
return codeclimate.convert(all_reports), number_of_reports
return (codeclimate.convert(all_reports, severity_map),
number_of_reports)

if out_format == "gerrit":
return gerrit.convert(all_reports, severity_map), number_of_reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def test_codeclimate_output(self):
'description': 'Duplicate code detected',
'categories': ['Bug Risk'],
'fingerprint': '3d15184f38c5fa57e479b744fe3f5035',
'severity': 'minor',
'location': {
'path': 'notes.cpp',
'lines': {
Expand Down
18 changes: 15 additions & 3 deletions codechecker_common/output/codeclimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from codechecker_common.report import Report


def convert(reports: List[Report]) -> Dict:
def convert(reports: List[Report], severity_map: Dict[str, str]) -> Dict:
"""Convert the given reports to codeclimate format.
This function will convert the given report to Code Climate format.
Expand All @@ -22,18 +22,30 @@ def convert(reports: List[Report]) -> Dict:
"""
codeclimate_reports = []
for report in reports:
codeclimate_reports.append(__to_codeclimate(report))
codeclimate_reports.append(__to_codeclimate(report, severity_map))
return codeclimate_reports


def __to_codeclimate(report: Report) -> Dict:
__codeclimate_severity_map = {
'CRITICAL': 'critical',
'HIGH': 'major',
'MEDIUM': 'minor',
'LOW': 'minor',
'STYLE': 'info',
'UNSPECIFIED': 'info',
}


def __to_codeclimate(report: Report, severity_map: Dict[str, str]) -> Dict:
"""Convert a Report to Code Climate format."""
return {
"type": "issue",
"check_name": report.check_name,
"description": report.description,
"categories": ["Bug Risk"],
"fingerprint": report.report_hash,
"severity": __codeclimate_severity_map.get(
severity_map.get(report.check_name, 'UNSPECIFIED'), 'info'),
"location": {
"path": report.file_path,
"lines": {
Expand Down
2 changes: 1 addition & 1 deletion web/client/codechecker_client/cmd_line_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def print_reports(client,
output_formats.remove('gerrit')

if 'codeclimate' in output_formats:
cc_reports = codeclimate.convert(reports)
cc_reports = codeclimate.convert(reports, context.severity_map)
# Codelimate was the only format specified.
if selected_output_format_num == 1 and not output_dir:
print(json.dumps(cc_reports))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def test_diff_codeclimate_output(self):
"Bug Risk"
],
"fingerprint": "c2132f78ef0e01bdb5eacf616048625f",
"severity": "minor",
"location": {
"path": "new_delete.cpp",
"lines": {
Expand Down

0 comments on commit 45dfd69

Please sign in to comment.