From a92109b65f0a2fb1454c08328efb28fed9d73adf Mon Sep 17 00:00:00 2001 From: timmy Date: Thu, 6 Aug 2026 00:47:54 +0000 Subject: [PATCH] fix: normalize nullable pull request authors (#56) --- src/main.py | 2 +- tests/test_context_timeout.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 684461a..b9851c3 100644 --- a/src/main.py +++ b/src/main.py @@ -94,7 +94,7 @@ async def context() -> JSONResponse: if isinstance(i, dict) ] pr_models = [ - PullRequest(id=p["id"], number=p["number"], title=p["title"], state=p["state"], user=p.get("user", {}).get("login", ""), url=p["html_url"]) + PullRequest(id=p["id"], number=p["number"], title=p["title"], state=p["state"], user=(p.get("user") or {}).get("login", ""), url=p["html_url"]) for p in prs_data[:50] if isinstance(p, dict) ] diff --git a/tests/test_context_timeout.py b/tests/test_context_timeout.py index 5de5dec..d17eeb9 100644 --- a/tests/test_context_timeout.py +++ b/tests/test_context_timeout.py @@ -90,4 +90,33 @@ async def test_context_normalizes_nullable_repository_description(monkeypatch): response = await main.context() repository = json.loads(response.body)["repos"][0] - assert repository["description"] == "" \ No newline at end of file + assert repository["description"] == "" + + +@pytest.mark.anyio +async def test_context_normalizes_nullable_pull_request_author(monkeypatch): + async def user(): + return {"id": 1, "login": "timmy"} + + async def empty_collection(): + return [] + + async def pull_request_collection(): + return [{ + "id": 56, + "number": 56, + "title": "Nullable author", + "state": "open", + "user": None, + "html_url": "https://forge.example/pulls/56", + }] + + 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"] == "" \ No newline at end of file