-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupdate_finding_metadata.py
More file actions
37 lines (30 loc) · 1.11 KB
/
update_finding_metadata.py
File metadata and controls
37 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from codemodder.codemods.base_codemod import ToolRule
from codemodder.codetf import Change, ChangeSet
def update_finding_metadata(
tool_rules: list[ToolRule],
changesets: list[ChangeSet],
) -> list[ChangeSet]:
if not (tool_rule_map := {rule.id: (rule.name, rule.url) for rule in tool_rules}):
return changesets
new_changesets: list[ChangeSet] = []
for changeset in changesets:
new_changes: list[Change] = []
for change in changeset.changes:
new_changes.append(
change.with_findings(
[
(
finding.with_rule(*tool_rule_map[finding.rule.id])
if finding.rule.id in tool_rule_map
else finding
)
for finding in change.fixedFindings or []
]
or None
)
)
new_changesets.append(changeset.with_changes(new_changes))
return new_changesets