fix: skip malformed pull request entries (#83)
All checks were successful
CI / lint (pull_request) Successful in 8s
CI / build-frontend (pull_request) Successful in 5s

This commit is contained in:
timmy 2026-08-06 07:17:40 +00:00
parent 49ce2d9945
commit 77404cfd03
2 changed files with 37 additions and 0 deletions

View File

@ -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())

View File

@ -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"
]