"""Common functionality and interface for interacting with Git remote VCS"""from__future__importannotationsimportloggingimportwarningsfromabcimportABCMeta,abstractmethodfromfunctoolsimportlru_cachefromtypingimportTYPE_CHECKINGfromsemantic_release.helpersimportparse_git_urlifTYPE_CHECKING:fromtypingimportAny,Callable# Globalslogger=logging.getLogger(__name__)
[docs]classHvcsBase(metaclass=ABCMeta):""" Interface for subclasses interacting with a remote vcs environment Methods generally have a base implementation are implemented here but likely just provide a not-supported message but return gracefully This class cannot be instantated directly but must be inherited from and implement the designated abstract methods. """def__init__(self,remote_url:str,*args:Any,**kwargs:Any)->None:self._remote_url=remote_urlself._name:str|None=Noneself._owner:str|None=Nonedef_not_supported(self:HvcsBase,method_name:str)->None:warnings.warn(f"{method_name} is not supported by {type(self).__qualname__}",stacklevel=2,)@lru_cache(maxsize=1)def_get_repository_owner_and_name(self)->tuple[str,str]:""" Parse the repository's remote url to identify the repository owner and name """parsed_git_url=parse_git_url(self._remote_url)returnparsed_git_url.namespace,parsed_git_url.repo_name@propertydefrepo_name(self)->str:ifself._nameisNone:_,name=self._get_repository_owner_and_name()self._name=namereturnself._name@propertydefowner(self)->str:ifself._ownerisNone:_owner,_=self._get_repository_owner_and_name()self._owner=_ownerreturnself._owner
[docs]@abstractmethoddefremote_url(self,use_token:bool)->str:""" Return the remote URL for the repository, including the token for authentication if requested by setting the `use_token` parameter to True, """self._not_supported(self.remote_url.__name__)return""
[docs]@abstractmethoddefget_changelog_context_filters(self)->tuple[Callable[...,Any],...]:""" Return a list of functions that can be used as filters in a Jinja2 template ex. filters to convert text to URLs for issues and commits """self._not_supported(self.get_changelog_context_filters.__name__)return()