Skip to content

Commit f270f30

Browse files
committed
chore: ruff format
1 parent 33283bb commit f270f30

File tree

6 files changed

+295
-219
lines changed

6 files changed

+295
-219
lines changed

src/pydisgit/__init__.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,66 +18,77 @@
1818
app.asgi_app = HmacVerifyMiddleware(app.asgi_app, bound.github_webhook_secret)
1919

2020
from .handlers import router as free_handler_router
21+
2122
handler_router = free_handler_router.bind(bound, app.logger)
2223

2324
# http client
2425

26+
2527
@app.before_serving
2628
async def setup_httpclient():
27-
app.http_client = AsyncClient(
28-
headers={'User-Agent': 'pydisgit (kyori flavour)'}
29-
)
29+
app.http_client = AsyncClient(headers={"User-Agent": "pydisgit (kyori flavour)"})
30+
3031

3132
@app.after_serving
3233
async def teardown_httpclient():
3334
await app.http_client.aclose()
3435

35-
@app.get('/')
36+
37+
@app.get("/")
3638
async def hello() -> str:
3739
"""
3840
root handler
3941
"""
4042
return "begone foul beast", 400
4143

4244

43-
@app.post('/<hook_id>/<token>')
45+
@app.post("/<hook_id>/<token>")
4446
async def gh_hook(hook_id: str, token: str) -> dict:
4547
event = request.headers["X-GitHub-Event"]
4648
if not event or not request.content_type:
4749
raise BadRequest("No event or content type")
4850

49-
#if (!(await validateRequest(request, env.githubWebhookSecret))) {
51+
# if (!(await validateRequest(request, env.githubWebhookSecret))) {
5052
# return new Response('Invalid secret', { status: 403 });
51-
#}
53+
# }
5254

5355
if "application/json" in request.content_type:
5456
json = await request.json
5557
elif "application/x-www-form-urlencoded" in request.content_type:
56-
json = json.loads((await request.form)['payload'])
58+
json = json.loads((await request.form)["payload"])
5759
else:
5860
raise BadRequest(f"Unknown content type {request.content_type}")
5961

6062
embed = handler_router.process_request(event, json)
6163
if not embed:
62-
return 'Webhook NO-OP', 200
64+
return "Webhook NO-OP", 200
6365

64-
if app.config['DEBUG']:
66+
if app.config["DEBUG"]:
6567
pprint.pprint(embed)
6668
pass
6769
# embed = await bound.buildDebugPaste(embed)
6870

6971
http: AsyncClient = app.http_client
7072

71-
result = await http.post(f"https://discord.com/api/webhooks/{hook_id}/{token}", json = embed)
73+
result = await http.post(
74+
f"https://discord.com/api/webhooks/{hook_id}/{token}", json=embed
75+
)
7276

7377
if result.status_code in (200, 204):
7478
result_text = "".join([await a async for a in result.aiter_text()])
75-
return {"message": f"We won! Webhook {hook_id} executed with token {token} :3, response: {result_text}"}, 200
79+
return {
80+
"message": f"We won! Webhook {hook_id} executed with token {token} :3, response: {result_text}"
81+
}, 200
7682
else:
77-
return Response(response = await result.aread(), status = result.status_code, content_type=result.headers['content-type'], headers=result.headers)
83+
return Response(
84+
response=await result.aread(),
85+
status=result.status_code,
86+
content_type=result.headers["content-type"],
87+
headers=result.headers,
88+
)
7889

7990

80-
@app.get('/health')
91+
@app.get("/health")
8192
async def health_check() -> str:
8293
"""
8394
simple aliveness check

src/pydisgit/conf.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
"""
22
Configuration for pydisgit
33
"""
4+
45
from typing import Optional
56
import logging
67
import re
78

9+
810
class Config:
911
"""
1012
Raw environment from Workers
1113
"""
14+
1215
IGNORED_BRANCH_REGEX: str = "^$"
1316
IGNORED_BRANCHES: str = ""
1417
IGNORED_USERS: str = ""
@@ -29,25 +32,27 @@ class BoundEnv:
2932
__ignored_users: list[str]
3033
__ignored_payloads: list[str]
3134
__pastegg_api_key: str
32-
__github_webhook_secret: str;
35+
__github_webhook_secret: str
3336

3437
def __init__(self, env, logger):
35-
self.__ignored_branch_pattern = re.compile(env['IGNORED_BRANCH_REGEX']) if 'IGNORED_BRANCH_REGEX' in env else None
36-
self.__ignored_branches = env['IGNORED_BRANCHES'].split(",")
37-
self.__ignored_users = env['IGNORED_USERS'].split(",")
38-
self.__ignored_payloads = env['IGNORED_PAYLOADS'].split(",")
39-
self.__pastegg_api_key = env['PASTE_GG_API_KEY']
40-
self.__github_webhook_secret = env['GITHUB_WEBHOOK_SECRET']
38+
self.__ignored_branch_pattern = (
39+
re.compile(env["IGNORED_BRANCH_REGEX"]) if "IGNORED_BRANCH_REGEX" in env else None
40+
)
41+
self.__ignored_branches = env["IGNORED_BRANCHES"].split(",")
42+
self.__ignored_users = env["IGNORED_USERS"].split(",")
43+
self.__ignored_payloads = env["IGNORED_PAYLOADS"].split(",")
44+
self.__pastegg_api_key = env["PASTE_GG_API_KEY"]
45+
self.__github_webhook_secret = env["GITHUB_WEBHOOK_SECRET"]
4146

4247
logger.info("Ignored branch pattern: %s", self.__ignored_branch_pattern)
4348
logger.info("Ignored branches: %s", self.__ignored_branches)
4449
logger.info("Ignored users: %s", self.__ignored_users)
4550
logger.info("Ignored payloads: %s", self.__ignored_payloads)
4651

4752
def ignored_branch(self, branch: str) -> bool:
48-
return (self.__ignored_branch_pattern
49-
and self.__ignored_branch_pattern.match(branch)) \
50-
or branch in self.__ignored_branches
53+
return (
54+
self.__ignored_branch_pattern and self.__ignored_branch_pattern.match(branch)
55+
) or branch in self.__ignored_branches
5156

5257
def ignored_user(self, user: str) -> bool:
5358
return user in self.__ignored_users
@@ -61,6 +66,8 @@ def github_webhook_secret(self) -> str:
6166

6267
async def build_debug_paste(self, embed: any) -> str:
6368
pass
69+
70+
6471
# embed = JSON.stringify({
6572
# "files": [
6673
# {

0 commit comments

Comments
 (0)