@@ -447,17 +447,38 @@ def _finalize(self) -> None:
447447
448448 new_version = f'{ path } #{ source .commit } '
449449 targets = []
450- source_url = source .from_ or source .original
450+ source_url = urllib .parse .urlparse (source .from_ or source .original )
451+
452+ # https://github.com/npm/hosted-git-info
453+ hosted_git = [
454+ ('@github.com' , 'github' ),
455+ ('@bitbucket.org' , 'bitbucket' ),
456+ ('@gitlab.com' , 'gitlab' ),
457+ ('@gist.github.com' , 'gist' ),
458+ ('@git.sr.ht' , 'sourcehut' ),
459+ ]
460+ for domain , shortcut in hosted_git :
461+ if domain in source_url .netloc .lower ():
462+ targets .append (
463+ f"{ shortcut } :{ source_url .path [1 :].replace ('.git' , '' )} "
464+ f'#{ source_url .fragment } '
465+ )
466+ break
451467
452468 if (
453- source_url .startswith (GIT_URL_PREFIX + 'ssh' )
454- and ':' not in urllib . parse . urlparse ( source_url ) .netloc
469+ source_url .scheme . startswith (GIT_URL_PREFIX + 'ssh' )
470+ and ':' not in source_url .netloc
455471 ):
456- source_url = re .sub (r'(://[^/]+)/' , r'\1:' , source_url )
457- elif source_url .startswith (GIT_URL_PREFIX ):
458- targets .append (source_url [len (GIT_URL_PREFIX ) :])
459-
460- targets .append (source_url )
472+ path_match = re .compile (r'^/([^/]+)(.*)' ).match (source_url .path )
473+ if path_match :
474+ parent , child = path_match .groups ()
475+ source_url = source_url ._replace (
476+ netloc = f'{ source_url .netloc } :{ parent } ' , path = child
477+ )
478+ elif source_url .scheme .startswith (GIT_URL_PREFIX ):
479+ targets .append (source_url .geturl ()[len (GIT_URL_PREFIX ) :])
480+
481+ targets .append (source_url .geturl ())
461482 for t in targets :
462483 data [t ] = new_version
463484 data [t .replace ('#' + source .commit , '' )] = new_version
0 commit comments