From 77404cfd03be16d9d59df2dc19664d645259c8f6 Mon Sep 17 00:00:00 2001 From: timmy Date: Thu, 6 Aug 2026 07:17:40 +0000 Subject: [PATCH] fix: skip malformed pull request entries (#83) --- src/main.py | 4 ++++ tests/test_context_timeout.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main.py b/src/main.py index e2725c5..714be72 100644 --- a/src/main.py +++ b/src/main.py @@ -119,6 +119,10 @@ async def context() -> JSONResponse: 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 or [])[:50] if isinstance(p, dict) + and all( + field in p + for field in ("id", "number", "title", "state", "html_url") + ) ] ctx = compute(user_model, repo_models, issue_models, pr_models) return JSONResponse(ctx.model_dump()) diff --git a/tests/test_context_timeout.py b/tests/test_context_timeout.py index 3e7e8ad..d3e2b22 100644 --- a/tests/test_context_timeout.py +++ b/tests/test_context_timeout.py @@ -250,3 +250,36 @@ async def test_context_skips_malformed_issue_entries(monkeypatch): issues = json.loads(response.body)["issues"] assert [issue["title"] for issue in issues] == ["Valid issue"] + + +@pytest.mark.anyio +async def test_context_skips_malformed_pull_request_entries(monkeypatch): + async def user(): + return {"id": 1, "login": "timmy"} + + async def pull_request_collection(): + return [ + {"id": 83, "title": "missing-required-fields"}, + { + "id": 1, + "number": 83, + "title": "Valid pull request", + "state": "open", + "html_url": "https://forge.example/stackchain/stackchain-dashboard/pulls/83", + }, + ] + + async def empty_collection(): + return [] + + 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_requests = json.loads(response.body)["pull_requests"] + + assert [pull_request["title"] for pull_request in pull_requests] == [ + "Valid pull request" + ] -- 2.43.0