-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathepics.py
More file actions
143 lines (125 loc) · 4.61 KB
/
epics.py
File metadata and controls
143 lines (125 loc) · 4.61 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
from __future__ import annotations
from typing import Any
from ..models.epics import (
AddEpicWorkItems,
CreateEpic,
Epic,
EpicIssue,
PaginatedEpicIssueResponse,
PaginatedEpicResponse,
UpdateEpic,
)
from ..models.query_params import PaginatedQueryParams, RetrieveQueryParams
from .base_resource import BaseResource
class Epics(BaseResource):
def __init__(self, config: Any) -> None:
super().__init__(config, "/workspaces/")
def create(self, workspace_slug: str, project_id: str, data: CreateEpic) -> Epic:
"""Create a new epic in a project.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
data: Epic creation data
"""
# enable epics feature flag
response = self._post(
f"{workspace_slug}/projects/{project_id}/epics",
data.model_dump(exclude_none=True),
)
return Epic.model_validate(response)
def retrieve(
self,
workspace_slug: str,
project_id: str,
epic_id: str,
params: RetrieveQueryParams | None = None,
) -> Epic:
"""Retrieve an epic by ID.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
epic_id: UUID of the epic
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}/projects/{project_id}/epics/{epic_id}", params=query_params
)
return Epic.model_validate(response)
def update(
self, workspace_slug: str, project_id: str, epic_id: str, data: UpdateEpic
) -> Epic:
"""Partially update an existing epic.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
epic_id: UUID of the epic
data: Epic update data
"""
response = self._patch(
f"{workspace_slug}/projects/{project_id}/epics/{epic_id}",
data.model_dump(exclude_none=True),
)
return Epic.model_validate(response)
def delete(self, workspace_slug: str, project_id: str, epic_id: str) -> None:
"""Delete an epic.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
epic_id: UUID of the epic
"""
self._delete(f"{workspace_slug}/projects/{project_id}/epics/{epic_id}")
def list(
self,
workspace_slug: str,
project_id: str,
params: PaginatedQueryParams | None = None,
) -> PaginatedEpicResponse:
"""List epics in a project.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
params: Optional query parameters for filtering, ordering, and pagination
"""
query_params = params.model_dump(exclude_none=True) if params else None
response = self._get(f"{workspace_slug}/projects/{project_id}/epics", params=query_params)
return PaginatedEpicResponse.model_validate(response)
def list_issues(
self,
workspace_slug: str,
project_id: str,
epic_id: str,
params: PaginatedQueryParams | None = None,
) -> PaginatedEpicIssueResponse:
"""List work items under an epic.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
epic_id: UUID of the epic
params: Optional query parameters for pagination
"""
query_params = params.model_dump(exclude_none=True) if params else None
response = self._get(
f"{workspace_slug}/projects/{project_id}/epics/{epic_id}/issues",
params=query_params,
)
return PaginatedEpicIssueResponse.model_validate(response)
def add_issues(
self,
workspace_slug: str,
project_id: str,
epic_id: str,
data: AddEpicWorkItems,
) -> list[EpicIssue]:
"""Add work items as sub-issues under an epic.
Args:
workspace_slug: The workspace slug identifier
project_id: UUID of the project
epic_id: UUID of the epic
data: Work item IDs to add
"""
response = self._post(
f"{workspace_slug}/projects/{project_id}/epics/{epic_id}/issues",
data.model_dump(exclude_none=True),
)
return [EpicIssue.model_validate(item) for item in response]