Skip to content

Commit 0b9f837

Browse files
committed
Refactor CSV processing to avoid duplicate iteration over items
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent fe1d9ea commit 0b9f837

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

vulnerabilities/pipelines/v2_importers/project_kb_msr2019_importer.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,35 @@ def collect_advisories(self) -> Iterable[AdvisoryData]:
5656
with open(csv_path, newline="", encoding="utf-8") as f:
5757
reader = csv.reader(f)
5858
next(reader, None) # skip header
59-
rows = [r for r in reader if len(r) == 4 and r[0]] # vuln_id, vcs_url, commit_hash, poc
60-
61-
for vuln_id, vcs_url, commit_hash, _ in rows:
62-
if not vuln_id or not vcs_url or not commit_hash:
63-
continue
64-
65-
patches = []
66-
affected_packages = []
67-
references = []
68-
append_patch_classifications(
69-
url=vcs_url,
70-
commit_hash=commit_hash,
71-
patch_text=None,
72-
affected_packages=affected_packages,
73-
references=references,
74-
patches=patches,
75-
)
76-
77-
yield AdvisoryData(
78-
advisory_id=vuln_id,
79-
affected_packages=affected_packages,
80-
patches=patches,
81-
references_v2=references,
82-
url="https://github.com/SAP/project-kb/blob/main/MSR2019/dataset/vulas_db_msr2019_release.csv",
83-
)
59+
60+
for row in reader:
61+
if len(row) != 4:
62+
continue
63+
64+
vuln_id, vcs_url, commit_hash, poc = row
65+
66+
if not vuln_id or not vcs_url or not commit_hash:
67+
continue
68+
69+
patches = []
70+
affected_packages = []
71+
references = []
72+
append_patch_classifications(
73+
url=vcs_url,
74+
commit_hash=commit_hash,
75+
patch_text=None,
76+
affected_packages=affected_packages,
77+
references=references,
78+
patches=patches,
79+
)
80+
81+
yield AdvisoryData(
82+
advisory_id=vuln_id,
83+
affected_packages=affected_packages,
84+
patches=patches,
85+
references_v2=references,
86+
url="https://github.com/SAP/project-kb/blob/main/MSR2019/dataset/vulas_db_msr2019_release.csv",
87+
)
8488

8589
def clean_downloads(self):
8690
"""Remove the cloned repository from disk."""

0 commit comments

Comments
 (0)