swh.core.github.utils module#

swh.core.github.utils.get_canonical_github_origin_url(url: str, credentials: Optional[List[Dict[str, str]]] = None) Optional[str][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.)

exception swh.core.github.utils.RateLimited(response)[source]#

Bases: Exception

exception swh.core.github.utils.MissingRateLimitReset[source]#

Bases: Exception

class swh.core.github.utils.GitHubSession(user_agent: str, credentials: Optional[List[Dict[str, str]]] = 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.

credentials: Optional[List[Dict[str, str]]] = None#
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_canonical_url(url: str) Optional[str][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.

Returns

The canonical url if any, None otherwise.