Skip to content

Commit 1cd07e1

Browse files
Clarify new/existing GitHub App installation documentation (#99)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cbfd8bc commit 1cd07e1

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
107107
> - Use `"async"` with `AsyncWebhookView`
108108
> - Use `"sync"` with `SyncWebhookView`
109109
110-
5. Setup your GitHub App, either by registering a new one or importing an existing one, and configure django-github-app using your GitHub App's information.
110+
5. Setup your GitHub App and configure django-github-app using your GitHub App's information.
111111
112112
You will need the following information from your GitHub App:
113113
@@ -136,7 +136,22 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
136136
>
137137
> django-github-app will automatically detect if `GITHUB_APP["PRIVATE_KEY"]` is a path and load the file contents. For more information, see the [`PRIVATE_KEY`](#private_key) section in the [Configuration](#configuration) documentation below.
138138
139-
### Create a New GitHub App
139+
### GitHub App Setup
140+
141+
After completing the [Installation](#installation) steps above, you will need to set up your GitHub App using the information from Step 5 above.
142+
143+
Choose the appropriate setup method based on your situation:
144+
145+
- **[Create a New GitHub App](#create-a-new-github-app)**: If you're setting up a fresh GitHub App
146+
- **[Use an Existing GitHub App](#use-an-existing-github-app-and-installation)**: If your GitHub App is already installed on organizations/repositories
147+
148+
> [!IMPORTANT]
149+
> django-github-app needs to create `Installation` and `Repository` models in your database to track where your GitHub App is installed. How this happens depends on your setup method:
150+
>
151+
> - **New GitHub App**: When you install the app for the first time, GitHub sends an `installation.created` webhook event. django-github-app automatically creates the necessary models when it receives this event.
152+
> - **Existing GitHub App**: If the app is already installed, no `installation.created` webhook event is sent. You must use the `github import-app` management command to manually create the models.
153+
154+
#### Create a New GitHub App
140155
141156
1. Register a new GitHub App, following [these instructions](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app) from the GitHub Docs. For a more detailed tutorial, there is also [this page](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-github-app-that-responds-to-webhook-events) -- in particular the section on [Setup](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-github-app-that-responds-to-webhook-events#setup).
142157
@@ -169,9 +184,11 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
169184
- Select the account to install it on
170185
- Choose which repositories to give it access to
171186
172-
When you install the app, django-github-app will automatically create the necessary `Installation` and `Repository` models when it receives the `installation.created` webhook event.
187+
When you install the app **for the first time**, django-github-app will automatically create the necessary `Installation` and `Repository` models when it receives the `installation.created` webhook event.
188+
189+
#### Use an Existing GitHub App and Installation
173190
174-
### Use an Existing GitHub App and Installation
191+
If your GitHub App is already installed on organizations/repositories, the `installation.created` webhook event won't be sent when you connect django-github-app to your existing app. In this case, you need to manually import the installation data.
175192
176193
1. Collect your existing app and installation's information.
177194
@@ -199,7 +216,7 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
199216
}
200217
```
201218
202-
3. Import your existing GitHub App by using the `github import-app` management command.
219+
3. Import your existing GitHub App by using the `github import-app` management command to create the necessary `Installation` and `Repository` models.
203220
204221
```bash
205222
python manage.py github import-app --type user --name <username> --installation-id 123456
@@ -209,6 +226,9 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
209226
uv run manage.py github import-app --type user --name <username> --installation-id 123456
210227
```
211228
229+
> [!NOTE]
230+
> After importing, django-github-app will handle future webhook events normally, including repository additions/removals via the `installation_repositories` event.
231+
212232
## Getting Started
213233
214234
### Webhook Events

0 commit comments

Comments
 (0)