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 sarif parser #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions run_community_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_files_to_analyze(code_path: str) -> set[str]:
}


def main(argv: list[str] | None = None) -> None:
def main() -> None:
"""Runs the CLI."""
code_path = os.getenv("CODE_PATH", "/code")
toolbox_path = os.getenv("TOOLBOX_PATH", "/toolbox")
Expand All @@ -65,11 +65,12 @@ def main(argv: list[str] | None = None) -> None:
help="Which community analyzer to run. Example: 'kube-linter'",
required=False,
)
if argv:
args = parser.parse_args(argv, namespace=CommunityAnalyzerArgs)
# analyzer name is mandatory in case of community analyzers but not custom analyzers
if analyzer_name := args.analyzer:
issue_map_path = get_issue_map(analyzer_name)
args = parser.parse_args(argv, namespace=CommunityAnalyzerArgs)

# analyzer name is mandatory in case of community analyzers but not custom analyzers
if analyzer_name := args.analyzer:
logger.info("Fetching issue map for: %s", analyzer_name)
issue_map_path = get_issue_map(analyzer_name)

modified_files = get_files_to_analyze(code_path)
run_sarif_parser(
Expand Down
9 changes: 8 additions & 1 deletion sarif-parser/src/sarif_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""sarif-parser - Parse SARIF reports and covert them to DeepSource issues."""

from __future__ import annotations

import hashlib
Expand Down Expand Up @@ -57,6 +58,7 @@ def parse(

deepsource_issues: list[Issue] = []
total_report_issues = 0
issue_count_in_issues_map = 0
for run in sarif_data["runs"]:
total_report_issues += len(run["results"])
for issue in run["results"]:
Expand Down Expand Up @@ -121,9 +123,11 @@ def parse(

logger.info(
"Total issues in SARIF report: %s. \n"
"Issues extracted for the run in files sent for analysis: %s",
"Issues extracted for the run in files sent for analysis: %s. \n"
"Sanitized issues count with IDs in issue map: %s.",
total_report_issues,
len(deepsource_issues),
issue_count_in_issues_map,
)

return deepsource_issues
Expand Down Expand Up @@ -174,6 +178,9 @@ def run_sarif_parser(
sentry.raise_info(
f"Could not find issue map at {issue_map_path} for analyzer."
)
logger.warning(
"Could not find issue map at %s for analyzer.", issue_map_path
)

# Run parser
deepsource_issues = []
Expand Down
Loading