Close connections after use (#2724)

This commit is contained in:
Hemslo Wang
2023-08-31 20:01:08 +02:00
committed by GitHub
parent fbf2e613a5
commit 73236e231a
7 changed files with 160 additions and 16 deletions
+17
View File
@@ -119,6 +119,23 @@ class GithubIntegration:
seconds_between_writes=seconds_between_writes,
)
def close(self) -> None:
"""
Close connections to the server. Alternatively, use the GithubIntegration object as a context manager:
.. code-block:: python
with github.GithubIntegration(...) as gi:
# do something
"""
self.__requester.close()
def __enter__(self) -> "GithubIntegration":
return self
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self.close()
def get_github_for_installation(self, installation_id, token_permissions=None):
# The installation has to authenticate as an installation, not an app
auth = self.auth.get_installation_auth(installation_id, token_permissions, self.__requester)