Skip to content

Commit d41881e

Browse files
committed
implement finding msg
1 parent 5b8ef32 commit d41881e

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

src/codemodder/codeql.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ class CodeQLResult(SarifResult):
4343
def from_sarif(
4444
cls, sarif_result, sarif_run, truncate_rule_id: bool = False
4545
) -> Self:
46+
rule_id = cls.extract_rule_id(sarif_result, sarif_run, truncate_rule_id)
47+
text_for_rule = get_text_for_rule(rule_id, sarif_run)
48+
finding_msg = f"""{sarif_result['message']['text']}\n{text_for_rule}"""
4649
return cls(
47-
rule_id=(
48-
rule_id := cls.extract_rule_id(
49-
sarif_result, sarif_run, truncate_rule_id
50-
)
51-
),
50+
rule_id=rule_id,
5251
locations=cls.extract_locations(sarif_result),
5352
codeflows=cls.extract_code_flows(sarif_result),
5453
related_locations=cls.extract_related_locations(sarif_result),
@@ -62,6 +61,7 @@ def from_sarif(
6261
# url=,
6362
),
6463
),
64+
finding_msg=finding_msg,
6565
)
6666

6767

@@ -80,3 +80,12 @@ def from_sarif(cls, sarif_file: str | Path, truncate_rule_id: bool = False) -> S
8080
)
8181
result_set.add_result(codeql_result)
8282
return result_set
83+
84+
85+
# TODO: cache, make hashable
86+
def get_text_for_rule(rule_id: str, sarif_run: dict) -> str:
87+
for ext in sarif_run["tool"]["extensions"]:
88+
for rule in ext.get("rules", []):
89+
if rule["id"] == rule_id:
90+
return f"{rule["fullDescription"]["text"]}\n{rule["help"]["text"]}"
91+
return ""

src/codemodder/result.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __hash__(self):
7676
@dataclass(frozen=True, kw_only=True)
7777
class SASTResult(Result):
7878
finding_id: str
79+
finding_msg: str | None
7980

8081

8182
@dataclass(frozen=True, kw_only=True)

src/codemodder/semgrep.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def from_sarif(
7272
url=semgrep_url_from_id(rule_id),
7373
),
7474
),
75+
finding_msg="TODO",
7576
)
7677

7778

src/core_codemods/defectdojo/results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def from_result(cls, result: dict) -> Self:
3737
url=None,
3838
),
3939
),
40+
finding_msg="TODO",
4041
)
4142

4243
@override

src/core_codemods/sonar/results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def from_result(cls, result: dict) -> Self:
7676
url=sonar_url_from_id(rule_id),
7777
),
7878
),
79+
finding_msg="TODO",
7980
)
8081

8182
def match_location(self, pos, node):

0 commit comments

Comments
 (0)