-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbase.py
More file actions
191 lines (168 loc) · 6.41 KB
/
base.py
File metadata and controls
191 lines (168 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from typing import Any
from ...models.query_params import RetrieveQueryParams, WorkItemQueryParams
from ...models.work_items import (
CreateWorkItem,
PaginatedWorkItemResponse,
UpdateWorkItem,
WorkItem,
WorkItemDetail,
WorkItemSearch,
)
from ..base_resource import BaseResource
from .activities import WorkItemActivities
from .attachments import WorkItemAttachments
from .comments import WorkItemComments
from .links import WorkItemLinks
from .relations import WorkItemRelations
from .work_logs import WorkLogs
class WorkItems(BaseResource):
def __init__(self, config: Any) -> None:
super().__init__(config, "/workspaces/")
# Initialize sub-resources
self.relations = WorkItemRelations(config)
self.links = WorkItemLinks(config)
self.attachments = WorkItemAttachments(config)
self.comments = WorkItemComments(config)
self.activities = WorkItemActivities(config)
self.work_logs = WorkLogs(config)
def create(self, workspace_slug: str, project_id: str, data: CreateWorkItem) -> WorkItem:
"""Create a new work item.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
data: Work item data
"""
response = self._post(
f"{workspace_slug}/projects/{project_id}/issues",
data.model_dump(exclude_none=True),
)
return WorkItem.model_validate(response)
def retrieve(
self,
workspace_slug: str,
project_id: str,
work_item_id: str,
params: RetrieveQueryParams | None = None,
) -> WorkItemDetail:
"""Retrieve a work item by ID.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
work_item_id: UUID of the work item
params: Optional query parameters for expand, fields, etc.
Example:
# Get work item with expanded relationships
from plane.models.schemas import RetrieveQueryParams
work_item = client.work_items.retrieve(
"my-workspace",
"project-id",
"work-item-id",
params=RetrieveQueryParams(expand="assignees,labels,state")
)
# Get specific fields only
work_item = client.work_items.retrieve(
"my-workspace",
"project-id",
"work-item-id",
params=RetrieveQueryParams(fields="id,name,priority,state")
)
"""
query_params = params.model_dump(exclude_none=True) if params else None
response = self._get(
f"{workspace_slug}/projects/{project_id}/issues/{work_item_id}",
params=query_params,
)
return WorkItemDetail.model_validate(response)
def retrieve_by_identifier(
self,
workspace_slug: str,
project_identifier: str,
issue_identifier: int,
params: RetrieveQueryParams | None = None,
) -> WorkItemDetail:
"""Retrieve a work item by project and issue identifiers.
Args:
workspace_slug: The workspace slug identifier
project_identifier: Project identifier string
issue_identifier: Issue sequence number
params: Optional query parameters for expand, fields, etc.
"""
query_params = params.model_dump(exclude_none=True) if params else None
response = self._get(
f"{workspace_slug}/issues/{project_identifier}-{issue_identifier}",
params=query_params,
)
return WorkItemDetail.model_validate(response)
def update(
self,
workspace_slug: str,
project_id: str,
work_item_id: str,
data: UpdateWorkItem,
) -> WorkItem:
"""Update a work item by ID.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
work_item_id: UUID of the work item
data: Updated work item data
"""
response = self._patch(
f"{workspace_slug}/projects/{project_id}/issues/{work_item_id}",
data.model_dump(exclude_none=True),
)
return WorkItem.model_validate(response)
def delete(self, workspace_slug: str, project_id: str, work_item_id: str) -> None:
"""Delete a work item by ID.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
work_item_id: UUID of the work item
"""
return self._delete(f"{workspace_slug}/projects/{project_id}/issues/{work_item_id}")
def list(
self,
workspace_slug: str,
project_id: str,
params: WorkItemQueryParams | None = None,
) -> PaginatedWorkItemResponse:
"""List work items with optional filtering parameters.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
params: Optional query parameters for filtering, ordering, and pagination
Example:
from plane.models.schemas import WorkItemQueryParams
# List work items with filters
work_items = client.work_items.list(
"my-workspace",
"project-id",
params=WorkItemQueryParams(
priority="high",
state="state-id",
expand="assignees,labels"
)
)
"""
query_params = params.model_dump(exclude_none=True) if params else None
response = self._get(
f"{workspace_slug}/projects/{project_id}/issues", params=query_params
)
return PaginatedWorkItemResponse.model_validate(response)
def search(
self,
workspace_slug: str,
query: str,
params: RetrieveQueryParams | None = None,
) -> WorkItemSearch:
"""Search work items.
Args:
workspace_slug: The workspace slug identifier
query: Search query string
params: Optional query parameters for expand, fields, etc.
"""
search_params = {"q": query}
if params:
search_params.update(params.model_dump(exclude_none=True))
response = self._get(f"{workspace_slug}/issues/search", params=search_params)
return WorkItemSearch.model_validate(response)