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: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
18
18
19
19
## [Unreleased]
20
20
21
+
### Added
22
+
23
+
- Added `SyncWebhookView`, a synchronous counterpart to `AsyncWebhookView` for Django applications running under WSGI. Works with `SyncGitHubAPI` and synchronous event handlers to provide a fully synchronous workflow for processing GitHub webhooks.
24
+
21
25
### Changed
22
26
23
27
-`AsyncGitHubAPI` and `SyncGitHubAPI` clients can now take an instance of `Installation` using the `installation` kwarg, in addition to the previous behavior of providing the `installation_id`. One or the other must be used for authenticated requests, not both.
Copy file name to clipboardExpand all lines: README.md
+56-7Lines changed: 56 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ A Django toolkit providing the batteries needed to build GitHub Apps - from webh
11
11
12
12
Built on [gidgethub](https://github.com/gidgethub/gidgethub) and [httpx](https://github.com/encode/httpx), django-github-app handles the boilerplate of GitHub App development. Features include webhook event routing and storage, API client with automatic authentication, and models for managing GitHub App installations, repositories, and webhook event history.
13
13
14
-
The library primarily uses async features (following gidgethub), with sync support in active development to better integrate with the majority of Django projects.
14
+
Fully supports both sync (WSGI) and async (ASGI) Django applications.
15
15
16
16
## Requirements
17
17
@@ -51,17 +51,27 @@ The library primarily uses async features (following gidgethub), with sync suppo
51
51
52
52
4. Add django-github-app's webhook view to your Django project's urls.
53
53
54
+
For Django projects running on ASGI, use `django_github_app.views.AsyncWebhookView`:
55
+
54
56
```python
55
57
from django.urls import path
56
-
57
58
from django_github_app.views import AsyncWebhookView
58
59
59
60
urlpatterns = [
60
61
path("gh/", AsyncWebhookView.as_view()),
61
62
]
62
63
```
63
64
64
-
For the moment, django-github-app only provides an async webhook view. While sync support is being actively developed, the webhook view remains async-only.
65
+
For traditional Django projects running on WSGI, use `django_github_app.views.SyncWebhookView`:
66
+
67
+
```python
68
+
from django.urls import path
69
+
from django_github_app.views import SyncWebhookView
70
+
71
+
urlpatterns = [
72
+
path("gh/", SyncWebhookView.as_view()),
73
+
]
74
+
```
65
75
66
76
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.
67
77
@@ -169,6 +179,8 @@ django-github-app provides a router-based system for handling GitHub webhook eve
169
179
170
180
To start handling GitHub webhooks, create your event handlers in a new file (e.g., `events.py`) within your Django app.
171
181
182
+
For ASGI projects using `django_github_app.views.AsyncWebhookView`:
183
+
172
184
```python
173
185
# your_app/events.py
174
186
from django_github_app.routing import GitHubRouter
In this example, we automatically label issues based on their title and post a welcome comment on newly opened issues. The router ensures each webhook is directed to the appropriate handler based on the event type and action.
219
+
For WSGI projects using `django_github_app.views.SyncWebhookView`:
208
220
209
-
> [!NOTE]
210
-
> Handlers must be async functions as django-github-app uses gidgethub for webhook event routing which only supports async operations. Sync support is planned to better integrate with Django projects that don't use async.
221
+
```python
222
+
# your_app/events.py
223
+
from django_github_app.routing import GitHubRouter
"body": "Thanks for opening an issue! We'll take a look soon."
253
+
})
254
+
```
255
+
256
+
> [!IMPORTANT]
257
+
> Choose either async or sync handlers based on your webhook view - async handlers for`AsyncWebhookView`, sync handlers for`SyncWebhookView`. Mixing async and sync handlers is not supported.
258
+
259
+
In these examples, we automatically label issues based on their title and post a welcome comment on newly opened issues. The router ensures each webhook is directed to the appropriate handler based on the event type and action.
211
260
212
261
Each handler receives two arguments:
213
262
214
263
- `event`: A `gidgethub.sansio.Event` containing the webhook payload
215
-
- `gh`: A GitHub API client for making API calls
264
+
- `gh`: A GitHub API client for making API calls (`AsyncGitHubAPI`for async handlers, `SyncGitHubAPI`for sync handlers)
216
265
217
266
To activate your webhook handlers, import them in your app's `AppConfig.ready()` method, similar to how Django signals are registered.
0 commit comments