Skip to content

Commit

Permalink
Merge pull request #207 from lsst-sqre/tickets/DM-39710-remove-app-fa…
Browse files Browse the repository at this point in the history
…ctory

DM-398710: Remove GitHubAppClientFactory.create_app_client
  • Loading branch information
jonathansick authored Sep 14, 2023
2 parents 5817676 + 9dcc1fc commit 9134a10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Backwards-incompatible changes

- Remove the `GitHubAppClientFactory.create_app_client` method, which does not work with the Gidgethub API. Instead, the documentation shows how to create a JWT with the `GitHubAppClientFactory` and pass it with requests.
15 changes: 12 additions & 3 deletions docs/user-guide/github-apps/create-a-github-client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,29 @@ Authenticating as the app
Your app can authenticate to GitHub in two modes: as the *app itself*, or as an *installation* of the app.
Authenticating as the GitHub App enables your app to access information about the app itself, such as its installations.

To do this, get the app's JWT and use it with an GitHub client requests:

.. code-block:: python
client = github_client_factory.create_anonymous_client()
jwt = github_client_factory.get_app_jwt()
Example of using the JWT to get the app's installations:

.. code-block:: python
app_client = github_client_factory.create_app_client()
data = await client.getitem("/app/installations", jwt=jwt)
Authenticating as the app installation
======================================

To authenticate as an installation of the app, you need to know the installation ID.
Dependening on the scenario, there are multiple ways of getting the installation ID.
Depending on the scenario, there are multiple ways of getting the installation ID.

In a webhook handler
--------------------

If your app recieves a webhook from GitHub, the installation ID will be included in the payload (as the ``installation.id`` field, see the `~safir.github.webhooks.GitHubAppInstallationModel`).
If your app receives a webhook from GitHub, the installation ID will be included in the payload (as the ``installation.id`` field, see the `~safir.github.webhooks.GitHubAppInstallationModel`).

.. code-block:: python
Expand Down
10 changes: 0 additions & 10 deletions src/safir/github/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ def create_anonymous_client(self) -> GitHubAPI:
"""
return self._create_client()

def create_app_client(self) -> GitHubAPI:
"""Create a client authenticated as the GitHub App.
Returns
-------
gidgethub.httpx.GitHubAPI
The app client.
"""
return self._create_client(oauth_token=self.get_app_jwt())

async def create_installation_client(
self, installation_id: str
) -> GitHubAPI:
Expand Down

0 comments on commit 9134a10

Please sign in to comment.