From 1bda9caf8992ad6d04a9cbd078b5047166f39491 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 18:35:37 +0000 Subject: [PATCH] refactor: Update get_github_installation_ids to use httpx --- openhands/server/routes/github.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/openhands/server/routes/github.py b/openhands/server/routes/github.py index 921d6df6d860..ca9dfc5f6507 100644 --- a/openhands/server/routes/github.py +++ b/openhands/server/routes/github.py @@ -90,23 +90,19 @@ async def get_github_installation_ids( ): headers = generate_github_headers(github_token) try: - response = await call_sync_from_async( - requests.get, 'https://api.github.com/user/installations', headers=headers - ) - response.raise_for_status() - except requests.exceptions.RequestException as e: + async with httpx.AsyncClient() as client: + response = await client.get('https://api.github.com/user/installations', headers=headers) + response.raise_for_status() + data = response.json() + ids = [installation['id'] for installation in data['installations']] + return JSONResponse(content=ids) + + except httpx.HTTPError as e: raise HTTPException( - status_code=response.status_code if response else 500, + status_code=e.response.status_code if hasattr(e, 'response') else 500, detail=f'Error fetching installations: {str(e)}', ) - data = response.json() - ids = [installation['id'] for installation in data['installations']] - json_response = JSONResponse(content=ids) - response.close() - - return json_response - @app.get('/search/repositories') async def search_github_repositories(