MCPcopy Create free account
hub / github.com/pollinations/pollinations / GitHubGraphQL

Class GitHubGraphQL

apps/polly/src/services/github_graphql.py:17–2136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class GitHubGraphQL:
18 def __init__(self):
19 self._session: aiohttp.ClientSession | None = None
20 self._connector: aiohttp.TCPConnector | None = None
21 self._cache = TTLCache(maxsize=512, ttl=CACHE_TTL)
22
23 @property
24 def owner(self) -> str:
25 return config.github_repo.split("/")[0]
26
27 @property
28 def repo(self) -> str:
29 return config.github_repo.split("/")[1]
30
31 async def get_session(self) -> aiohttp.ClientSession:
32 if self._session is None or self._session.closed:
33 self._connector = aiohttp.TCPConnector(
34 limit=50,
35 limit_per_host=30,
36 keepalive_timeout=60,
37 enable_cleanup_closed=True,
38 ttl_dns_cache=300,
39 use_dns_cache=True,
40 )
41 self._session = aiohttp.ClientSession(
42 connector=self._connector,
43 timeout=aiohttp.ClientTimeout(total=30, connect=10),
44 )
45 return self._session
46
47 async def close(self):
48 if self._session and not self._session.closed:
49 await self._session.close()
50 self._session = None
51 if self._connector:
52 await self._connector.close()
53 self._connector = None
54
55 async def _get_token(self, for_projects: bool = False) -> str | None:
56 if for_projects:
57 if github_auth.github_app_auth:
58 token = await github_auth.github_app_auth.get_token()
59 if token:
60 logger.debug("Using GitHub App token for project operation")
61 return token
62 if config.github_project_pat:
63 logger.debug("Falling back to GITHUB_PROJECT_PAT for project operation")
64 return config.github_project_pat
65 else:
66 logger.warning("ProjectV2 operation: No GitHub App or GITHUB_PROJECT_PAT configured")
67 return None
68
69 if github_auth.github_app_auth:
70 token = await github_auth.github_app_auth.get_token()
71 if token:
72 return token
73 return config.github_token if config.github_token else None
74

Callers 1

github_graphql.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected