Skip to content

Commit 21a5802

Browse files
committed
Add clone functionality in Importer
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 420c9a0 commit 21a5802

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

vulnerabilities/importer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ class Importer:
294294
spdx_license_expression = ""
295295
license_url = ""
296296
notice = ""
297+
vcs_response = None
297298

298299
def __init__(self):
299300
if not self.spdx_license_expression:
@@ -319,6 +320,14 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
319320
"""
320321
raise NotImplementedError
321322

323+
def clone(self, repo_url):
324+
try:
325+
self.vcs_response = fetch_via_vcs(repo_url)
326+
except Exception as e:
327+
msg = f"Failed to fetch {repo_url} via vcs: {e}"
328+
logger.error(msg)
329+
raise ForkError(msg) from e
330+
322331

323332
class ForkError(Exception):
324333
pass

vulnerabilities/importers/npm.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from vulnerabilities.importer import AdvisoryData
2222
from vulnerabilities.importer import AffectedPackage
23-
from vulnerabilities.importer import GitImporter
23+
from vulnerabilities.importer import Importer
2424
from vulnerabilities.importer import Reference
2525
from vulnerabilities.importer import VulnerabilitySeverity
2626
from vulnerabilities.severity_systems import CVSSV2
@@ -29,16 +29,14 @@
2929
from vulnerabilities.utils import load_json
3030

3131

32-
class NpmImporter(GitImporter):
32+
class NpmImporter(Importer):
3333
spdx_license_expression = "MIT"
3434
license_url = "https://github.com/nodejs/security-wg/blob/main/LICENSE.md"
35-
36-
def __init__(self):
37-
super().__init__(repo_url="git+https://github.com/nodejs/security-wg")
35+
repo_url = "git+https://github.com/nodejs/security-wg"
3836

3937
def advisory_data(self) -> Iterable[AdvisoryData]:
4038
try:
41-
self.clone()
39+
self.clone(self.repo_url)
4240
path = Path(self.vcs_response.dest_dir)
4341

4442
vuln = path / "vuln"

0 commit comments

Comments
 (0)