Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PlaneClient
- `plane/client/` — `PlaneClient` (API key / access token auth) and `OAuthClient` (OAuth 2.0 flows).
- `plane/errors/` — `PlaneError` → `HttpError`, `ConfigurationError`.
- `plane/config.py` — `Configuration` and `RetryConfig` dataclasses.
- `plane/api/v2/` — the v2 surface (`client.v2`). **Migration complete**: all 95
- `plane/api/v2/` — the v2 surface (`client.v2`). **Migration complete**: all 96
`V2Resource` subclasses in the package (`tests/v2/tree_walk.py`'s
`all_resource_classes()`) are on the flat shape and swept by the rule tests.
`tests/v2/tree_walk.py`'s `UNMIGRATED_RESOURCES` — the opt-out list the sweeps
Expand All @@ -90,7 +90,7 @@ PlaneClient
never grow, so it cannot silently regain a member. Count resources, not
grouping nodes: `wiki` and `group_sync` hold no `V2Resource` base, `path` or
`operations` of their own — they only group children (`wiki.pages`,
`wiki.collections`, `group_sync.config`) — so neither is in the 95.
`wiki.collections`, `group_sync.config`) — so neither is in the 96.

The whole project band is wired onto `client.v2.workspaces.projects`:
`states`, `labels`, `work_items`, `cycles`, `milestones`, `modules`,
Expand All @@ -99,7 +99,7 @@ PlaneClient
`work_item_properties`, `work_item_types` and `workflows` — nineteen
children, and a fetched project reaches every one of them that is itself
navigable (`project.cycles.list()`, `project.permissions.me()`). Twenty-one of
the 95 classes are navigable — `workspaces`, `projects`, `work_items`,
the 96 classes are navigable — `workspaces`, `projects`, `work_items`,
`cycles`, `milestones`, `modules`, `estimates`, `webhooks`, `collections`,
`customers`, `initiatives`, `releases`, `work_item_types`,
`work_item_properties`, `automations`, `workflows`, `dashboards` and `agent_runs`
Expand All @@ -115,8 +115,8 @@ PlaneClient
`estimate_points`, not `points` — `Estimate.points` is itself an API field,
returned inline by `expand=["points"]`. `webhooks` is workspace-scoped, not
part of the project band, reached via `.logs`. A fetched work item reaches
all seven of its children — `comments`, `attachments`, `links`, `worklogs`,
`activities`, `relations`, `dependencies`.
all eight of its children — `comments`, `attachments`, `links`, `worklogs`,
`activities`, `relations`, `dependencies`, `subscribers`.

`client.v2.workspaces.roles.list("acme", role_slug="admin")` is worth flagging:
the workspace slug is the positional argument, while the role's own slug filter
Expand Down Expand Up @@ -167,7 +167,7 @@ PlaneClient
`cycles`, `milestones`, `modules`, `estimates`, `webhooks`, `collections`,
`customers`, `initiatives`, `releases`, `work_item_types`,
`work_item_properties`, `automations`, `workflows`, `dashboards`, `workspaces`,
`agent_runs` — 21 of the 95 classes) returns a `Loaded` row from
`agent_runs` — 21 of the 96 classes) returns a `Loaded` row from
`retrieve`/`list`/`iterate`, not a bare
pydantic model: it carries its own data and reaches its own children with none of the
ids repeated (`project.states.list()`, `work_item.comments.list()`,
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ work_items = client.work_items.list(

`client.v2` reaches the v2 surface. v1 resources on the client are unchanged.

The v2 surface is complete: every one of the 95 `V2Resource` subclasses in the
The v2 surface is complete: every one of the 96 `V2Resource` subclasses in the
package (`tests/v2/tree_walk.py`'s `all_resource_classes()`, the enumeration the
test suite itself sweeps) is on the flat shape described below and reachable
through `client.v2`. Counting resources means not counting grouping nodes:
`wiki` and `group_sync` hold no `V2Resource` base, `path` or `operations` of
their own — they only group children (`wiki.pages`, `wiki.collections`,
`group_sync.config`) — and are outside the 95.
`group_sync.config`) — and are outside the 96.

Wired directly on `client.v2.workspaces`: `agent_runs` (with `.activities`),
`agent_run_activities`, `artifacts`, `assets`, `audit_logs`,
Expand Down Expand Up @@ -279,7 +279,7 @@ client.v2.workspaces.projects.states.list(slug="acme", project="ENG")
A resource with children (`projects`, `work_items`, `cycles`, `milestones`,
`modules`, `estimates`, `webhooks`, `collections`, `customers`, `initiatives`,
`releases`, `work_item_types`, `work_item_properties`, `automations`,
`workflows`, `dashboards`, `workspaces` and `agent_runs` — 21 of the 95 classes, some
`workflows`, `dashboards`, `workspaces` and `agent_runs` — 21 of the 96 classes, some
families having a separate project-scoped and workspace-scoped resource, each
independently navigable)
doesn't just hand back a bare pydantic model from `retrieve`/`list`/`iterate` —
Expand Down Expand Up @@ -315,8 +315,9 @@ log; `collections` via `.members`/`.pages`; `customers` via `.requests`,
workspace-scoped resource only); `automations` via `.edges`, `.nodes`,
`.activities`; `workflows` via `.states`, `.transitions`; `dashboards` via
`.widgets`; and `agent_runs` via `.activities`, the run's log. A work item
itself reaches all seven of its own children this way — `comments`,
`attachments`, `links`, `worklogs`, `activities`, `relations`, `dependencies`.
itself reaches all eight of its own children this way — `comments`,
`attachments`, `links`, `worklogs`, `activities`, `relations`, `dependencies`,
`subscribers`.

`list` and `iterate` yield these same navigable rows, not bare pydantic models —
`for project in client.v2.workspaces.projects.iterate("acme"): project.states.list()`
Expand Down Expand Up @@ -402,7 +403,7 @@ scripts to prove it, rather than trusting it by inspection.
### The five rules the tests enforce

Five properties of the surface are each enforced by a sweep in `tests/v2/`, over
every one of the 95 resource classes (`tests/v2/tree_walk.py`'s
every one of the 96 resource classes (`tests/v2/tree_walk.py`'s
`all_resource_classes()`) rather than a hand-picked subset — so a newly added
resource is covered the moment it exists, with nothing to remember to add it to:

Expand Down
4 changes: 4 additions & 0 deletions plane/api/v2/_generated/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@
"work_items_partial_update",
"work_items_retrieve",
"work_items_retrieve_by_identifier",
"work_items_subscribers_partial_update",
"work_items_subscribers_partial_update_by_identifier",
"work_items_subscribers_retrieve",
"work_items_subscribers_retrieve_by_identifier",
"work_items_unarchive",
"work_items_upsert",
"work_items_use",
Expand Down
11 changes: 11 additions & 0 deletions plane/api/v2/_loaded/work_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..work_items.dependencies import WorkItemDependencies
from ..work_items.links import WorkItemLinks
from ..work_items.relations import WorkItemRelations
from ..work_items.subscribers import WorkItemSubscribersResource
from ..work_items.worklogs import WorkItemWorklogs

# Typed view on `Owned`: `WorkItemComments`' own methods with `slug`, `project`
Expand Down Expand Up @@ -71,6 +72,10 @@ class _OwnedDependencies(Owned["WorkItemDependencies"]):
create = staticmethod(bind3(WorkItemDependencies.create))
delete = staticmethod(bind3(WorkItemDependencies.delete))

class _OwnedSubscribers(Owned["WorkItemSubscribersResource"]):
retrieve = staticmethod(bind3(WorkItemSubscribersResource.retrieve))
update = staticmethod(bind3(WorkItemSubscribersResource.update))


class LoadedWorkItem(Loaded, WorkItem):
"""A work item row that is also the place its children live."""
Expand Down Expand Up @@ -116,3 +121,9 @@ def dependencies(self) -> _OwnedDependencies:
return cast(
"_OwnedDependencies", Owned(self._resources.dependencies, self._ids, self._id_names)
)

@property
def subscribers(self) -> _OwnedSubscribers:
return cast(
"_OwnedSubscribers", Owned(self._resources.subscribers, self._ids, self._id_names)
)
9 changes: 6 additions & 3 deletions plane/api/v2/work_items/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Work items (api_v2) -- the hardest, and largest, api_v2 resource family.
Project-scoped, with `archive`/`unarchive` plus nested `.comments`/`.attachments`/
`.links`/`.worklogs`/`.activities`/`.relations`/`.dependencies`.
`.links`/`.worklogs`/`.activities`/`.relations`/`.dependencies`/`.subscribers`.

A fetched row (`retrieve`/`create`, and every row in a `list` page) comes back as
a `LoadedWorkItem`: it carries the row's data and can reach every child -- `.comments`,
`.attachments`, `.links`, `.worklogs`, `.activities`, `.relations`, `.dependencies` --
without the caller repeating `slug`/`project`/`work_item`."""
`.attachments`, `.links`, `.worklogs`, `.activities`, `.relations`, `.dependencies`,
`.subscribers` -- without the caller repeating `slug`/`project`/`work_item`."""

from __future__ import annotations

Expand Down Expand Up @@ -38,6 +38,7 @@
from .dependencies import WorkItemDependencies
from .links import WorkItemLinks
from .relations import WorkItemRelations
from .subscribers import WorkItemSubscribersResource
from .worklogs import WorkItemWorklogs
from .workspace import WorkspaceWorkItems

Expand All @@ -48,6 +49,7 @@
"WorkItemDependencies",
"WorkItemLinks",
"WorkItemRelations",
"WorkItemSubscribersResource",
"WorkItemWorklogs",
"WorkItems",
"WorkspaceWorkItems",
Expand Down Expand Up @@ -84,6 +86,7 @@ def __init__(self, transport: V2Transport) -> None:
self.activities = WorkItemActivities(transport)
self.relations = WorkItemRelations(transport)
self.dependencies = WorkItemDependencies(transport)
self.subscribers = WorkItemSubscribersResource(transport)

# -- CRUD ---------------------------------------------------------------

Expand Down
53 changes: 53 additions & 0 deletions plane/api/v2/work_items/subscribers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Work item subscribers (api_v2). One list per work item with no pk of its own, so it
goes through the kernel's `_retrieve_singleton`/`_update_singleton` pair. Named
`WorkItemSubscribersResource` to avoid clashing with the `WorkItemSubscribers` model.

The `*_by_identifier` pair reaches the same list by human-readable key (e.g.
`"ENG-12"`) with no project id, via `extra_paths`."""

from __future__ import annotations

from ....models.v2.work_items import UpdateWorkItemSubscribers, WorkItemSubscribers
from .._kernel.resource import V2Resource

__all__ = ["WorkItemSubscribersResource"]

_BY_IDENTIFIER = "/workspaces/{slug}/work-items/{identifier}/subscribers/"


class WorkItemSubscribersResource(
V2Resource[WorkItemSubscribers, UpdateWorkItemSubscribers, UpdateWorkItemSubscribers]
):
path = "/workspaces/{slug}/projects/{project_id}/work-items/{work_item_id}/subscribers/"
extra_paths = {
"retrieve_by_identifier": _BY_IDENTIFIER,
"update_by_identifier": _BY_IDENTIFIER,
}
model = WorkItemSubscribers
operations = {
"retrieve": "work_items_subscribers_retrieve",
"update": "work_items_subscribers_partial_update",
"retrieve_by_identifier": "work_items_subscribers_retrieve_by_identifier",
"update_by_identifier": "work_items_subscribers_partial_update_by_identifier",
}

def retrieve(self, slug: str, project: str, work_item: str) -> WorkItemSubscribers:
return self._retrieve_singleton(slug=slug, project_id=project, work_item_id=work_item)

def update(
self, slug: str, project: str, work_item: str, data: UpdateWorkItemSubscribers
) -> WorkItemSubscribers:
"""Apply `add`/`remove` and return the resulting list."""
return self._update_singleton(data, slug=slug, project_id=project, work_item_id=work_item)

def retrieve_by_identifier(self, slug: str, identifier: str) -> WorkItemSubscribers:
return self._retrieve_singleton(
action="retrieve_by_identifier", slug=slug, identifier=identifier
)

def update_by_identifier(
self, slug: str, identifier: str, data: UpdateWorkItemSubscribers
) -> WorkItemSubscribers:
return self._update_singleton(
data, action="update_by_identifier", slug=slug, identifier=identifier
)
4 changes: 4 additions & 0 deletions plane/models/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
UpdateWorkItem,
UpdateWorkItemComment,
UpdateWorkItemLink,
UpdateWorkItemSubscribers,
UpdateWorkItemWorklog,
WorkItem,
WorkItemActivity,
Expand All @@ -329,6 +330,7 @@
WorkItemLink,
WorkItemRelationCreate,
WorkItemRelationList,
WorkItemSubscribers,
WorkItemWorklog,
)
from .workflows import (
Expand Down Expand Up @@ -548,6 +550,8 @@
"CreateWorkItemComment",
"WorkItemDependencyCreate",
"WorkItemDependencyList",
"WorkItemSubscribers",
"UpdateWorkItemSubscribers",
"WorkItemLink",
"UpdateWorkItemLink",
"CreateWorkItemLink",
Expand Down
23 changes: 22 additions & 1 deletion plane/models/v2/work_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import date, datetime
from typing import Literal

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field

from .agent_runs import AgentRunLite

Expand Down Expand Up @@ -333,3 +333,24 @@ class WorkItemDependencyCreate(BaseModel):

relation_type: DependencyRelationType
work_item_ids: list[str]


# -- Subscribers ----------------------------------------------------------------


class WorkItemSubscribers(BaseModel):
"""The ids of the users subscribed to a work item."""

model_config = ConfigDict(extra="allow")

subscriber_ids: list[str]


class UpdateWorkItemSubscribers(BaseModel):
"""Subscribe the `add` users and unsubscribe the `remove` users; both optional.
Adding someone already subscribed, or removing someone who isn't, changes nothing."""

model_config = ConfigDict(extra="ignore")

add: list[str] | None = Field(default=None, max_length=100)
remove: list[str] | None = Field(default=None, max_length=100)
3 changes: 2 additions & 1 deletion tests/v2/test_singleton_verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def test_every_singleton_read_is_spelled_retrieve_or_me() -> None:
offenders = sorted(
f"{resource_class.__name__}.{name}()"
for resource_class, name in SINGLETON_READS
if name not in {"retrieve", *CALLER_SCOPED}
# `retrieve_by_identifier` is `retrieve` by readable key, the name it has everywhere.
if name not in {"retrieve", "retrieve_by_identifier", *CALLER_SCOPED}
# `list`-shaped singletons are a separate case: a collection URL that answers a
# map or an array rather than one row (`CustomerPropertyValues`,
# `WorkItemRelations`, `WorkItemDependencies`) is honestly a `list`.
Expand Down
45 changes: 44 additions & 1 deletion tests/v2/test_work_items_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Offline coverage for `WorkItems` (the flat depth-2 pattern), `WorkItemComments`
(the depth-3 exemplar: `slug, project, work_item` leading parameters), and the other
six work-item children on the same depth-3 shape. The children are constructed
seven work-item children on the same depth-3 shape. The children are constructed
directly rather than through `work_items.attachments` -- a resource's methods work
identically either way now that `V2Resource.__init__` binds no scope, and the tree
wiring itself is proved by `tests/v2/test_tree.py`."""
Expand All @@ -19,6 +19,7 @@
from plane.api.v2.work_items.dependencies import WorkItemDependencies
from plane.api.v2.work_items.links import WorkItemLinks
from plane.api.v2.work_items.relations import WorkItemRelations
from plane.api.v2.work_items.subscribers import WorkItemSubscribersResource
from plane.api.v2.work_items.worklogs import WorkItemWorklogs
from plane.config import Configuration
from plane.models.v2.work_items import (
Expand All @@ -30,6 +31,7 @@
UpdateWorkItem,
UpdateWorkItemComment,
UpdateWorkItemLink,
UpdateWorkItemSubscribers,
UpdateWorkItemWorklog,
WorkItemAttachmentConfirm,
WorkItemDependencyCreate,
Expand Down Expand Up @@ -516,6 +518,11 @@ def dependencies(config: Configuration) -> WorkItemDependencies:
return WorkItemDependencies(V2Transport(config))


@pytest.fixture
def subscribers(config: Configuration) -> WorkItemSubscribersResource:
return WorkItemSubscribersResource(V2Transport(config))


@pytest.fixture
def worklogs(config: Configuration) -> WorkItemWorklogs:
return WorkItemWorklogs(V2Transport(config))
Expand Down Expand Up @@ -699,6 +706,41 @@ def test_dependencies_list_and_create_hit_the_collection_url(
assert responses.calls[2].request.url == f"{BASE}/w1/dependencies/w2/"


@responses.activate
def test_subscribers_retrieve_and_update_hit_the_singleton_url(
subscribers: WorkItemSubscribersResource,
) -> None:
responses.get(f"{BASE}/w1/subscribers/", json={"subscriber_ids": ["u1"]})
responses.patch(f"{BASE}/w1/subscribers/", json={"subscriber_ids": ["u2"]})

assert subscribers.retrieve("acme", "ENG", "w1").subscriber_ids == ["u1"]
assert responses.calls[0].request.url == f"{BASE}/w1/subscribers/"

updated = subscribers.update(
"acme", "ENG", "w1", UpdateWorkItemSubscribers(add=["u2"], remove=["u1"])
)
assert updated.subscriber_ids == ["u2"]
assert responses.calls[1].request.method == "PATCH"
assert json.loads(responses.calls[1].request.body) == {"add": ["u2"], "remove": ["u1"]}


@responses.activate
def test_subscribers_by_identifier_need_no_project(
subscribers: WorkItemSubscribersResource,
) -> None:
url = "https://api.example.com/api/v2/workspaces/acme/work-items/ENG-12/subscribers/"
responses.get(url, json={"subscriber_ids": ["u1"]})
responses.patch(url, json={"subscriber_ids": []})

assert subscribers.retrieve_by_identifier("acme", "ENG-12").subscriber_ids == ["u1"]
removed = subscribers.update_by_identifier(
"acme", "ENG-12", UpdateWorkItemSubscribers(remove=["u1"])
)
assert removed.subscriber_ids == []
assert [call.request.url for call in responses.calls] == [url, url]
assert json.loads(responses.calls[1].request.body) == {"remove": ["u1"]}


@responses.activate
def test_worklogs_full_crud_with_expand(worklogs: WorkItemWorklogs) -> None:
responses.get(
Expand Down Expand Up @@ -842,5 +884,6 @@ def test_fetched_work_item_reaches_every_child(config: Configuration) -> None:
"activities",
"relations",
"dependencies",
"subscribers",
):
assert hasattr(item, child), f"LoadedWorkItem is missing {child}"
Loading