repomatic.github.urls module

Read a GitHub repository out of the forms that name it.

A repository reaches this package in several spellings: the owner/name slug of GITHUB_REPOSITORY, an HTTPS remote, an SSH remote, and a project_urls entry that points into the repository rather than at it. This module is the one reader of all of them, so every consumer derives the same (owner, name) pair from the same input.

A leaf module with no project-internal imports, so any module can import it without the risk of an import cycle.

repomatic.github.urls.GITHUB_REPO_RE = re.compile('(?:^|[/@])(?:www\\.)?github\\.com[:/]+(?P<owner>[^/\\s:?#]+)/(?P<name>[^/\\s?#]+)')

A repository on github.com, in a URL or in a remote.

The host must start the string or follow a / (a URL scheme) or an @ (an SSH user), so a host that only ends in github.com does not match, and neither does api.github.com, whose first path segment is not an owner. After the host comes a / in a URL, or a : in an SSH remote such as git@github.com:owner/name.git. The match stops after the name, so a deep link like https://github.com/owner/name/issues/1 reads as its repository.

repomatic.github.urls.parse_github_repo(url)[source]

Read the (owner, name) pair of the GitHub repository url points at.

Accepts an HTTPS URL, an SSH remote (git@github.com:owner/name.git and ssh://git@github.com/owner/name), and a deep link into the repository (https://github.com/owner/name/blob/main/readme.md). A trailing .git, slash, query or fragment is dropped.

Parameters:

url (str) – A URL or a git remote.

Return type:

tuple[str, str] | None

Returns:

The (owner, name) pair, or None when url names no repository on github.com: another host, or a URL with an owner and no name.

repomatic.github.urls.split_slug(slug)[source]

Split an owner/name slug into its two halves.

Parameters:

slug (str) – A repository slug, like the value of GITHUB_REPOSITORY.

Return type:

tuple[str, str]

Returns:

The (owner, name) pair. A slug with no / is all name, with an empty owner.

repomatic.github.urls.repo_name(slug)[source]

The name half of an owner/name slug.

It is also the package name an owner/name upstream implies: the inline package==X.Y.Z pins of a workflow name the package by its repository.

Parameters:

slug (str) – A repository slug.

Return type:

str

Returns:

The repository name. A slug with no / is returned whole.