Normalize malformed Gitea pull request authors #88

Merged
rockachopa merged 1 commits from timmy/87-normalize-malformed-gitea-pr-authors into main 2026-08-06 08:18:29 +00:00
2 changed files with 41 additions and 1 deletions

View File

@ -132,7 +132,18 @@ async def context() -> JSONResponse:
)
]
pr_models = [
PullRequest(id=p["id"], number=p["number"], title=p["title"], state=p["state"], user=(p.get("user") or {}).get("login", ""), url=p["html_url"])
PullRequest(
id=p["id"],
number=p["number"],
title=p["title"],
state=p["state"],
user=(
p["user"].get("login", "")
if isinstance(p.get("user"), dict)
else ""
),
url=p["html_url"],
)
for p in (prs_data or [])[:50]
if isinstance(p, dict)
and all(

View File

@ -153,6 +153,35 @@ async def test_context_normalizes_nullable_pull_request_author(monkeypatch):
assert pull_request["user"] == ""
@pytest.mark.anyio
async def test_context_normalizes_malformed_pull_request_author(monkeypatch):
async def user():
return {"id": 1, "login": "timmy"}
async def empty_collection():
return []
async def pull_request_collection():
return [{
"id": 87,
"number": 87,
"title": "Malformed author",
"state": "open",
"user": "unknown",
"html_url": "https://forge.example/pulls/87",
}]
monkeypatch.setattr(main, "current_user", user)
monkeypatch.setattr(main, "repos", empty_collection)
monkeypatch.setattr(main, "issues", empty_collection)
monkeypatch.setattr(main, "pull_requests", pull_request_collection)
response = await main.context()
pull_request = json.loads(response.body)["pull_requests"][0]
assert pull_request["user"] == ""
@pytest.mark.anyio
async def test_context_normalizes_null_collection_payloads(monkeypatch):
async def user():