Skip to content

Commit 06a81fe

Browse files
adjust installation instructions in README
1 parent 02b6800 commit 06a81fe

File tree

1 file changed

+99
-49
lines changed

1 file changed

+99
-49
lines changed

README.md

Lines changed: 99 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,7 @@ The library is async-only at the moment (following gidgethub), with sync support
2020

2121
## Installation
2222

23-
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).
24-
25-
Make note of the following information while setting up your new GitHub App:
26-
27-
- App ID
28-
- Client ID
29-
- Name
30-
- Private Key
31-
- Webhook Secret
32-
- Webhook URL
33-
34-
For the Private Key, you will be able to use either the file contents or the file itself to authenticate with GitHub. See step 5 below for more information about private key configuration.
35-
36-
For the Webhook URL, the endpoint is up to you. See step 4 below for how the endpoint is configured. Using these installation instructions as an example, you would enter `<your project's base url>/gh/` as the Webhook URL.
37-
38-
> [!NOTE]
39-
> To use an existing GitHub App with django-github-app, see [Import an Existing GitHub App](#importing-an-existing-github-app).
40-
41-
2. Install the package from PyPI:
23+
1. Install the package from PyPI:
4224

4325
```bash
4426
python -m pip install django-github-app
@@ -49,15 +31,15 @@ The library is async-only at the moment (following gidgethub), with sync support
4931
uv sync
5032
```
5133

52-
3. Add the app to your Django project's `INSTALLED_APPS`:
34+
2. Add the app to your Django project's `INSTALLED_APPS`:
5335
5436
```python
5537
INSTALLED_APPS = [
5638
"django_github_app",
5739
]
5840
```
5941
60-
4. Run the `migrate` management command to add django-github-app's models to your database:
42+
3. Run the `migrate` management command to add django-github-app's models to your database:
6143

6244
```bash
6345
python manage.py migrate
@@ -81,35 +63,105 @@ The library is async-only at the moment (following gidgethub), with sync support
8163
8264
For the moment, django-github-app only supports an async webhook view, as this library is a wrapper around [gidgethub](https://github.com/gidgethub/gidgethub) which is async only. Sync support is planned.
8365
84-
As noted above in step 1, the path here must match the Webhook URL you entered when setting up your GitHub App.
66+
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.
8567
86-
5. Add the following dictionary to your Django project's `DJANGO_SETTINGS_MODULE`, filling in the values from step 1 above. The example below uses [environs](https://github.com/sloria/environs) to load the values from an `.env` file.
68+
You will need the following information from your GitHub App:
8769
88-
```python
89-
import environs
90-
91-
env = environs.Env()
92-
env.read_env()
93-
94-
GITHUB_APP = {
95-
"APP_ID": env.int("GITHUB_APP_ID"),
96-
"CLIENT_ID": env.str("GITHUB_CLIENT_ID"),
97-
"NAME": env.str("GITHUB_NAME"),
98-
"PRIVATE_KEY": env.str("GITHUB_PRIVATE_KEY"),
99-
"WEBHOOK_SECRET": env.str("GITHUB_WEBHOOK_SECRET"),
100-
}
101-
```
70+
- App ID
71+
- Client ID
72+
- Name
73+
- Private Key (either the file object or the contents)
74+
- Webhook Secret
75+
- Webhook URL
10276
103-
> [!NOTE]
104-
> In this example, the private key's contents are set and loaded directly from the environment. If you prefer to use the file itself, you could do something like this instead:
105-
>
106-
> ```python
107-
> from pathlib import Path
108-
>
109-
> GITHUB_APP = {
110-
> "PRIVATE_KEY": env.path("GITHUB_PRIVATE_KEY_PATH"),
111-
> }
112-
> ```
77+
All examples below use [environs](https://github.com/sloria/environs) to load the values from an `.env` file. Adjust the code to your preferred way of loading Django settings.
78+
79+
> [!NOTE]
80+
> By default, examples use the private key contents loaded directly from environment. To use a key file instead:
81+
>
82+
> ```python
83+
> import environs
84+
>
85+
> env = environs.Env()
86+
> env.read_env()
87+
>
88+
> GITHUB_APP = {
89+
> "PRIVATE_KEY": env.path("GITHUB_PRIVATE_KEY_PATH"),
90+
> }
91+
> ```
92+
>
93+
> django-github-app will automatically detect if `GITHUB_APP["PRIVATE_KEY"]` is a path and load the file contents.
94+
95+
- **Option A: Create a new Github App**
96+
97+
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).
98+
99+
For the Private Key, you will be able to use either the file contents or the file itself to authenticate with GitHub, as described in the note above.
100+
101+
For the Webhook URL, use the endpoint you configured in step 4 (e.g., `<your project's base url>/gh/`).
102+
103+
2. Configure your Django settings by adding the following dictionary to your `DJANGO_SETTINGS_MODULE`, filling in the values from the previous setup.
104+
105+
```python
106+
import environs
107+
108+
env = environs.Env()
109+
env.read_env()
110+
111+
GITHUB_APP = {
112+
"APP_ID": env.int("GITHUB_APP_ID"),
113+
"CLIENT_ID": env.str("GITHUB_CLIENT_ID"),
114+
"NAME": env.str("GITHUB_NAME"),
115+
"PRIVATE_KEY": env.str("GITHUB_PRIVATE_KEY"),
116+
"WEBHOOK_SECRET": env.str("GITHUB_WEBHOOK_SECRET"),
117+
}
118+
```
119+
120+
3. Install the GitHub App on your account:
121+
122+
- Go to your GitHub App's settings
123+
- Click "Install App"
124+
- Select the account to install it on
125+
- Choose which repositories to give it access to
126+
127+
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.
128+
129+
- **Option B: Use an existing GitHub App and Installation**
130+
131+
1. Collect your existing app and installation's information:
132+
133+
- All GitHub App information and credentials listed above
134+
- Make sure the Webhook URL matches the endpoint configured in step 4
135+
- Account type where installed (`org` or `user`)
136+
- Account name (username or organization name)
137+
- Installation ID (e.g. `https://github.com/settings/installations/<ID>` for an user installation)
138+
139+
2. Configure your Django settings by adding the following dictionary to your `DJANGO_SETTINGS_MODULE`, filling in the values from your existing GitHub App.
140+
141+
```python
142+
import environs
143+
144+
env = environs.Env()
145+
env.read_env()
146+
147+
GITHUB_APP = {
148+
"APP_ID": env.int("GITHUB_APP_ID"),
149+
"CLIENT_ID": env.str("GITHUB_CLIENT_ID"),
150+
"NAME": env.str("GITHUB_NAME"),
151+
"PRIVATE_KEY": env.str("GITHUB_PRIVATE_KEY"),
152+
"WEBHOOK_SECRET": env.str("GITHUB_WEBHOOK_SECRET"),
153+
}
154+
```
155+
156+
3. Import your existing GitHub App by using the provided management command:
157+
158+
```bash
159+
python manage.py github import-app --type user --name <username> --installation-id 123456
160+
161+
# or for you thrill seekers and early adopters
162+
163+
uv run manage.py github import-app --type user --name <username> --installation-id 123456
164+
```
113165
114166
## Getting Started
115167
@@ -289,8 +341,6 @@ issues = await repo.aget_issues(params={"state": "open"})
289341
- `owner`: Repository owner from full name
290342
- `repo`: Repository name from full name
291343
292-
### Importing an Existing GitHub App
293-
294344
## Configuration
295345
296346
Configuration of django-github-app is done through a `GITHUB_APP` dictionary in your Django project's `DJANGO_SETTINGS_MODULE`.

0 commit comments

Comments
 (0)