@@ -484,7 +484,7 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
484484
485485 @classmethod
486486 def is_valid (cls , url : str , is_explicit : Optional [bool ] = None ) -> bool :
487- """Whether URL is compatible included Git URL matchers or not.
487+ r """Whether URL is compatible included Git URL matchers or not.
488488
489489 Examples
490490 --------
@@ -527,7 +527,38 @@ def is_valid(cls, url: str, is_explicit: Optional[bool] = None) -> bool:
527527 False
528528
529529 You could create a GitHub matcher that consider github.com hostnames to be
530- exclusively.
530+ exclusively git:
531+
532+ >>> GitHubMatcher = Matcher(
533+ ... # Since github.com exclusively serves git repos, make explicit
534+ ... label='gh-matcher',
535+ ... description='Matches github.com https URLs, exact VCS match',
536+ ... pattern=re.compile(
537+ ... rf'''
538+ ... ^(?P<scheme>ssh)?
539+ ... ((?P<user>\w+)@)?
540+ ... (?P<hostname>(github.com)+):
541+ ... (?P<path>(\w[^:]+))
542+ ... {RE_SUFFIX}?
543+ ... ''',
544+ ... re.VERBOSE,
545+ ... ),
546+ ... is_explicit=True,
547+ ... pattern_defaults={
548+ ... 'hostname': 'github.com'
549+ ... }
550+ ... )
551+
552+ >>> GitURL.matchers.register(GitHubMatcher)
553+
554+ >>> GitURL.is_valid(
555+ ... url='git@github.com:vcs-python/libvcs.git', is_explicit=True
556+ ... )
557+ True
558+
559+ This is just us cleaning up:
560+
561+ >>> GitURL.matchers.unregister('gh-matcher')
531562 """
532563 return super ().is_valid (url = url , is_explicit = is_explicit )
533564
@@ -538,12 +569,12 @@ def to_url(self) -> str:
538569 --------
539570
540571 SSH style URL:
541- >>> git_url = GitURL(url='git@github.com:vcs-python/libvcs.git ')
572+ >>> git_url = GitURL(url='git@github.com:vcs-python/libvcs')
542573
543574 >>> git_url.path = 'vcs-python/vcspull'
544575
545576 >>> git_url.to_url()
546- 'git@github.com:vcs-python/vcspull.git '
577+ 'git@github.com:vcs-python/vcspull'
547578
548579 HTTPs URL:
549580
0 commit comments