aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/apis/github/orgs.py
diff options
context:
space:
mode:
Diffstat (limited to 'arthur/apis/github/orgs.py')
-rw-r--r--arthur/apis/github/orgs.py25
1 files changed, 25 insertions, 0 deletions
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)