You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+99-49Lines changed: 99 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,25 +20,7 @@ The library is async-only at the moment (following gidgethub), with sync support
20
20
21
21
## Installation
22
22
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:
42
24
43
25
```bash
44
26
python -m pip install django-github-app
@@ -49,15 +31,15 @@ The library is async-only at the moment (following gidgethub), with sync support
49
31
uv sync
50
32
```
51
33
52
-
3. Add the app to your Django project's `INSTALLED_APPS`:
34
+
2. Add the app to your Django project's `INSTALLED_APPS`:
53
35
54
36
```python
55
37
INSTALLED_APPS = [
56
38
"django_github_app",
57
39
]
58
40
```
59
41
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:
61
43
62
44
```bash
63
45
python manage.py migrate
@@ -81,35 +63,105 @@ The library is async-only at the moment (following gidgethub), with sync support
81
63
82
64
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.
83
65
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.
85
67
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:
- Private Key (either the file object or the contents)
74
+
- Webhook Secret
75
+
- Webhook URL
102
76
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:
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:
> 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.
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.
0 commit comments