44from arthur .config import CONFIG
55
66
7- async def add_staff_member (username : str ) -> None :
8- """Add a user to the default GitHub team."""
7+ async def add_member_to_team (username : str , github_team_slug : str ) -> None :
8+ """Add a user to a GitHub team."""
99 async with aiohttp .ClientSession () as session :
10- endpoint = f"https://api.github.com/orgs/{ CONFIG .github_org } /teams/{ CONFIG . github_team } /memberships/{ username } "
10+ endpoint = f"https://api.github.com/orgs/{ CONFIG .github_org } /teams/{ github_team_slug } /memberships/{ username } "
1111 async with session .put (endpoint , headers = HEADERS ) as response :
1212 try :
1313 response .raise_for_status ()
@@ -25,3 +25,22 @@ async def add_staff_member(username: str) -> None:
2525
2626 msg = f"Unexpected error: { e .message } "
2727 raise GitHubError (msg )
28+
29+
30+ async def remove_member_from_team (username : str , github_team_slug : str ) -> None :
31+ """Remove a user from a GitHub team."""
32+ async with aiohttp .ClientSession () as session :
33+ endpoint = f"https://api.github.com/orgs/{ CONFIG .github_org } /teams/{ github_team_slug } /memberships/{ username } "
34+ async with session .delete (endpoint , headers = HEADERS ) as response :
35+ try :
36+ response .raise_for_status ()
37+ except aiohttp .ClientResponseError as e :
38+ if e .status == HTTP_404 :
39+ msg = f"Team or user not found: { e .message } "
40+ raise GitHubError (msg )
41+ if e .status == HTTP_403 :
42+ msg = f"Forbidden: { e .message } "
43+ raise GitHubError (msg )
44+
45+ msg = f"Unexpected error: { e .message } "
46+ raise GitHubError (msg )
0 commit comments