Merge pull request 'fix: Handle nullable Gitea issue metadata' (#51) from timmy/50-handle-nullable-gitea-issue-metadata into main
This commit is contained in:
commit
a6732b9c93
11
src/main.py
11
src/main.py
|
|
@ -86,7 +86,7 @@ async def context() -> JSONResponse:
|
||||||
if isinstance(r, dict)
|
if isinstance(r, dict)
|
||||||
]
|
]
|
||||||
issue_models = [
|
issue_models = [
|
||||||
Issue(id=i["id"], number=i["number"], title=i["title"], state=i["state"], labels=[l.get("name", "") for l in i.get("labels", [])], assignees=[a.get("login", "") for a in i.get("assignees", [])], url=i["html_url"])
|
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[:50]
|
for i in issues_data[:50]
|
||||||
if isinstance(i, dict)
|
if isinstance(i, dict)
|
||||||
]
|
]
|
||||||
|
|
@ -96,14 +96,7 @@ async def context() -> JSONResponse:
|
||||||
if isinstance(p, dict)
|
if isinstance(p, dict)
|
||||||
]
|
]
|
||||||
ctx = compute(user_model, repo_models, issue_models, pr_models)
|
ctx = compute(user_model, repo_models, issue_models, pr_models)
|
||||||
return JSONResponse({
|
return JSONResponse(ctx.model_dump())
|
||||||
"user": ctx.user.dict(),
|
|
||||||
"repos": [r.dict() for r in ctx.repos],
|
|
||||||
"issues": [i.dict() for i in ctx.issues],
|
|
||||||
"pull_requests": [p.dict() for p in ctx.pull_requests],
|
|
||||||
"view": ctx.view,
|
|
||||||
"deltas": [d.dict() for d in ctx.deltas],
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/v1/events")
|
@app.get("/api/v1/events")
|
||||||
|
|
|
||||||
|
|
@ -36,17 +36,17 @@ class PullRequest(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
|
|
||||||
|
class SuggestionDelta(BaseModel):
|
||||||
|
panel: str
|
||||||
|
action: str
|
||||||
|
target: str = ""
|
||||||
|
priority: str = "medium"
|
||||||
|
|
||||||
|
|
||||||
class ViewContext(BaseModel):
|
class ViewContext(BaseModel):
|
||||||
user: User
|
user: User
|
||||||
repos: list[Repo] = []
|
repos: list[Repo] = []
|
||||||
issues: list[Issue] = []
|
issues: list[Issue] = []
|
||||||
pull_requests: list[PullRequest] = []
|
pull_requests: list[PullRequest] = []
|
||||||
view: str = "dashboard"
|
view: str = "dashboard"
|
||||||
deltas: list[dict] = []
|
deltas: list[SuggestionDelta] = []
|
||||||
|
|
||||||
|
|
||||||
class SuggestionDelta(BaseModel):
|
|
||||||
panel: str
|
|
||||||
action: str
|
|
||||||
target: str = ""
|
|
||||||
priority: str = "medium"
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -30,4 +31,35 @@ async def test_context_returns_fallback_when_gitea_exceeds_deadline(monkeypatch)
|
||||||
assert response.headers["retry-after"] == "1"
|
assert response.headers["retry-after"] == "1"
|
||||||
assert b'"repos":[]' in response.body
|
assert b'"repos":[]' in response.body
|
||||||
assert b'"error":"Gitea context request timed out after 0.01s"' in response.body
|
assert b'"error":"Gitea context request timed out after 0.01s"' in response.body
|
||||||
assert cancelled.is_set()
|
assert cancelled.is_set()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_context_normalizes_nullable_issue_collections(monkeypatch):
|
||||||
|
async def user():
|
||||||
|
return {"id": 1, "login": "timmy"}
|
||||||
|
|
||||||
|
async def empty_collection():
|
||||||
|
return []
|
||||||
|
|
||||||
|
async def issue_collection():
|
||||||
|
return [{
|
||||||
|
"id": 50,
|
||||||
|
"number": 50,
|
||||||
|
"title": "Nullable metadata",
|
||||||
|
"state": "open",
|
||||||
|
"labels": None,
|
||||||
|
"assignees": None,
|
||||||
|
"html_url": "https://forge.example/issues/50",
|
||||||
|
}]
|
||||||
|
|
||||||
|
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()
|
||||||
|
issue = json.loads(response.body)["issues"][0]
|
||||||
|
|
||||||
|
assert issue["labels"] == []
|
||||||
|
assert issue["assignees"] == []
|
||||||
Loading…
Reference in New Issue
Block a user