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 3, 2021
1 parent 3a12734 commit ca9f933
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion analyzer/codechecker_analyzer/cmd/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ 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
15 changes: 12 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,27 @@ 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

__codeclimate_severity_map = {
'UNDEFINED': 'info',
'LOW': 'minor',
'STYLE': 'minor',
'MEDIUM': 'high',
'HIGH': 'critical',
}

def __to_codeclimate(report: Report) -> Dict:
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, 'UNDEFINED'), 'info'),
"location": {
"path": report.file_path,
"lines": {
Expand Down

0 comments on commit ca9f933

Please sign in to comment.