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
+188Lines changed: 188 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,8 @@ cog.outl(f"- Django {', '.join([version for version in DJ_VERSIONS if version !=
211
211
212
212
## Getting Started
213
213
214
+
### Webhook Events
215
+
214
216
django-github-app provides a router-based system for handling GitHub webhook events, built on top of [gidgethub](https://github.com/gidgethub/gidgethub). The router matches incoming webhooks to your handler functions based on the event type and optional action.
215
217
216
218
To start handling GitHub webhooks, create your event handlers in a new file (e.g., `events.py`) within your Django app.
@@ -315,6 +317,77 @@ For more information about GitHub webhook events and payloads, see these pages i
315
317
316
318
For more details about how `gidgethub.sansio.Event` and webhook routing work, see the [gidgethub documentation](https://gidgethub.readthedocs.io).
317
319
320
+
### Mentions
321
+
322
+
django-github-app provides a `@gh.mention` decorator to easily respond when your GitHub App is mentioned in comments. This is useful for building interactive bots that respond to user commands.
323
+
324
+
For ASGI projects:
325
+
326
+
```python
327
+
# your_app/events.py
328
+
import re
329
+
from django_github_app.routing import GitHubRouter
330
+
from django_github_app.mentions import MentionScope
data={"body": f"Hello! You mentioned me at position {mention.position}"}
386
+
)
387
+
```
388
+
389
+
The mention decorator automatically extracts mentions from comments and provides context about each mention. Handlers are called once for each matching mention in a comment.
390
+
318
391
## Features
319
392
320
393
### GitHub API Client
@@ -485,6 +558,121 @@ The library includes event handlers for managing GitHub App installations and re
485
558
486
559
The library loads either async or sync versions of these handlers based on your `GITHUB_APP["WEBHOOK_TYPE"]` setting.
487
560
561
+
### Mentions
562
+
563
+
The `@gh.mention` decorator provides a powerful way to build interactive GitHub Apps that respond to mentions in comments. When users mention your app (e.g., `@mybot help`), the decorator automatically detects these mentions and routes them to your handlers.
564
+
565
+
#### How It Works
566
+
567
+
The mention system:
568
+
1. Monitors incoming webhook events for comments containing mentions
569
+
2. Extracts all mentions while ignoring those in code blocks, inline code, or blockquotes
570
+
3. Filters mentions based on your specified criteria (username pattern, scope)
571
+
4. Calls your handler once for each matching mention, providing rich context
572
+
573
+
#### Mention Context
574
+
575
+
Each handler receives a `context` parameter with detailed information about the mention:
0 commit comments