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 `@gh.mention` decorator for handling GitHub mentions in comments. Supports filtering by username pattern (exact match or regex) and scope (issues, PRs, or commits).
Copy file name to clipboardExpand all lines: README.md
+203Lines changed: 203 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,78 @@ 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}"},
387
+
)
388
+
```
389
+
390
+
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.
391
+
318
392
## Features
319
393
320
394
### GitHub API Client
@@ -485,6 +559,135 @@ The library includes event handlers for managing GitHub App installations and re
485
559
486
560
The library loads either async or sync versions of these handlers based on your `GITHUB_APP["WEBHOOK_TYPE"]` setting.
487
561
562
+
### Mentions
563
+
564
+
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.
565
+
566
+
The mention system:
567
+
1. Monitors incoming webhook events for comments containing mentions
568
+
2. Extracts all mentions while ignoring those in code blocks, inline code, or blockquotes
569
+
3. Filters mentions based on your specified criteria (username pattern, scope)
570
+
4. Calls your handler once for each matching mention, providing rich context
571
+
572
+
#### Context
573
+
574
+
Each handler receives a `context` parameter with detailed information about the mention:
0 commit comments