@@ -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 ""
0 commit comments