Skip to content

Commit

Permalink
Fix finding IDs for semgrep sarifs (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella authored Dec 20, 2024
1 parent b4d64d7 commit 8d0af71
Showing 1 changed file with 3 additions and 24 deletions.
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

0 comments on commit 8d0af71

Please sign in to comment.