|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from ..models.work_item_relation_definitions import ( |
| 4 | + CreateWorkItemRelationDefinition, |
| 5 | + UpdateWorkItemRelationDefinition, |
| 6 | + WorkItemRelationDefinition, |
| 7 | +) |
| 8 | +from .base_resource import BaseResource |
| 9 | + |
| 10 | + |
| 11 | +class WorkItemRelationDefinitions(BaseResource): |
| 12 | + """API client for managing workspace-level work item relation definitions.""" |
| 13 | + |
| 14 | + def __init__(self, config: Any) -> None: |
| 15 | + super().__init__(config, "/workspaces/") |
| 16 | + |
| 17 | + def list( |
| 18 | + self, |
| 19 | + workspace_slug: str, |
| 20 | + is_default: bool | None = None, |
| 21 | + is_active: bool | None = None, |
| 22 | + ) -> list[WorkItemRelationDefinition]: |
| 23 | + """List all work item relation definitions in the workspace. |
| 24 | +
|
| 25 | + Args: |
| 26 | + workspace_slug: The workspace slug identifier |
| 27 | + is_default: Optional filter by default status |
| 28 | + is_active: Optional filter by active status |
| 29 | + """ |
| 30 | + params: dict[str, Any] = {} |
| 31 | + if is_default is not None: |
| 32 | + params["is_default"] = str(is_default).lower() |
| 33 | + if is_active is not None: |
| 34 | + params["is_active"] = str(is_active).lower() |
| 35 | + |
| 36 | + response = self._get( |
| 37 | + f"{workspace_slug}/work-item-relation-definitions/", |
| 38 | + params=params if params else None, |
| 39 | + ) |
| 40 | + return [WorkItemRelationDefinition.model_validate(item) for item in response] |
| 41 | + |
| 42 | + def create( |
| 43 | + self, workspace_slug: str, data: CreateWorkItemRelationDefinition |
| 44 | + ) -> WorkItemRelationDefinition: |
| 45 | + """Create a new work item relation definition in the workspace. |
| 46 | +
|
| 47 | + Args: |
| 48 | + workspace_slug: The workspace slug identifier |
| 49 | + data: Relation definition data |
| 50 | + """ |
| 51 | + response = self._post( |
| 52 | + f"{workspace_slug}/work-item-relation-definitions/", |
| 53 | + data.model_dump(exclude_none=True), |
| 54 | + ) |
| 55 | + return WorkItemRelationDefinition.model_validate(response) |
| 56 | + |
| 57 | + def update( |
| 58 | + self, |
| 59 | + workspace_slug: str, |
| 60 | + definition_id: str, |
| 61 | + data: UpdateWorkItemRelationDefinition, |
| 62 | + ) -> WorkItemRelationDefinition: |
| 63 | + """Update a work item relation definition in the workspace. |
| 64 | +
|
| 65 | + Args: |
| 66 | + workspace_slug: The workspace slug identifier |
| 67 | + definition_id: UUID of the relation definition |
| 68 | + data: Updated relation definition data |
| 69 | + """ |
| 70 | + response = self._patch( |
| 71 | + f"{workspace_slug}/work-item-relation-definitions/{definition_id}/", |
| 72 | + data.model_dump(exclude_none=True), |
| 73 | + ) |
| 74 | + return WorkItemRelationDefinition.model_validate(response) |
| 75 | + |
| 76 | + def delete(self, workspace_slug: str, definition_id: str) -> None: |
| 77 | + """Delete a work item relation definition in the workspace. |
| 78 | +
|
| 79 | + Args: |
| 80 | + workspace_slug: The workspace slug identifier |
| 81 | + definition_id: UUID of the relation definition |
| 82 | + """ |
| 83 | + return self._delete( |
| 84 | + f"{workspace_slug}/work-item-relation-definitions/{definition_id}/" |
| 85 | + ) |
0 commit comments