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 finding IDs for semgrep sarifs #960

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
27 changes: 3 additions & 24 deletions src/codemodder/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from typing_extensions import Self, override

from codemodder.codetf import Finding, Rule
from codemodder.context import CodemodExecutionContext
from codemodder.logging import logger
from codemodder.result import LineInfo, Result, ResultSet, SarifLocation, SarifResult
Expand Down Expand Up @@ -48,31 +47,11 @@ class SemgrepResult(SarifResult):
location_type = SemgrepLocation

@classmethod
def from_sarif(
cls, sarif_result, sarif_run, truncate_rule_id: bool = False
) -> Self:
# avoid circular import
def rule_url_from_id(cls, sarif_result, sarif_run, rule_id):
del sarif_result, sarif_run
from core_codemods.semgrep.api import semgrep_url_from_id

return cls(
rule_id=(
rule_id := cls.extract_rule_id(
sarif_result, sarif_run, truncate_rule_id
)
),
locations=cls.extract_locations(sarif_result),
codeflows=cls.extract_code_flows(sarif_result),
related_locations=cls.extract_related_locations(sarif_result),
finding_id=rule_id,
finding=Finding(
id=rule_id,
rule=Rule(
id=rule_id,
name=rule_id,
url=semgrep_url_from_id(rule_id),
),
),
)
return semgrep_url_from_id(rule_id)


class SemgrepResultSet(ResultSet):
Expand Down
Loading