blob: 60255acbc39d0ed0d98adfa07d122a04fdfed994 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import aiohttp
from arthur.apis.github.common 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)
|