|
5 | 5 | """
|
6 | 6 |
|
7 | 7 | import os
|
| 8 | +import sys |
8 | 9 | import asyncio
|
9 | 10 | import aiohttp
|
10 | 11 | from rich import print
|
@@ -225,12 +226,33 @@ def clear_cache() -> None:
|
225 | 226 | print(f"[red]Error clearing cache: {str(e)}[/red]")
|
226 | 227 |
|
227 | 228 |
|
| 229 | +async def check_user_admin(session: aiohttp.ClientSession, org: str, username: str) -> bool: |
| 230 | + url = f"https://api.github.com/orgs/{org}/memberships/{username}" |
| 231 | + async with session.get(url, headers=headers) as response: |
| 232 | + if response.status == 404: |
| 233 | + return False |
| 234 | + elif response.status != 200: |
| 235 | + print(f"[red]Error fetching membership for {username} in {org}: {response.status}[/red]") |
| 236 | + return False |
| 237 | + return (await response.json())['role'] == 'admin' |
| 238 | + |
| 239 | + |
228 | 240 | async def main(orgs, debug: bool, timelimit_days: int):
|
229 | 241 | """Main execution function."""
|
230 | 242 | # Show cache status
|
231 | 243 | print(f"[blue]Cache directory: {CACHE_DIR} (size: {get_cache_size()})[/blue]")
|
232 | 244 | print(f"[blue]Cache contains {len(cache)} items[/blue]")
|
233 | 245 |
|
| 246 | + # check who the current user is |
| 247 | + async with aiohttp.ClientSession() as session: |
| 248 | + async with session.get("https://api.github.com/user", headers=headers) as response: |
| 249 | + if response.status == 200: |
| 250 | + user_data = await response.json() |
| 251 | + current_user = user_data["login"] |
| 252 | + print(f"[blue]Current user: {current_user}[/blue]") |
| 253 | + else: |
| 254 | + sys.exit(f"[red]Error fetching user data: {response.status}[/red]") |
| 255 | + |
234 | 256 | async with aiohttp.ClientSession() as session:
|
235 | 257 | # Check rate limit
|
236 | 258 | async with session.get(
|
@@ -284,6 +306,12 @@ async def main(orgs, debug: bool, timelimit_days: int):
|
284 | 306 | )
|
285 | 307 | for org in orgs:
|
286 | 308 | print(f"[bold]{org}[/bold]")
|
| 309 | + is_admin = await check_user_admin(session, org, current_user) |
| 310 | + if is_admin: |
| 311 | + if debug: |
| 312 | + print(f" [green]{current_user} is an admin in {org}[/green]") |
| 313 | + else: |
| 314 | + print(f" [yellow]{current_user} is not an admin in {org}, list of users will be incomplete (limited to public membership)[/yellow]") |
287 | 315 | n_active = 0
|
288 | 316 | n_inactive = 0
|
289 | 317 | for username, last_activity, user_orgs in sorted(
|
|
0 commit comments