diff --git a/src/packageurl/contrib/url2purl.py b/src/packageurl/contrib/url2purl.py index 4bb5274..2353b0b 100644 --- a/src/packageurl/contrib/url2purl.py +++ b/src/packageurl/contrib/url2purl.py @@ -543,7 +543,14 @@ def build_github_purl(url): # https://github.com/pombredanne/schematics.git git_pattern = r"https?://github.com/(?P.+)/(?P.+).(git)" + # https://github.com///commit/ + commit_pattern = ( + r"https?://github.com/" + r"(?P[^/]+)/(?P[^/]+)/commit/(?P[0-9a-fA-F]{7,40})/?$" + ) + patterns = ( + commit_pattern, archive_tags_pattern, archive_pattern, raw_pattern, @@ -591,6 +598,13 @@ def build_github_purl(url): ) +# https://bitbucket.org///commits/ +bitbucket_commit_pattern = ( + r"https?://bitbucket.org/" + r"(?P[^/]+)/(?P[^/]+)/commits/(?P[0-9a-fA-F]{7,64})/?$" +) + + @purl_router.route("https?://bitbucket\\.org/.*") def build_bitbucket_purl(url): """ @@ -599,7 +613,18 @@ def build_bitbucket_purl(url): https://bitbucket.org/TG1999/first_repo/src/master or https://bitbucket.org/TG1999/first_repo/src or https://bitbucket.org/TG1999/first_repo/src/master/new_folder + https://bitbucket.org/TG1999/first_repo/commits/16a60c4a74ef477cd8c16ca82442eaab2fbe8c86 """ + commit_matche = re.search(bitbucket_commit_pattern, url) + if commit_matche: + return PackageURL( + type="bitbucket", + namespace=commit_matche.group("namespace"), + name=commit_matche.group("name"), + version=commit_matche.group("version"), + qualifiers={}, + subpath="", + ) segments = get_path_segments(url) @@ -651,7 +676,26 @@ def build_gitlab_purl(url): https://gitlab.com/TG1999/firebase/-/tree https://gitlab.com/TG1999/firebase/-/master https://gitlab.com/tg1999/Firebase/-/tree/master + https://gitlab.com/tg1999/Firebase/-/commit/bf04e5f289885cf2f20a92b387bcc6df33e30809 """ + # https://gitlab.com///-/commit/ + commit_pattern = ( + r"https?://gitlab.com/" + r"(?P[^/]+)/(?P[^/]+)/-/commit/" + r"(?P[0-9a-fA-F]{7,64})/?$" + ) + + commit_matche = re.search(commit_pattern, url) + if commit_matche: + return PackageURL( + type="gitlab", + namespace=commit_matche.group("namespace"), + name=commit_matche.group("name"), + version=commit_matche.group("version"), + qualifiers={}, + subpath="", + ) + segments = get_path_segments(url) if not len(segments) >= 2: diff --git a/tests/contrib/data/url2purl.json b/tests/contrib/data/url2purl.json index 3b6efb8..3a99dd2 100644 --- a/tests/contrib/data/url2purl.json +++ b/tests/contrib/data/url2purl.json @@ -274,5 +274,8 @@ "": null, "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm": "pkg:generic/code.google.com/android-notifier?download_url=https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm", "https://cran.r-project.org/src/contrib/jsonlite_1.8.8.tar.gz": "pkg:cran/jsonlite@1.8.8", - "https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz": "pkg:cran/curl@4.3.2?download_url=https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz" + "https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz": "pkg:cran/curl@4.3.2?download_url=https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz", + "https://github.com/TG1999/first_repo/commit/98e516011d6e096e25247b82fc5f196bbeecff10": "pkg:github/tg1999/first_repo@98e516011d6e096e25247b82fc5f196bbeecff10", + "https://gitlab.com/TG1999/first_repo/-/commit/bf04e5f289885cf2f20a92b387bcc6df33e30809": "pkg:gitlab/tg1999/first_repo@bf04e5f289885cf2f20a92b387bcc6df33e30809", + "https://bitbucket.org/TG1999/first_repo/commits/16a60c4a74ef477cd8c16ca82442eaab2fbe8c86": "pkg:bitbucket/tg1999/first_repo@16a60c4a74ef477cd8c16ca82442eaab2fbe8c86" }