Skip to content

PyDrocsid.github_api

get_repo_description async

get_repo_description(owner: str, name: str) -> str | None

Get the description of a github repository.

Source code in PyDrocsid/github_api.py
36
37
38
39
40
41
42
43
44
45
async def get_repo_description(owner: str, name: str) -> str | None:
    """Get the description of a github repository."""

    result = await graphql(
        "query($owner:String!,$name:String!){repository(owner:$owner,name:$name){description}}", owner=owner, name=name
    )
    if not result:
        return None

    return cast(str | None, result["repository"]["description"])

get_users async

get_users(ids: list[str]) -> dict[str, GitHubUser] | None

Get a list of github users by their ids.

Source code in PyDrocsid/github_api.py
26
27
28
29
30
31
32
33
async def get_users(ids: list[str]) -> dict[str, GitHubUser] | None:
    """Get a list of github users by their ids."""

    result = await graphql("query($ids:[ID!]!){nodes(ids:$ids){...on User{id,login,url}}}", ids=ids)
    if not result:
        return None

    return {user["id"]: GitHubUser(user["id"], user["login"], user["url"]) for user in result["nodes"]}

graphql async

graphql(query: str, **kwargs: Any) -> dict[Any, Any] | None

Send a query to the github graphql api and return the result.

Source code in PyDrocsid/github_api.py
14
15
16
17
18
19
20
21
22
23
async def graphql(query: str, **kwargs: Any) -> dict[Any, Any] | None:
    """Send a query to the github graphql api and return the result."""

    headers = {"Authorization": f"bearer {GITHUB_TOKEN}"} if GITHUB_TOKEN else {}
    async with ClientSession() as session:
        async with session.post(API_URL, headers=headers, json={"query": query, "variables": kwargs}) as response:
            if response.status != 200:
                return None

            return cast(dict[Any, Any], (await response.json())["data"])