diff options
| author | 2024-02-12 20:58:19 +0000 | |
|---|---|---|
| committer | 2024-02-12 21:18:31 +0000 | |
| commit | 5e1ca0d61f2a0cab34af50ddce6fc8e4370336fd (patch) | |
| tree | 665bf89f6cdfa9748c5316c4c1ba43014d5969d1 /arthur/apis/github | |
| parent | Add grafana and github secrets to config class (diff) | |
Add API wrappers for github and grafana APIs
Diffstat (limited to 'arthur/apis/github')
| -rw-r--r-- | arthur/apis/github/__init__.py | 6 | ||||
| -rw-r--r-- | arthur/apis/github/teams.py | 22 |
2 files changed, 28 insertions, 0 deletions
diff --git a/arthur/apis/github/__init__.py b/arthur/apis/github/__init__.py new file mode 100644 index 0000000..77988a1 --- /dev/null +++ b/arthur/apis/github/__init__.py @@ -0,0 +1,6 @@ +from .teams import GithubTeamNotFoundError, list_team_members + +__all__ = ( + "GithubTeamNotFoundError", + "list_team_members", +) diff --git a/arthur/apis/github/teams.py b/arthur/apis/github/teams.py new file mode 100644 index 0000000..141892d --- /dev/null +++ b/arthur/apis/github/teams.py @@ -0,0 +1,22 @@ +import aiohttp + +from arthur.config import CONFIG + +HEADERS = { + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + "Authorization": f"Bearer {CONFIG.github_token.get_secret_value()}", +} +BASE_URL = "https://api.github.com" + + +class GithubTeamNotFoundError(aiohttp.ClientResponseError): + """Raised when a github team could not be found.""" + + +async def list_team_members(team_slug: str, session: aiohttp.ClientSession) -> list[dict[str, str]]: + """List all Github teams.""" + endpoint = BASE_URL + f"/orgs/{CONFIG.github_org}/teams/{team_slug}/members" + async with session.get(endpoint, headers=HEADERS) as response: + response.raise_for_status() + return await response.json() |