This commit is contained in:
envolution 2024-11-19 23:53:04 -05:00
parent 10fe17e712
commit d3a60cc29a

View file

@ -21,17 +21,16 @@ GITHUB_GRAPHQL_URL = 'https://api.%s/graphql'
async def get_http_client(): async def get_http_client():
"""Initialize and return the HTTP client.""" """Initialize and return the HTTP client."""
global _http_client global _http_client
if _http_client is None: if _http_client is not None:
if asyncio.iscoroutine(session): return _http_client
# Properly await the session coroutine
client = await session # Get the client instance, awaiting if necessary
# Ensure the client supports async context management client = await session if asyncio.iscoroutine(session) else session
if hasattr(client, '__aenter__'):
_http_client = client if not hasattr(client, '__aenter__'):
else: raise RuntimeError("HTTP client must support async context management")
raise RuntimeError("HTTP client must support async context management")
else: _http_client = client
_http_client = session
return _http_client return _http_client
async def execute_github_query(host: str, owner: str, reponame: str, token: str) -> dict: async def execute_github_query(host: str, owner: str, reponame: str, token: str) -> dict:
@ -49,7 +48,9 @@ async def execute_github_query(host: str, owner: str, reponame: str, token: str)
query_vars = QUERY_GITHUB.replace("$owner", owner).replace("$name", reponame) query_vars = QUERY_GITHUB.replace("$owner", owner).replace("$name", reponame)
try: try:
async with client.post( # Ensure we have a properly initialized client
http_client = await get_http_client()
async with http_client.post(
GITHUB_GRAPHQL_URL % host, GITHUB_GRAPHQL_URL % host,
headers=headers, headers=headers,
json={'query': query_vars} json={'query': query_vars}