Qlty config and code cleanup !2

merged merged by cmc on 2026-10-30 05:51 UTC · krz/hutch-notify:cleanup into main

4 files changed, +67 −10

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +46
@@ -0,0 +1,46 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Function and file complexity are left to review rather than counted.
42[smells.function_complexity]
43enabled = false
44
45[smells.file_complexity]
46enabled = false
app/apns.py +12 −6
@@ -2,6 +2,7 @@ from __future__ import annotations
22
33import json
44import time
5from dataclasses import dataclass
56from pathlib import Path
67
78import httpx
@@ -10,6 +11,13 @@ import jwt
1011from app.config import settings
1112
1213
14@dataclass(frozen=True)
15class APNSTarget:
16 device_token: str
17 apns_env: str
18 topic: str
19
20
1321class APNSClient:
1422 def __init__(self) -> None:
1523 self._key_text = Path(settings.apns_private_key_path).read_text()
@@ -35,16 +43,14 @@ class APNSClient:
3543
3644 async def send_alert(
3745 self,
46 target: APNSTarget,
3847 *,
39 device_token: str,
40 apns_env: str,
41 topic: str,
4248 title: str,
4349 body: str,
4450 payload: dict,
4551 ) -> tuple[bool, str | None, str | None]:
46 host = "https://api.push.apple.com" if apns_env == "production" else "https://api.sandbox.push.apple.com"
47 url = f"{host}/3/device/{device_token}"
52 host = "https://api.push.apple.com" if target.apns_env == "production" else "https://api.sandbox.push.apple.com"
53 url = f"{host}/3/device/{target.device_token}"
4854 merged_payload = {
4955 "aps": {
5056 "alert": {"title": title, "body": body},
@@ -56,7 +62,7 @@ class APNSClient:
5662 url,
5763 headers={
5864 "authorization": f"bearer {self._bearer_token()}",
59 "apns-topic": topic,
65 "apns-topic": target.topic,
6066 "apns-push-type": "alert",
6167 "apns-priority": "10",
6268 },
app/routers/test.py +2 −4
@@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException
22from sqlalchemy import select
33from sqlalchemy.ext.asyncio import AsyncSession
44
5from app.apns import APNSClient
5from app.apns import APNSClient, APNSTarget
66from app.db import get_db
77from app.models import Device
88from app.security import require_api_key
@@ -20,9 +20,7 @@ async def test_push(device_id: int, db: AsyncSession = Depends(get_db)) -> dict:
2020 client = APNSClient()
2121 try:
2222 ok, apns_id, error = await client.send_alert(
23 device_token=device.apns_token,
24 apns_env=device.apns_env,
25 topic=device.bundle_id,
23 APNSTarget(device.apns_token, device.apns_env, device.bundle_id),
2624 title="Hutch test",
2725 body="Test push from hutch-notify",
2826 payload={"event_type": "test", "deep_link": "hutch://home"},