1717from typing import Optional
1818
1919import pytz
20- import saneyaml
2120from dateutil import parser as dateparser
2221from django .db .models .query import QuerySet
2322from fetchcode .vcs import fetch_via_vcs
4241from vulnerabilities .utils import AffectedPackage as LegacyAffectedPackage
4342from vulnerabilities .utils import build_description
4443from vulnerabilities .utils import get_affected_packages_by_patched_package
44+ from vulnerabilities .utils import load_yaml
4545from vulnerabilities .utils import nearest_patched_package
4646from vulnerabilities .utils import resolve_version_range
4747
@@ -86,7 +86,7 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
8686 glob = "**/*.yml"
8787 files = (p for p in path .glob (glob ) if p .is_file ())
8888 for file in files :
89- purl_type = get_gitlab_package_type (path = file )
89+ purl_type = get_gitlab_package_type (path = file , root = path )
9090 if not purl_type :
9191 logger .error (f"Unknow gitlab directory structure { file !r} " )
9292 continue
@@ -102,16 +102,14 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
102102 self .vcs_response .delete ()
103103
104104
105- def get_gitlab_package_type (path : Path ):
105+ def get_gitlab_package_type (path : Path , root : Path ):
106106 """
107- Return a package type extracted from a gitlab advisory path or None
107+ Return a package type extracted from a gitlab advisory path
108108 """
109- parts = path .parts
110-
111- if len (parts ) < 3 :
112- return
113-
114- return parts [3 ]
109+ relative = path .relative_to (root )
110+ parts = relative .parts
111+ gitlab_schema = parts [0 ]
112+ return gitlab_schema
115113
116114
117115def get_purl (package_slug ):
@@ -184,8 +182,8 @@ def parse_gitlab_advisory(file):
184182 identifiers:
185183 - "GMS-2018-26"
186184 """
187- with open (file ) as f :
188- gitlab_advisory = saneyaml . load ( f )
185+ gitlab_advisory = load_yaml (file )
186+
189187 if not isinstance (gitlab_advisory , dict ):
190188 logger .error (
191189 f"parse_gitlab_advisory: unknown gitlab advisory format in { file !r} with data: { gitlab_advisory !r} "
0 commit comments