Skip to content

Commit c9650a1

Browse files
tweak and expand models section of README
1 parent dd0d004 commit c9650a1

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

README.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,24 @@ The client automatically handles authentication and token refresh when an instal
184184
185185
### Models
186186
187+
django-github-app provides models that handle the persistence and retrieval of GitHub App data. These models abstract away common patterns when working with GitHub Apps: storing webhook events, managing installation authentication, and tracking repository access.
188+
189+
All models and their managers provide async methods for database operations and GitHub API interactions, with sync wrappers where appropriate.
190+
187191
#### `EventLog`
188192
189-
Stores incoming webhook events with their payload and timestamp. Includes automatic cleanup of old events based on the `DAYS_TO_KEEP_EVENTS` setting via a `EventLog.objects.acleanup_events` manager method.
193+
Maintains a history of incoming webhook events, storing both the event type and its full payload. Automatically cleans up old events based on your configuration, via the `acleanup_events` manager method and the `GITHUB_APP["DAYS_TO_KEEP_EVENTS"]` setting.
194+
195+
Manager methods:
196+
197+
- `acreate_from_event`/`create_from_event`: Store incoming webhook events _(primarily for internal use)_
198+
- `acleanup_events`/`cleanup_events`: Remove events older than specified days
199+
200+
Properties:
201+
202+
- `action`: Extract action from event payload, if present
203+
204+
The model primarily serves the webhook handling system, but you can also use it to query past events if needed.
190205
191206
#### `Installation`
192207
@@ -198,22 +213,44 @@ from django_github_app.models import Installation
198213
# Get an installation and its access token
199214
installation = await Installation.objects.aget(repositories__full_name="owner/repo")
200215
async with AsyncGitHubAPI(installation_id=installation.installation_id) as gh:
201-
# Do something as the installation
216+
# Authenticated as this installation
217+
await gh.post("/repos/owner/repo/issues", data={"title": "Hello!"})
202218
```
203219
220+
Manager methods:
221+
222+
- `acreate_from_event`/`create_from_event`: Create from installation events _(primarily for internal use)_
223+
- `aget_from_event`/`get_from_event`: Retrieve installation from webhook events (`gidgethub.sansio.Event`)
224+
225+
Methods:
226+
227+
- `aget_access_token`/`get_access_token`: Generate GitHub access token for API calls
228+
204229
#### `Repository`
205230
206-
Represents repositories where your app is installed. Provides convenience methods for common GitHub operations:
231+
Tracks repositories where your app is installed and provides high-level methods for GitHub operations:
207232
208233
```python
209234
from django_github_app.models import Repository
210235
211-
# Get issues for a repository
236+
# Get open issues for a repository
212237
repo = await Repository.objects.aget(full_name="owner/repo")
213-
issues = await repo.aget_issues()
238+
issues = await repo.aget_issues(params={"state": "open"})
214239
```
215240
216-
All models provide both async and sync versions of their methods, though async is recommended for better performance.
241+
Manager methods:
242+
243+
- `aget_from_event`/`get_from_event`: Retrieve repository from webhook events (`gidgethub.sansio.Event`)
244+
245+
Methods:
246+
247+
- `get_gh_client`: Get configured API client for this repository
248+
- `aget_issues`/`get_issues`: Fetch repository's issues
249+
250+
Properties:
251+
252+
- `owner`: Repository owner from full name
253+
- `repo`: Repository name from full name
217254
218255
## Configuration
219256

0 commit comments

Comments
 (0)