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

fix(report): Parse data from sarif as URI #845

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
42 changes: 42 additions & 0 deletions tests/test_code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,46 @@ def finalize(self) -> str:
}
"""

sarif_report_uri = """
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Checkstyle",
"semanticVersion": "8.43",
"version": "8.43"
}
},
"results": [
{
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///my_path/my_file"
},
"region": {
"startColumn": 1,
"startLine": 1
}
}
}
],
"message": {
"text": "Error!"
},
"ruleId": "testRule"
}
]
}
]
}
"""

config_uncrustify = """
code_width = 120
input_tab_size = 2
Expand All @@ -189,6 +229,7 @@ def finalize(self) -> str:
[[sarif_report_minimal], True],
[[sarif_report], False],
[[sarif_report_split_uri], False],
[[sarif_report_uri], False],
[[json_report_minimal, sarif_report_minimal], True],
[[json_report, sarif_report], False],
[[json_report_minimal, sarif_report], False],
Expand All @@ -199,6 +240,7 @@ def finalize(self) -> str:
'sarif_no_issues',
'sarif_issues_found',
'sarif_split_uri_issues_found',
'sarif_uri',
'both_tested_no_issues',
'both_tested_issues_in_both',
'both_tested_issues_in_sarif',
Expand Down
12 changes: 6 additions & 6 deletions universum/modules/code_report_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def _process_one_sarif_issue(self, issue, root_uri_base_paths, who) -> None:
if location_data.get('address'):
continue # binary artifact can't be processed
raise ValueError("Unexpected lack of artifactLocation tag")
uri = artifact_data.get('uri')
i-keliukh marked this conversation as resolved.
Show resolved Hide resolved
if not uri:
raise ValueError("Unexpected lack of uri tag")
path = urllib.parse.unquote(urllib.parse.urlparse(uri).path)
if artifact_data.get('uriBaseId'):
uri = artifact_data.get('uri')
if not uri:
raise ValueError("Unexpected lack of uri tag")
# means path is relative, need to make absolute
uri_base_id = artifact_data.get('uriBaseId', '')
root_base_path = root_uri_base_paths.get(uri_base_id, '')
if uri_base_id and not root_base_path:
raise ValueError(f"Unexpected lack of 'originalUriBaseIds' value for {uri_base_id}")
path = str(Path(root_base_path, urllib.parse.unquote(uri)))
else:
path = urllib.parse.unquote(artifact_data.get('uri', ''))
path = str(Path(root_base_path) / path)
region_data = location_data.get('region')
if not region_data:
continue # TODO: cover this case as comment to the file as a whole
Expand Down
Loading