feat: keep delegated filings in My Work (Closes #870)
This commit is contained in:
1 parent
1fdbba1ca1
commit
a9ffc2d879
11 files changed
+179
-15
No files matched your search
+15
-2
@@ -367,6 +367,7 @@ async def repository_access(repository: str) -> dict | None:
|
||||
|
||||
WORK_SEARCHES = {
|
||||
"issue": ("assigned=true", "issues", None),
|
||||
"filed": ("created=true", "issues", "created_by_me"),
|
||||
"pull": ("assigned=true", "pulls", "assigned_to_me"),
|
||||
"review": ("review_requested=true", "pulls", "review_requested"),
|
||||
}
|
||||
@@ -738,8 +739,20 @@ def _page_metadata(result: dict) -> dict:
|
||||
|
||||
|
||||
async def issues() -> WorkItems:
|
||||
result = await work_page("issue")
|
||||
return WorkItems(result["items"], {"issue": _page_metadata(result)})
|
||||
assigned, filed = await asyncio.gather(work_page("issue"), work_page("filed"))
|
||||
merged: dict[int, dict] = {}
|
||||
for result in (assigned, filed):
|
||||
for issue in result["items"]:
|
||||
identity = issue.get("id")
|
||||
if identity not in merged:
|
||||
merged[identity] = {**issue, "work_reasons": []}
|
||||
for reason in issue.get("work_reasons", []):
|
||||
if reason not in merged[identity]["work_reasons"]:
|
||||
merged[identity]["work_reasons"].append(reason)
|
||||
return WorkItems(
|
||||
list(merged.values()),
|
||||
{"issue": _page_metadata(assigned), "filed": _page_metadata(filed)},
|
||||
)
|
||||
|
||||
|
||||
def _safe_web_url(value: Any) -> str:
|
||||
|
||||
+4
-2
@@ -1021,6 +1021,7 @@ def _context_payload(user_data, repo_data, issues_data, prs_data) -> dict:
|
||||
id=i["id"], number=i["number"], title=i["title"], state=i["state"],
|
||||
labels=[label.get("name", "") for label in (i.get("labels") or []) if isinstance(label, dict)],
|
||||
assignees=[assignee.get("login", "") for assignee in (i.get("assignees") or []) if isinstance(assignee, dict)],
|
||||
work_reasons=[reason for reason in (i.get("work_reasons") or []) if reason == "created_by_me"],
|
||||
repository=i["repository"].get("full_name", "") if isinstance(i.get("repository"), dict) else "",
|
||||
updated_at=i.get("updated_at") or "",
|
||||
due_date=i.get("due_date") if isinstance(i.get("due_date"), str) else None,
|
||||
@@ -1060,13 +1061,14 @@ def _context_payload(user_data, repo_data, issues_data, prs_data) -> dict:
|
||||
|
||||
|
||||
def _normalize_work_items(stream: str, items: list[dict]) -> list[dict]:
|
||||
if stream == "issue":
|
||||
if stream in {"issue", "filed"}:
|
||||
return [
|
||||
Issue(
|
||||
id=item["id"], number=item["number"], title=item["title"],
|
||||
state=item["state"],
|
||||
labels=[label.get("name", "") for label in (item.get("labels") or []) if isinstance(label, dict)],
|
||||
assignees=[assignee.get("login", "") for assignee in (item.get("assignees") or []) if isinstance(assignee, dict)],
|
||||
work_reasons=[reason for reason in (item.get("work_reasons") or []) if reason == "created_by_me"],
|
||||
repository=item["repository"].get("full_name", "") if isinstance(item.get("repository"), dict) else "",
|
||||
updated_at=item.get("updated_at") or "",
|
||||
due_date=item.get("due_date") if isinstance(item.get("due_date"), str) else None,
|
||||
@@ -3080,7 +3082,7 @@ async def resolve_work_route(
|
||||
|
||||
@app.get("/api/v1/work/{stream}")
|
||||
async def paged_work(
|
||||
stream: Literal["issue", "pull", "review"],
|
||||
stream: Literal["issue", "filed", "pull", "review"],
|
||||
page: int = Query(ge=2, le=100),
|
||||
) -> JSONResponse:
|
||||
try:
|
||||
|
||||
@@ -29,6 +29,7 @@ class Issue(BaseModel):
|
||||
state: str
|
||||
labels: list[str] = []
|
||||
assignees: list[str] = []
|
||||
work_reasons: list[str] = []
|
||||
repository: str = ""
|
||||
updated_at: str = ""
|
||||
due_date: str | None = None
|
||||
|
||||
Reference in new issue
Block a user