2424
2525import  pytz 
2626from  dateutil  import  parser  as  dateparser 
27+ from  fetchcode .vcs  import  VCSResponse 
2728from  fetchcode .vcs  import  fetch_via_vcs 
2829from  license_expression  import  Licensing 
2930from  packageurl  import  PackageURL 
@@ -288,6 +289,10 @@ class InvalidSPDXLicense(Exception):
288289    pass 
289290
290291
292+ class  ForkError (Exception ):
293+     pass 
294+ 
295+ 
291296class  Importer :
292297    """ 
293298    An Importer collects data from various upstreams and returns corresponding AdvisoryData objects 
@@ -297,7 +302,7 @@ class Importer:
297302    spdx_license_expression  =  "" 
298303    license_url  =  "" 
299304    notice  =  "" 
300-     vcs_response  =  None 
305+     vcs_response :  VCSResponse  =  None 
301306
302307    def  __init__ (self ):
303308        if  not  self .spdx_license_expression :
@@ -324,47 +329,18 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
324329        raise  NotImplementedError 
325330
326331    def  clone (self , repo_url ):
332+         """ 
333+         Clone the repo at repo_url and return the VCSResponse object 
334+         """ 
327335        try :
328336            self .vcs_response  =  fetch_via_vcs (repo_url )
337+             return  self .vcs_response 
329338        except  Exception  as  e :
330339            msg  =  f"Failed to fetch { repo_url }   via vcs: { e }  " 
331340            logger .error (msg )
332341            raise  ForkError (msg ) from  e 
333342
334343
335- class  ForkError (Exception ):
336-     pass 
337- 
338- 
339- class  GitImporter (Importer ):
340-     def  __init__ (self , repo_url ):
341-         super ().__init__ ()
342-         self .repo_url  =  repo_url 
343-         self .vcs_response  =  None 
344- 
345-     def  __enter__ (self ):
346-         super ().__enter__ ()
347-         self .clone ()
348-         return  self 
349- 
350-     def  __exit__ (self ):
351-         self .vcs_response .delete ()
352- 
353-     def  clone (self ):
354-         try :
355-             self .vcs_response  =  fetch_via_vcs (self .repo_url )
356-         except  Exception  as  e :
357-             msg  =  f"Failed to fetch { self .repo_url }   via vcs: { e }  " 
358-             logger .error (msg )
359-             raise  ForkError (msg ) from  e 
360- 
361-     def  advisory_data (self ) ->  Iterable [AdvisoryData ]:
362-         """ 
363-         Return AdvisoryData objects corresponding to the data being imported 
364-         """ 
365-         raise  NotImplementedError 
366- 
367- 
368344# TODO: Needs rewrite 
369345class  OvalImporter (Importer ):
370346    """ 
0 commit comments