Package: ghrepo
GitHub|PyPI|Issues|Changelogghrepoextracts a GitHub repository’s owner & name from various GitHub URL
formats (or just from a string of the formOWNER/REPONAMEorREPONAME),
and the resulting object provides properties for going in reverse to determine
the possible URLs.  Also included is a function for determining the GitHub
owner & name for a local Git repository, plus a couple of other useful Git
repository inspection functions.Installationghreporequires Python 3.7 or higher.  Just usepipfor Python 3 (You have pip, right?) to install it:python3 -m pip install ghrepoAPIGHRepoclassGHRepo(typing.NamedTuple):owner:strname:strA pair of a GitHub repository’s owner and base name.  Stringifying aGHRepoinstance produces a repository “fullname” of the form{owner}/{name}.propertyapi_url:strThe base URL for accessing the repository via the GitHub REST API; this is a
string of the formhttps://api.github.com/repos/{owner}/{name}.propertyclone_url:strThe URL for cloning the repository over HTTPSpropertygit_url:strThe URL for cloning the repository via the native Git protocolpropertyhtml_url:strThe URL for the repository’s web interfacepropertyssh_url:strThe URL for cloning the repository over SSHclassmethodparse_url(url:str)->GHRepoParse a GitHub repository URL.  The following URL formats are recognized:[https://[<username>[:<password>]@]][www.]github.com/<owner>/<name>[.git][/][https://]api.github.com/repos/<owner>/<name>git://github.com/<owner>/<name>[.git][ssh://]git@github.com:<owner>/<name>[.git]All other formats produce aValueError.classmethodparse(spec:str,default_owner:Optional[Union[str,Callable[[],str]]]=None,)->GHRepoParse a GitHub repository specifier.  This can be either a URL (as accepted byparse_url()) or a string in the form{owner}/{name}.  Ifdefault_owneris specified (as either a string or a zero-argument callable
that returns a string), strings that are just a repository name are also
accepted, and the resultingGHRepoinstances will have theirownerset
to the given value.Functions & ConstantsNote: All of the functions require Git to be installed in order to work.  I
am not certain of the minimal viable Git version, but the functions should work
with any Git as least as far back as version 1.7.get_local_repo(dirpath:Optional[AnyPath]=None,remote:str="origin")->GHRepoDetermine the GitHub repository for the Git repository located at or containing
the directorydirpath(default: the current directory) by parsing the URL
for the specified remote.  parsing the URL for the specified remote.  RaisesNoSuchRemoteErrorif the given remote does not exist.  Raisessubprocess.CalledProcessErrorif a different Git error occurs, such as the
given path not being in a Git repository.get_branch_upstream(branch:str,dirpath:Optional[AnyPath]=None)->GHRepo(New in version 0.5.0)Determine the GitHub repository for the upstream
remote of the given branch in the Git repository located at or containing the
directorydirpath(default: the current directory).RaisesNoUpstreamErrorif the given branch does not have an upstream remote
configured (This includes the situation in which the branch does not exist).
Raisessubprocess.CalledProcessErrorif a different Git error occurs, such
as the given path not being in a Git repository.get_current_branch(dirpath:Optional[AnyPath]=None)->strGet the current branch for the Git repository located at or containing the
directorydirpath(default: the current directory).  RaisesDetachedHeadErrorif the repository is in a detachedHEADstate.
Raisessubprocess.CalledProcessErrorif a different Git error occurs, such
as the given path not being in a Git repository.is_git_repo(dirpath:Optional[AnyPath]=None)->boolTests whether the given directory (default: the current directory) is either a
Git repository or contained in oneGH_USER_RGX:strA regular expression string (unanchored) for a valid GitHub username or
organization name.GH_REPO_RGX:strA regular expression string (unanchored) for a valid GitHub repository name
(without “.git” extension).ExceptionsclassDetachedHeadError(Exception)(New in version 0.6.0)Raised byget_current_branch()if the Git
repository is in a detachedHEADstateclassNoSuchRemoteError(Exception)(New in version 0.6.0)Raised byget_local_repo()when the given remote
does not exist in the GitHub repository.  The queried remote is available as
theremoteattribute.classNoUpstreamError(Exception)(New in version 0.6.0)Raised byget_branch_upstream()if the given
branch does not have a remote configured.  The queried branch is available as
thebranchattribute.Commandghrepoalso provides a command of the same name for getting the GitHub
repository associated with a local Git repository:ghrepo [<options>] [<dirpath>]By default, theghrepocommand just outputs the repository “fullname” (a
string of the form{owner}/{name}).  If the-Jor--jsonoption is
supplied, a JSON object is instead output, containing fields for the repository
owner, name, fullname, and individual URLs, like so:{"owner":"jwodder","name":"ghrepo","fullname":"jwodder/ghrepo","api_url":"https://api.github.com/repos/jwodder/ghrepo","clone_url":"https://github.com/jwodder/ghrepo.git","git_url":"git://github.com/jwodder/ghrepo.git","html_url":"https://github.com/jwodder/ghrepo","ssh_url":"git@github.com:jwodder/ghrepo.git"}Options-J,--jsonOutput JSON-rREMOTE,--remoteREMOTEParse the GitHub URL from the given remote
[default: origin]