@@ -543,7 +543,14 @@ def build_github_purl(url):
543543 # https://github.com/pombredanne/schematics.git
544544 git_pattern = r"https?://github.com/(?P<namespace>.+)/(?P<name>.+).(git)"
545545
546+ # https://github.com/<namespace>/<name>/commit/<sha>
547+ commit_pattern = (
548+ r"https?://github.com/"
549+ r"(?P<namespace>[^/]+)/(?P<name>[^/]+)/commit/(?P<version>[0-9a-fA-F]{7,40})/?$"
550+ )
551+
546552 patterns = (
553+ commit_pattern ,
547554 archive_tags_pattern ,
548555 archive_pattern ,
549556 raw_pattern ,
@@ -591,6 +598,13 @@ def build_github_purl(url):
591598 )
592599
593600
601+ # https://bitbucket.org/<namespace>/<name>/commits/<sha>
602+ bitbucket_commit_pattern = (
603+ r"https?://bitbucket.org/"
604+ r"(?P<namespace>[^/]+)/(?P<name>[^/]+)/commits/(?P<version>[0-9a-fA-F]{7,64})/?$"
605+ )
606+
607+
594608@purl_router .route ("https?://bitbucket\\ .org/.*" )
595609def build_bitbucket_purl (url ):
596610 """
@@ -599,7 +613,18 @@ def build_bitbucket_purl(url):
599613 https://bitbucket.org/TG1999/first_repo/src/master or
600614 https://bitbucket.org/TG1999/first_repo/src or
601615 https://bitbucket.org/TG1999/first_repo/src/master/new_folder
616+ https://bitbucket.org/TG1999/first_repo/commits/16a60c4a74ef477cd8c16ca82442eaab2fbe8c86
602617 """
618+ commit_matche = re .search (bitbucket_commit_pattern , url )
619+ if commit_matche :
620+ return PackageURL (
621+ type = "bitbucket" ,
622+ namespace = commit_matche .group ("namespace" ),
623+ name = commit_matche .group ("name" ),
624+ version = commit_matche .group ("version" ),
625+ qualifiers = {},
626+ subpath = "" ,
627+ )
603628
604629 segments = get_path_segments (url )
605630
@@ -651,7 +676,26 @@ def build_gitlab_purl(url):
651676 https://gitlab.com/TG1999/firebase/-/tree
652677 https://gitlab.com/TG1999/firebase/-/master
653678 https://gitlab.com/tg1999/Firebase/-/tree/master
679+ https://gitlab.com/tg1999/Firebase/-/commit/bf04e5f289885cf2f20a92b387bcc6df33e30809
654680 """
681+ # https://gitlab.com/<ns>/<name>/-/commit/<sha>
682+ commit_pattern = (
683+ r"https?://gitlab.com/"
684+ r"(?P<namespace>[^/]+)/(?P<name>[^/]+)/-/commit/"
685+ r"(?P<version>[0-9a-fA-F]{7,64})/?$"
686+ )
687+
688+ commit_matche = re .search (commit_pattern , url )
689+ if commit_matche :
690+ return PackageURL (
691+ type = "gitlab" ,
692+ namespace = commit_matche .group ("namespace" ),
693+ name = commit_matche .group ("name" ),
694+ version = commit_matche .group ("version" ),
695+ qualifiers = {},
696+ subpath = "" ,
697+ )
698+
655699 segments = get_path_segments (url )
656700
657701 if not len (segments ) >= 2 :
0 commit comments