Skip to content

Commit

Permalink
Merge pull request #3202 from csordasmarton/fix_codeclimate_output
Browse files Browse the repository at this point in the history
[fix] Fix file path in codeclimate output
  • Loading branch information
csordasmarton authored Mar 1, 2021
2 parents 6788bf4 + 7d21a79 commit dc4cc98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
5 changes: 1 addition & 4 deletions codechecker_common/output/codeclimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# -------------------------------------------------------------------------
"""Codeclimate output helpers."""

import os
from typing import Dict, List

from codechecker_common.report import Report
Expand All @@ -29,16 +28,14 @@ def convert(reports: List[Report]) -> Dict:

def __to_codeclimate(report: Report) -> Dict:
"""Convert a Report to Code Climate format."""
_, file_name = os.path.split(report.file_path)

return {
"type": "issue",
"check_name": report.check_name,
"description": report.description,
"categories": ["Bug Risk"],
"fingerprint": report.report_hash,
"location": {
"path": file_name,
"path": report.file_path,
"lines": {
"begin": report.main['location']['line']
}
Expand Down
32 changes: 32 additions & 0 deletions web/tests/functional/diff_local_remote/test_diff_local_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,38 @@ def test_diff_codeclimate_output(self):

shutil.rmtree(export_dir)

def test_diff_no_trim_codeclimate_output(self):
""" Test codeclimate output when using diff and don't set env vars. """
base_run_name = self._run_names[0]

export_dir_path = os.path.join(self._local_reports, "export_dir")

diff_cmd = [self._codechecker_cmd, "cmd", "diff",
"--unresolved",
"--url", self._url,
"-b", base_run_name,
"-n", self._local_reports,
"-o", "codeclimate",
"-e", export_dir_path]

self.run_cmd(diff_cmd, self._env)
issues_file_path = os.path.join(export_dir_path,
'codeclimate_issues.json')
self.assertTrue(os.path.exists(issues_file_path))

with open(issues_file_path, 'r',
encoding="utf-8", errors="ignore") as f:
issues = json.load(f)

malloc_issues = [i for i in issues if i["check_name"] == "unix.Malloc"]
self.assertNotEqual(len(malloc_issues), 0)

file_path = malloc_issues[0]["location"]["path"]
self.assertTrue(os.path.isabs(file_path))
self.assertTrue(file_path.endswith(f"/new_delete.cpp"))

shutil.rmtree(export_dir_path)

def test_diff_multiple_output(self):
""" Test multiple output type for diff command. """
base_run_name = self._run_names[0]
Expand Down

0 comments on commit dc4cc98

Please sign in to comment.