Skip to content

feat: added work items count endpoint#48

Open
sangeethailango wants to merge 5 commits into
mainfrom
chore-work-item-count
Open

feat: added work items count endpoint#48
sangeethailango wants to merge 5 commits into
mainfrom
chore-work-item-count

Conversation

@sangeethailango
Copy link
Copy Markdown
Member

@sangeethailango sangeethailango commented Jun 5, 2026

This pull request introduces a new API for counting work items in a workspace, with support for filtering and grouping, and adds corresponding data models and query parameter types. The changes include a new count_workspace method, new query parameter and response models, and supporting serialization logic.

New Work Item Counting API

  • WorkItems.count_workspace: Adds a new method to return the count of work items in a workspace, supporting optional filters, PQL, and grouping by various fields. The method returns either a flat count or grouped counts depending on the parameters.
  • prepare_work_item_count_params: Adds a helper function to serialize work item count query parameters, including filters, for HTTP requests.

Models and Query Parameter Types

  • WorkItemCountQueryParams and WorkItemCountGroupBy: Introduces new query parameter DTOs for the count endpoint, supporting filters, PQL, and a group_by field for grouped counts.
  • WorkItemFlatCountResponse, WorkItemGroupedCountResponse, WorkItemGroupCountEntry, and WorkItemCountResponse: Adds new response models to represent flat and grouped count results from the count endpoint.

Imports and Type Annotations

  • Updates imports in plane/api/work_items/base.py to include the new query parameter and response models.

Summary by CodeRabbit

  • New Features
    • Workspace-level work item count endpoint: get counts for a workspace as grouped results.
    • Flexible filtering and grouping across multiple dimensions (status, assignee, etc.) for clearer distribution insights.
    • Nested subgrouping support: group counts can include optional sub-group breakdowns and aggregated totals for deeper analysis.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

Warning

Review limit reached

@sangeethailango, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 21 minutes and 45 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cbc254d2-4d8d-4ab4-bf16-20186f39a9e0

📥 Commits

Reviewing files that changed from the base of the PR and between ea4e7b2 and 3c65a69.

📒 Files selected for processing (1)
  • plane/models/work_items.py
📝 Walkthrough

Walkthrough

Adds query DTOs and grouped (with optional subgrouping) count response models, plus a params serializer and WorkItems.count_workspace which GETs the workspace work-items count endpoint and returns the grouped-count response.

Changes

Work Item Count Feature

Layer / File(s) Summary
Count query parameters and group-by contract
plane/models/query_params.py
Adds WorkItemCountGroupBy literal and WorkItemCountQueryParams with optional pql, filters, group_by, and sub_group_by.
Count response models
plane/models/work_items.py
Adds WorkItemSubGroupCountEntry, WorkItemGroupCountEntry (supports flat count or nested total_count + sub_grouped_counts), WorkItemGroupedCountResponse, and aliases WorkItemCountResponse to the grouped response.
Workspace count endpoint integration
plane/api/work_items/base.py
Imports count DTOs, adds prepare_work_item_count_params (JSON-encodes dict filters) and WorkItems.count_workspace which GETs {workspace_slug}/work-items/count and validates the response as WorkItemGroupedCountResponse.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant WorkItems
  participant prepare_work_item_count_params
  participant HTTP_API
  participant Validator
  Client->>WorkItems: count_workspace(workspace_slug, params)
  WorkItems->>prepare_work_item_count_params: serialize params
  prepare_work_item_count_params-->>WorkItems: query params dict
  WorkItems->>HTTP_API: GET /workspaces/{slug}/work-items/count with params
  HTTP_API-->>WorkItems: JSON response
  WorkItems->>Validator: validate as WorkItemGroupedCountResponse
  Validator-->>Client: WorkItemCountResponse (grouped)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Prashant-Surya

Poem

🐰 I bounced through params, filters in tow,
I grouped and sub-grouped where numbers grow,
A helper encoded each dict with care,
The count endpoint answered — grouped counts to share!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new work items count endpoint with supporting DTOs and models.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore-work-item-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new Workspace-level Work Items “count” API to the SDK, enabling clients to retrieve either a single total count or grouped counts (by a chosen dimension), with optional filtering via structured filters or PQL.

Changes:

  • Added WorkItems.count_workspace(...) plus serialization helper for count-specific query params.
  • Introduced new query-param DTOs for the count endpoint: WorkItemCountQueryParams and WorkItemCountGroupBy.
  • Added new response models for flat and grouped count responses (WorkItemFlatCountResponse, WorkItemGroupedCountResponse, etc.).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
plane/models/work_items.py Adds new Pydantic response models for flat vs. grouped count payloads.
plane/models/query_params.py Adds count-endpoint query parameter DTOs and a Literal[...] type for supported group_by values.
plane/api/work_items/base.py Implements count_workspace and a helper to serialize count query params (including JSON-encoding filters).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plane/api/work_items/base.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

Comment thread plane/models/work_items.py Outdated
Comment on lines +670 to +673
grouped_by: str | None = None
sub_grouped_by: str | None = None
total_count: int | None = None
grouped_counts: dict[str, WorkItemGroupCountEntry] | None = None
Comment on lines +117 to +120
Without ``group_by`` the response is ``{"count": N}``.
With ``group_by`` the response is
``{"grouped_by": ..., "total_count": N, "results": {group_key: {"count": N}}}``.
"""
Comment on lines +141 to +144
"ORM field to group counts by. When supplied the response shape "
"changes from a flat ``{count}`` to a grouped "
"``{grouped_by, total_count, results}`` envelope."
),
Comment on lines +150 to +153
"Optional second field to group by, for nested grouping. Only valid if "
"`group_by` is also supplied. The response shape changes to include an "
"additional nesting level in the `results` envelope."
),
Comment on lines +147 to +155
sub_group_by: WorkItemCountGroupBy | None = Field(
None,
description=(
"Optional second field to group by, for nested grouping. Only valid if "
"`group_by` is also supplied. The response shape changes to include an "
"additional nesting level in the `results` envelope."
),
)

Comment on lines +269 to +273
def count_workspace(
self,
workspace_slug: str,
params: WorkItemQueryParams | None = None,
) -> PaginatedWorkItemResponse:
"""List work items across the entire workspace.
params: WorkItemCountQueryParams | None = None,
) -> WorkItemCountResponse:
Comment on lines +639 to +642
"sub_grouped_by": null,
"total_count": 42,
"grouped_counts": {"urgent": {"count": 3}, "none": {"count": 6}}
}
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
plane/models/work_items.py (1)

607-624: ⚡ Quick win

Consider adding validation for mutually exclusive shapes.

WorkItemGroupCountEntry supports two distinct shapes (flat with count vs nested with total_count + sub_grouped_counts), but all fields are optional with no validation enforcing the mutual exclusivity. This allows invalid states like:

  • All fields None
  • Both count and total_count set

Since model_validator was imported (line 3), consider adding a validator to enforce that exactly one shape is present:

🛡️ Suggested validator
 class WorkItemGroupCountEntry(BaseModel):
     """Count entry for a single group in a grouped count response.
 
     Shape depends on whether ``sub_group_by`` was supplied:
 
     * **Flat** (``group_by`` only): ``{"count": N}``
     * **Nested** (``group_by`` + ``sub_group_by``):
       ``{"total_count": N, "sub_grouped_counts": {sub_key: {"count": N}}}``
     """
 
     model_config = ConfigDict(extra="allow", populate_by_name=True)
 
     # flat grouped shape (group_by only)
     count: int | None = None
     # sub-grouped shape (group_by + sub_group_by)
     total_count: int | None = None
     sub_grouped_counts: dict[str, WorkItemSubGroupCountEntry] | None = None
+
+    `@model_validator`(mode="after")
+    def validate_shape(self) -> "WorkItemGroupCountEntry":
+        """Ensure exactly one of flat or nested shape is present."""
+        has_flat = self.count is not None
+        has_nested = self.total_count is not None or self.sub_grouped_counts is not None
+        
+        if not has_flat and not has_nested:
+            raise ValueError("Count entry must have either 'count' (flat) or 'total_count'/'sub_grouped_counts' (nested)")
+        if has_flat and has_nested:
+            raise ValueError("Count entry cannot mix flat ('count') and nested ('total_count'/'sub_grouped_counts') shapes")
+        if has_nested and (self.total_count is None or self.sub_grouped_counts is None):
+            raise ValueError("Nested shape requires both 'total_count' and 'sub_grouped_counts'")
+        
+        return self
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plane/models/work_items.py` around lines 607 - 624, WorkItemGroupCountEntry
currently allows invalid combinations because count, total_count, and
sub_grouped_counts are all optional; add a model-level validator on
WorkItemGroupCountEntry (use model_validator with mode="after") that enforces
exactly one valid shape: either a flat shape where count is not None and both
total_count and sub_grouped_counts are None, or a nested shape where total_count
is not None and sub_grouped_counts is a dict (and count is None); raise
ValueError with a clear message for all-none or both-shapes-present cases so
invalid states (all None or both count and total_count set) are rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plane/models/work_items.py`:
- Around line 607-624: WorkItemGroupCountEntry currently allows invalid
combinations because count, total_count, and sub_grouped_counts are all
optional; add a model-level validator on WorkItemGroupCountEntry (use
model_validator with mode="after") that enforces exactly one valid shape: either
a flat shape where count is not None and both total_count and sub_grouped_counts
are None, or a nested shape where total_count is not None and sub_grouped_counts
is a dict (and count is None); raise ValueError with a clear message for
all-none or both-shapes-present cases so invalid states (all None or both count
and total_count set) are rejected.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d2b5a0b-6d86-46e0-8d85-f5b752940100

📥 Commits

Reviewing files that changed from the base of the PR and between c770094 and ea4e7b2.

📒 Files selected for processing (3)
  • plane/api/work_items/base.py
  • plane/models/query_params.py
  • plane/models/work_items.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plane/models/query_params.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants