@@ -484,7 +484,7 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
484
484
485
485
@classmethod
486
486
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.
488
488
489
489
Examples
490
490
--------
@@ -527,7 +527,38 @@ def is_valid(cls, url: str, is_explicit: Optional[bool] = None) -> bool:
527
527
False
528
528
529
529
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')
531
562
"""
532
563
return super ().is_valid (url = url , is_explicit = is_explicit )
533
564
@@ -538,12 +569,12 @@ def to_url(self) -> str:
538
569
--------
539
570
540
571
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')
542
573
543
574
>>> git_url.path = 'vcs-python/vcspull'
544
575
545
576
>>> git_url.to_url()
546
- 'git@github.com:vcs-python/vcspull.git '
577
+ 'git@github.com:vcs-python/vcspull'
547
578
548
579
HTTPs URL:
549
580
0 commit comments