From 5f86b58b88931c2bf335b69794b7ba874212aac2 Mon Sep 17 00:00:00 2001 From: timmy Date: Thu, 6 Aug 2026 06:47:47 +0000 Subject: [PATCH] fix: skip malformed issue entries (#81) --- src/main.py | 4 ++++ tests/test_context_timeout.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main.py b/src/main.py index 6f12139..e2725c5 100644 --- a/src/main.py +++ b/src/main.py @@ -110,6 +110,10 @@ async def context() -> JSONResponse: Issue(id=i["id"], number=i["number"], title=i["title"], state=i["state"], labels=[l.get("name", "") for l in (i.get("labels") or [])], assignees=[a.get("login", "") for a in (i.get("assignees") or [])], url=i["html_url"]) for i in (issues_data or [])[:50] if isinstance(i, dict) + and all( + field in i + for field in ("id", "number", "title", "state", "html_url") + ) ] 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"]) diff --git a/tests/test_context_timeout.py b/tests/test_context_timeout.py index 84976ed..3e7e8ad 100644 --- a/tests/test_context_timeout.py +++ b/tests/test_context_timeout.py @@ -219,3 +219,34 @@ async def test_context_skips_malformed_repository_entries(monkeypatch): repositories = json.loads(response.body)["repos"] assert [repository["name"] for repository in repositories] == ["dashboard"] + + +@pytest.mark.anyio +async def test_context_skips_malformed_issue_entries(monkeypatch): + async def user(): + return {"id": 1, "login": "timmy"} + + async def issue_collection(): + return [ + {"id": 81, "title": "missing-required-fields"}, + { + "id": 1, + "number": 81, + "title": "Valid issue", + "state": "open", + "html_url": "https://forge.example/stackchain/dashboard/issues/81", + }, + ] + + async def empty_collection(): + return [] + + monkeypatch.setattr(main, "current_user", user) + monkeypatch.setattr(main, "repos", empty_collection) + monkeypatch.setattr(main, "issues", issue_collection) + monkeypatch.setattr(main, "pull_requests", empty_collection) + + response = await main.context() + issues = json.loads(response.body)["issues"] + + assert [issue["title"] for issue in issues] == ["Valid issue"]