Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
163 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,41 @@ | ||
import json | ||
from typing import List, Optional, Tuple | ||
|
||
from mythx_cli.formatter.json import JSONFormatter | ||
from mythx_models.response import AnalysisInputResponse, DetectedIssuesResponse | ||
from mythx_models.response.issue import Severity, SourceType | ||
|
||
from mythx_cli.formatter.json import JSONFormatter | ||
|
||
|
||
class SonarQubeFormatter(JSONFormatter): | ||
report_requires_input = False | ||
|
||
@staticmethod | ||
def format_detected_issues(resp: DetectedIssuesResponse, inp: AnalysisInputResponse) -> str: | ||
def format_detected_issues( | ||
issues_list: List[Tuple[DetectedIssuesResponse, Optional[AnalysisInputResponse]]] | ||
) -> str: | ||
new_reports = [] | ||
for report in resp.issue_reports: | ||
for issue in report: | ||
new_issue = {} | ||
for loc in issue.decoded_locations: | ||
for raw_loc in issue.locations: | ||
if raw_loc.source_type != SourceType.SOLIDITY_FILE: | ||
continue | ||
new_issue["onInputFile"] = raw_loc.source_list[raw_loc.source_map.components[0].file_id] | ||
new_issue["atLineNr"] = loc.start_line | ||
for resp, _ in issues_list: | ||
for report in resp.issue_reports: | ||
for issue in report: | ||
new_issue = {} | ||
for loc in issue.decoded_locations: | ||
for raw_loc in issue.locations: | ||
if raw_loc.source_type != SourceType.SOLIDITY_FILE: | ||
continue | ||
new_issue["onInputFile"] = raw_loc.source_list[raw_loc.source_map.components[0].file_id] | ||
new_issue["atLineNr"] = loc.start_line | ||
|
||
new_issue.update( | ||
{ | ||
"linterName": "mythx", | ||
"forRule": issue.swc_id, | ||
"ruleType": issue.severity.name, | ||
"remediationEffortMinutes": 0, | ||
"severity": "vulnerability" if issue.severity == Severity.HIGH else issue.severity.name, | ||
"message": issue.description_long, | ||
} | ||
) | ||
new_reports.append(new_issue) | ||
new_issue.update( | ||
{ | ||
"linterName": "mythx", | ||
"forRule": issue.swc_id, | ||
"ruleType": issue.severity.name, | ||
"remediationEffortMinutes": 0, | ||
"severity": "vulnerability" if issue.severity == Severity.HIGH else issue.severity.name, | ||
"message": issue.description_long, | ||
} | ||
) | ||
new_reports.append(new_issue) | ||
|
||
return json.dumps(new_reports) |
Oops, something went wrong.