GitHub repository fetcher
This helper implements extensive fetching for GitHub repositories.
Info
All requests to the functions are automatically cached.
Fetching general information about GitHub repository
If you have a GitHub API token, you should use
github_fetch_graphql, if you
don't - github_fetch_rest.
The difference, is that GraphQL requires API key, but has much higher rate limits, while REST API is the opposite. Which makes REST API great for one-time uses and GraphQL for massive updates.
After you fetched general information about the repository, you would probably
want to fetch such things as latest commit/release/Git tag. For this you should
use result.prefetch_commit()
and/or result.prefetch_latest_version().
As every function is limited to only one request (this is to make predicting
rate limiting intuitive), github_fetch_rest
will not fetch that data but github_fetch_graphql
will (GraphQL allows us to include multiple requests into one).
Note
Those functions don't do any additional requests if data is already present in the result object. Which means, you can safely do code like this:
Don't forget to consult result.prefetch_commit()
and result.prefetch_latest_version().
Functions
github_fetch_graphql
async
github_fetch_graphql(
owner: str, repo: str, github_token: str
) -> GHRepository
Fetch a GitHub repository using GraphQL API.
GraphQL API allows us to include multiple different requests in one, which makes it superior for ratelimit-sensitive operations, but it requires a token.
github_fetch_rest
async
github_fetch_rest(
owner: str, repo: str, *, github_token: str | None
) -> GHRepository
Fetch a GitHub repository using REST API.
REST API makes GitHub token optional, but it is a lot easier to get rate limited. If GitHub token is provided, use GraphQL API instead.
Do not forget to handle redirects!
Warning
Other undocumented functions in this module are considered private and you should not use them.
Response classes
GHRepository
Bases: NupdModel
prefetch_commit
async
prefetch_latest_version
async
Prefetch latest version, if it is not yet prefetched.
First it tries to fetch the latest GitHub release, if it fails - it
fallbacks to Git tags. If there are no tags, the returned object's
latest_version stays None.
MetaInformation
Bases: NupdModel