From a6ac8a024cd0fc7ac5e17d7bb1b9ec4692e322d9 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Wed, 16 Jul 2025 10:00:10 +0100 Subject: Add new endpoints for removing organisation members --- arthur/apis/github/orgs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 arthur/apis/github/orgs.py (limited to 'arthur/apis/github/orgs.py') diff --git a/arthur/apis/github/orgs.py b/arthur/apis/github/orgs.py new file mode 100644 index 0000000..55039c8 --- /dev/null +++ b/arthur/apis/github/orgs.py @@ -0,0 +1,25 @@ +import aiohttp + +from arthur.apis.github import GitHubError, HEADERS, HTTP_403, HTTP_404 +from arthur.config import CONFIG + + +async def remove_org_member(username: str) -> None: + """Remove a user from the GitHub organisation.""" + async with aiohttp.ClientSession() as session: + endpoint = f"https://api.github.com/orgs/{CONFIG.github_org}/members/{username}" + + async with session.delete(endpoint, headers=HEADERS) as resp: + try: + resp.raise_for_status() + return await resp.json() + except aiohttp.ClientResponseError as e: + if e.status == HTTP_404: + msg = f"Team or user not found in the org: {e.message}" + raise GitHubError(msg) + if e.status == HTTP_403: + msg = f"Forbidden: {e.message}" + raise GitHubError(msg) + + msg = f"Unexpected error: {e.message}" + raise GitHubError(msg) -- cgit v1.2.3