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 @@ |
| 1 | config_version = "0" |
| 2 | |
| 3 | exclude_patterns = [ |
| 4 | "**/vendor/**", |
| 5 | "**/node_modules/**", |
| 6 | "**/testdata/**", |
| 7 | "**/dist/**", |
| 8 | "**/.build/**", |
| 9 | "**/build/**", |
| 10 | "**/*.min.*", |
| 11 | "**/generated/**", |
| 12 | ".claude/**", |
| 13 | "**/Pods/**", |
| 14 | ] |
| 15 | |
| 16 | test_patterns = [ |
| 17 | "**/test/**", |
| 18 | "**/tests/**", |
| 19 | "**/Tests/**", |
| 20 | "**/*_test.*", |
| 21 | "**/test_*.*", |
| 22 | "**/*.test.*", |
| 23 | "**/*Tests.swift", |
| 24 | "e2e/**", |
| 25 | ] |
| 26 | |
| 27 | [[source]] |
| 28 | name = "default" |
| 29 | default = true |
| 30 | |
| 31 | [[plugin]] |
| 32 | name = "osv-scanner" |
| 33 | |
| 34 | [[plugin]] |
| 35 | name = "trufflehog" |
| 36 | |
| 37 | # Early returns are guard clauses, which keep the happy path unindented. |
| 38 | [smells.return_statements] |
| 39 | enabled = false |
| 40 | |
| 41 | # Function and file complexity are left to review rather than counted. |
| 42 | [smells.function_complexity] |
| 43 | enabled = false |
| 44 | |
| 45 | [smells.file_complexity] |
| 46 | enabled = false |
app/apns.py
+12 −6
| @@ -2,6 +2,7 @@ from __future__ import annotations |
| 2 | 2 | |
| 3 | 3 | import json |
| 4 | 4 | import time |
| 5 | from dataclasses import dataclass |
| 5 | 6 | from pathlib import Path |
| 6 | 7 | |
| 7 | 8 | import httpx |
| @@ -10,6 +11,13 @@ import jwt |
| 10 | 11 | from app.config import settings |
| 11 | 12 | |
| 12 | 13 | |
| 14 | @dataclass(frozen=True) |
| 15 | class APNSTarget: |
| 16 | device_token: str |
| 17 | apns_env: str |
| 18 | topic: str |
| 19 | |
| 20 | |
| 13 | 21 | class APNSClient: |
| 14 | 22 | def __init__(self) -> None: |
| 15 | 23 | self._key_text = Path(settings.apns_private_key_path).read_text() |
| @@ -35,16 +43,14 @@ class APNSClient: |
| 35 | 43 | |
| 36 | 44 | async def send_alert( |
| 37 | 45 | self, |
| 46 | target: APNSTarget, |
| 38 | 47 | *, |
| 39 | | device_token: str, |
| 40 | | apns_env: str, |
| 41 | | topic: str, |
| 42 | 48 | title: str, |
| 43 | 49 | body: str, |
| 44 | 50 | payload: dict, |
| 45 | 51 | ) -> 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}" |
| 48 | 54 | merged_payload = { |
| 49 | 55 | "aps": { |
| 50 | 56 | "alert": {"title": title, "body": body}, |
| @@ -56,7 +62,7 @@ class APNSClient: |
| 56 | 62 | url, |
| 57 | 63 | headers={ |
| 58 | 64 | "authorization": f"bearer {self._bearer_token()}", |
| 59 | | "apns-topic": topic, |
| 65 | "apns-topic": target.topic, |
| 60 | 66 | "apns-push-type": "alert", |
| 61 | 67 | "apns-priority": "10", |
| 62 | 68 | }, |
app/routers/test.py
+2 −4
| @@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException |
| 2 | 2 | from sqlalchemy import select |
| 3 | 3 | from sqlalchemy.ext.asyncio import AsyncSession |
| 4 | 4 | |
| 5 | | from app.apns import APNSClient |
| 5 | from app.apns import APNSClient, APNSTarget |
| 6 | 6 | from app.db import get_db |
| 7 | 7 | from app.models import Device |
| 8 | 8 | from app.security import require_api_key |
| @@ -20,9 +20,7 @@ async def test_push(device_id: int, db: AsyncSession = Depends(get_db)) -> dict: |
| 20 | 20 | client = APNSClient() |
| 21 | 21 | try: |
| 22 | 22 | 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), |
| 26 | 24 | title="Hutch test", |
| 27 | 25 | body="Test push from hutch-notify", |
| 28 | 26 | payload={"event_type": "test", "deep_link": "hutch://home"}, |