nitpick.style.fetchers.github module
Support for gh
and github
schemes.
- class nitpick.style.fetchers.github.GitHubFetcher(session: CachedSession | None = None, protocols: tuple[str, ...] = (<Scheme.GH: 'gh'>, <Scheme.GITHUB: 'github'>), domains: tuple[str, ...] = ('github.com', ))[source]
Bases:
HttpFetcher
Fetch styles from GitHub repositories.
- normalize(url: furl) furl
Normalize a URL.
Produces a canonical URL, meant to be used to uniquely identify a style resource.
The base name has .toml appended if not already ending in that extension
Individual fetchers can further normalize the path and scheme.
- class nitpick.style.fetchers.github.GitHubURL(owner: str, repository: str, git_reference: str, path: tuple[str, ...] = (), auth_token: str | None = None, query_params: tuple[tuple[str, str], ...] | None = None)[source]
Bases:
object
Represent a GitHub URL, created from a URL or from its parts.
- property api_url: furl
API URL for this repo.
- property credentials: tuple[str, str] | tuple[()]
Credentials encoded in this URL.
A tuple of
(api_token, '')
if present, or empty tuple otherwise.
- classmethod from_furl(url: furl) GitHubURL [source]
Create an instance from a parsed URL in any accepted format.
See the code for
test_parsing_github_urls()
for more examples.
- property git_reference_or_default: str
Return the Git reference if informed, or return the default branch.
- property long_protocol_url: furl
Long protocol URL (
github
).
- property raw_content_url: furl
Raw content URL for this path.
- property short_protocol_url: furl
Short protocol URL (
gh
).
- property token: str | None
Token encoded in this URL.
If present and it starts with a
$
, it will be replaced with the value of the environment corresponding to the remaining part of the string.
- property url: furl
Default URL built from attributes.
- nitpick.style.fetchers.github.get_default_branch(api_url: str, *, token: str | None = None) str [source]
Get the default branch from the GitHub repo using the API.
For now, for URLs without an authorization token embedded, the request is not authenticated on GitHub, so it might hit a rate limit with:
requests.exceptions.HTTPError: 403 Client Error: rate limit exceeded for url
This function is using
lru_cache()
as a simple memoizer, trying to avoid this rate limit error.