Skip to content

feat: added work items count endpoint#48

Merged
dheeru0198 merged 8 commits into
mainfrom
chore-work-item-count
Jun 9, 2026
Merged

feat: added work items count endpoint#48
dheeru0198 merged 8 commits into
mainfrom
chore-work-item-count

Conversation

@sangeethailango

@sangeethailango sangeethailango commented Jun 5, 2026

Copy link
Copy Markdown
Member

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 work-item count endpoint returns grouped counts with a consistent grouped response format.
    • Flexible filtering and grouping across multiple dimensions (status, assignee, etc.) for clearer distribution insights.
    • Nested subgrouping with optional sub-group breakdowns and aggregated totals for deeper analysis.
  • Chores
    • Package version bump.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

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 41 minutes and 13 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: 96be242a-2eea-4025-9e00-2b46fbafce1b

📥 Commits

Reviewing files that changed from the base of the PR and between df4f3b1 and 060bdb0.

📒 Files selected for processing (3)
  • plane/api/work_items/base.py
  • plane/models/query_params.py
  • 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.

Project Metadata

Layer / File(s) Summary
pyproject version bump
pyproject.toml
Bumps project version from 0.2.14 to 0.2.15.

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

Possibly related PRs

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 describes the main change: adding a new work items count endpoint to the API with supporting models and query parameters.
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 thread plane/models/work_items.py Outdated
Comment thread plane/models/query_params.py Outdated
Comment thread plane/models/query_params.py
Comment thread plane/models/query_params.py
Comment thread plane/models/query_params.py
Comment thread plane/api/work_items/base.py
Comment thread plane/models/work_items.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread plane/models/query_params.py Outdated
Comment thread plane/api/work_items/base.py
Comment thread plane/models/work_items.py Outdated
Comment thread plane/api/work_items/base.py
sangeethailango and others added 2 commits June 9, 2026 18:12
…s non-optional

Raises ValueError when sub_group_by is set without group_by. Tightens
WorkItemGroupedCountResponse so total_count is always an int and
grouped_counts always a dict (never None).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dheeru0198 dheeru0198 merged commit 491a923 into main Jun 9, 2026
4 checks passed
@dheeru0198 dheeru0198 deleted the chore-work-item-count branch June 9, 2026 12:47
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