Skip to content

request

request(token, endpoint, method=http.HttpMethod.get, dict_data=None)

Make an api request to github.

See::

- https://docs.github.com/en/rest/overview/resources-in-the-rest-api
- https://docs.github.com/en/rest/overview/endpoints-available-for-github-apps

Parameters:

Name Type Description Default
token str

A github personal access token.

required
endpoint str

A github api endpoint.

required
method HttpMethod

The http method to use. (default 'GET')

get
dict_data object | None

A payload if the method if POST or GET.

None

Returns:

Type Description
OneOf[Issue, Any]

A response from Github.

Source code in m/github/request.py
def request(
    token: str,
    endpoint: str,
    method: http.HttpMethod = http.HttpMethod.get,
    dict_data: object | None = None,
) -> OneOf[Issue, Any]:
    """Make an api request to github.

    See::

        - https://docs.github.com/en/rest/overview/resources-in-the-rest-api
        - https://docs.github.com/en/rest/overview/endpoints-available-for-github-apps

    Args:
        token: A github personal access token.
        endpoint: A github api endpoint.
        method: The http method to use. (default 'GET')
        dict_data: A payload if the method if `POST` or `GET`.

    Returns:
        A response from Github.
    """
    url = f'https://api.github.com{endpoint}'
    headers = {'authorization': f'Bearer {token}'}
    return http.fetch_json(url, headers, method, dict_data)