scripts: zephyr_module: Fix purl regex

Remove root domain from PURL type
Nested PURL namespaces were not correctly detected.

Signed-off-by: Thomas Gagneret <thomas.gagneret@hexploy.com>
This commit is contained in:
Thomas Gagneret 2025-02-09 16:53:49 +01:00 committed by Benjamin Cabé
commit d6c59f0b4d

View file

@ -77,12 +77,12 @@ class Walker:
purl = None purl = None
# This is designed to match repository with the following url pattern: # This is designed to match repository with the following url pattern:
# '<protocol><base_url>/<namespace>/<package> # '<protocol><type>/<namespace>/<package>
COMMON_GIT_URL_REGEX=r'((git@|http(s)?:\/\/)(?P<base_url>[\w\.@]+)(\/|:))(?P<namespace>[\w,\-,\_]+)\/(?P<package>[\w,\-,\_]+)(.git){0,1}((\/){0,1})$' COMMON_GIT_URL_REGEX=r'((git@|http(s)?:\/\/)(?P<type>[\w\.@]+)(\.\w+)(\/|:))(?P<namespace>[\w,\-,\_\/]+)\/(?P<package>[\w,\-,\_]+)(.git){0,1}((\/){0,1})$'
match = re.fullmatch(COMMON_GIT_URL_REGEX, url) match = re.fullmatch(COMMON_GIT_URL_REGEX, url)
if match: if match:
purl = f'pkg:{match.group("base_url")}/{match.group("namespace")}/{match.group("package")}' purl = f'pkg:{match.group("type")}/{match.group("namespace")}/{match.group("package")}'
if purl and (version or len(version) > 0): if purl and (version or len(version) > 0):
purl += f'@{version}' purl += f'@{version}'