Add support for get_app() with App authentication (#2549)

Moves `Github.get_app()` called without `slug` parameter into `GithubIntegration`, because it needs an `AppAuth`,
and we collect all such endpoints there. Calling `Github.get_app()` without `slug` parameter is now deprecated.

Replaces `datetime.utcnow()` with `datetime.now(timezone.utc)`, as it is deprecated in Python 3.12.
This commit is contained in:
chantra
2023-06-16 08:09:16 +02:00
committed by GitHub
parent 6a21761e0f
commit 6d4b6d1419
13 changed files with 137 additions and 53 deletions
+18 -1
View File
@@ -4,6 +4,7 @@ import deprecated
from github import Consts
from github.Auth import AppAuth
from github.GithubApp import GithubApp
from github.GithubException import GithubException
from github.Installation import Installation
from github.InstallationAuthorization import InstallationAuthorization
@@ -71,7 +72,10 @@ class GithubIntegration:
jwt_algorithm=jwt_algorithm,
)
assert auth is not None
assert isinstance(
auth, AppAuth
), f"GithubIntegration requires github.Auth.AppAuth authentication, not {type(auth)}"
self.auth = auth
self.__requester = Requester(
@@ -213,3 +217,16 @@ class GithubIntegration:
:rtype: :class:`github.Installation.Installation`
"""
return self._get_installed_app(url=f"/app/installations/{installation_id}")
def get_app(self):
"""
:calls: `GET /app <https://docs.github.com/en/rest/reference/apps#get-the-authenticated-app>`_
:rtype: :class:`github.GithubApp.GithubApp`
"""
headers, data = self.__requester.requestJsonAndCheck(
"GET", "/app", headers=self._get_headers()
)
return GithubApp(
requester=self.__requester, headers=headers, attributes=data, completed=True
)