Skip to content

Commit

Permalink
refactor: Update get_github_installation_ids to use httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Jan 24, 2025
1 parent 19a4f1c commit 1bda9ca
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions openhands/server/routes/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1bda9ca

Please sign in to comment.