Skip to content

Commit 9e095f6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 781910b commit 9e095f6

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

README.md

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Fully supports both sync (WSGI) and async (ASGI) Django applications.
102102
>
103103
> env = environs.Env()
104104
> env.read_env()
105-
>
105+
>
106106
> GITHUB_APP = {
107107
> "PRIVATE_KEY": env.path("GITHUB_PRIVATE_KEY_PATH"),
108108
> }
@@ -202,28 +202,26 @@ gh = GitHubRouter()
202202
async def handle_issue(event, gh, *args, **kwargs):
203203
issue = event.data["issue"]
204204
labels = []
205-
205+
206206
# Add labels based on issue title
207207
title = issue["title"].lower()
208208
if "bug" in title:
209209
labels.append("bug")
210210
if "feature" in title:
211211
labels.append("enhancement")
212-
212+
213213
if labels:
214-
await gh.post(
215-
issue["labels_url"],
216-
data=labels
217-
)
214+
await gh.post(issue["labels_url"], data=labels)
215+
218216
219217
# Handle specific issue actions
220218
@gh.event("issues", action="opened")
221219
async def welcome_new_issue(event, gh, *args, **kwargs):
222220
"""Post a comment when a new issue is opened"""
223221
url = event.data["issue"]["comments_url"]
224-
await gh.post(url, data={
225-
"body": "Thanks for opening an issue! We'll take a look soon."
226-
})
222+
await gh.post(
223+
url, data={"body": "Thanks for opening an issue! We'll take a look soon."}
224+
)
227225
```
228226
229227
For WSGI projects using `django_github_app.views.SyncWebhookView`:
@@ -239,28 +237,24 @@ gh = GitHubRouter()
239237
def handle_issue(event, gh, *args, **kwargs):
240238
issue = event.data["issue"]
241239
labels = []
242-
240+
243241
# Add labels based on issue title
244242
title = issue["title"].lower()
245243
if "bug" in title:
246244
labels.append("bug")
247245
if "feature" in title:
248246
labels.append("enhancement")
249-
247+
250248
if labels:
251-
gh.post(
252-
issue["labels_url"],
253-
data=labels
254-
)
249+
gh.post(issue["labels_url"], data=labels)
250+
255251
256252
# Handle specific issue actions
257253
@gh.event("issues", action="opened")
258254
def welcome_new_issue(event, gh, *args, **kwargs):
259255
"""Post a comment when a new issue is opened"""
260256
url = event.data["issue"]["comments_url"]
261-
gh.post(url, data={
262-
"body": "Thanks for opening an issue! We'll take a look soon."
263-
})
257+
gh.post(url, data={"body": "Thanks for opening an issue! We'll take a look soon."})
264258
```
265259
266260
> [!IMPORTANT]
@@ -279,9 +273,10 @@ To activate your webhook handlers, import them in your app's `AppConfig.ready()`
279273
# your_app/apps.py
280274
from django.apps import AppConfig
281275
276+
282277
class YourAppConfig(AppConfig):
283-
default_auto_field = 'django.db.models.BigAutoField'
284-
name = 'your_app'
278+
default_auto_field = "django.db.models.BigAutoField"
279+
name = "your_app"
285280
286281
def ready(self):
287282
from . import events # noqa: F401
@@ -315,23 +310,24 @@ async def get_public_repo():
315310
async with AsyncGitHubAPI() as gh:
316311
return await gh.getitem("/repos/django/django")
317312
313+
318314
# Interact as the GitHub App installation
319315
async def create_comment(repo_full_name: str):
320316
# Get the installation for the repository
321-
installation = await Installation.objects.aget(repositories__full_name=repo_full_name)
322-
317+
installation = await Installation.objects.aget(
318+
repositories__full_name=repo_full_name
319+
)
320+
323321
async with AsyncGitHubAPI(installation_id=installation.installation_id) as gh:
324322
await gh.post(
325-
f"/repos/{repo_full_name}/issues/1/comments",
326-
data={"body": "Hello!"}
323+
f"/repos/{repo_full_name}/issues/1/comments", data={"body": "Hello!"}
327324
)
328-
325+
329326
# You can either provide the `installation_id` as above, or the `Installation` instance
330327
# itself
331328
async with AsyncGitHubAPI(installation=installation) as gh:
332329
await gh.post(
333-
f"/repos/{repo_full_name}/issues/1/comments",
334-
data={"body": "World!"}
330+
f"/repos/{repo_full_name}/issues/1/comments", data={"body": "World!"}
335331
)
336332
```
337333
@@ -348,24 +344,19 @@ def get_public_repo_sync():
348344
with SyncGitHubAPI() as gh:
349345
return gh.getitem("/repos/django/django")
350346
347+
351348
# Interact as the GitHub App installation
352349
def create_comment_sync(repo_full_name: str):
353350
# Get the installation for the repository
354351
installation = Installation.objects.get(repositories__full_name=repo_full_name)
355-
352+
356353
with SyncGitHubAPI(installation_id=installation.installation_id) as gh:
357-
gh.post(
358-
f"/repos/{repo_full_name}/issues/1/comments",
359-
data={"body": "Hello!"}
360-
)
354+
gh.post(f"/repos/{repo_full_name}/issues/1/comments", data={"body": "Hello!"})
361355
362356
# You can either provide the `installation_id` as above, or the `Installation` instance
363357
# itself
364358
with SyncGitHubAPI(installation=installation) as gh:
365-
gh.post(
366-
f"/repos/{repo_full_name}/issues/1/comments",
367-
data={"body": "World!"}
368-
)
359+
gh.post(f"/repos/{repo_full_name}/issues/1/comments", data={"body": "World!"})
369360
```
370361
371362
### Models

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencies = [
5353
"django-typer[rich]>=2.4.0",
5454
"django>=4.2",
5555
"gidgethub>=5.3.0",
56-
"httpx>=0.27.2",
56+
"httpx>=0.27.2"
5757
]
5858
description = "A Django toolkit for GitHub Apps with batteries included."
5959
dynamic = ["version"]

0 commit comments

Comments
 (0)