swh.core.github.utils module#
- swh.core.github.utils.get_canonical_github_origin_url(url: str, credentials: List[Dict[str, str]] | None = None) str | None [source]#
Retrieve canonical github url out of an url if any or None otherwise.
This triggers an http request to the github api url to determine the canonical repository url (if no credentials is provided, the http request is anonymous. Either way that request can be rate-limited by github.)
- class swh.core.github.utils.GitHubSession(user_agent: str, credentials: List[Dict[str, str]] | None = None)[source]#
Bases:
object
Manages a
requests.Session
with (optionally) multiple credentials, and cycles through them when reaching rate-limits.Initialize a requests session with the proper headers for requests to GitHub.
- set_next_session_token() None [source]#
Update the current authentication token with the next one in line.
- request(url) Response [source]#
Repeatedly requests the given URL, cycling through credentials and sleeping if necessary; until either a successful response or
MissingRateLimitReset
- get_repository_metadata(repo_url: str) Dict[str, Any] | None [source]#
Retrieve metadata of a repository from the github API.
- Parameters:
repo_url – URL of a github repository
- Returns:
A dictionary holding the metadata of the repository or None if this is not a valid github repository.
- Throws:
requests.HTTPError: if the request to the github API failed.
- get_canonical_url(repo_url: str) str | None [source]#
Retrieve canonical github url out of a github url.
This triggers an http request to the github api url to determine the canonical repository url.
- Parameters:
repo_url – URL of a github repository
- Returns:
The canonical github url, the input url if it is not a github one, None otherwise.