Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
113 changes: 113 additions & 0 deletions crowdin_api/api_resources/tasks/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
TaskSettingsTemplateLanguages,
)
from crowdin_api.sorting import Sorting
from crowdin_api.api_resources.tasks.types import TaskCommentPatchRequest


class TasksResource(BaseResource):
Expand Down Expand Up @@ -934,6 +935,118 @@ def list_user_tasks(

return self._get_entire_data(method="get", path="user/tasks", params=params)

# Task Comments
def get_task_comments_path(
self,
projectId: int,
taskId: int,
taskCommentId: Optional[int] = None,
):
if taskCommentId is not None:
return f"projects/{projectId}/tasks/{taskId}/comments/{taskCommentId}"

return f"projects/{projectId}/tasks/{taskId}/comments"

def list_task_comments(
self,
taskId: int,
projectId: Optional[int] = None,
orderBy: Optional[Sorting] = None,
page: Optional[int] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
):
"""
List Task Comments.
"""
Comment thread
andrii-bodnar marked this conversation as resolved.

projectId = projectId or self.get_project_id()
params = {"orderBy": orderBy}
params.update(self.get_page_params(page=page, offset=offset, limit=limit))

return self._get_entire_data(
method="get",
path=self.get_task_comments_path(projectId=projectId, taskId=taskId),
params=params,
)

def add_task_comment(
self,
text: str,
taskId: int,
projectId: Optional[int] = None,
):
"""
Add Task Comment.
"""

projectId = projectId or self.get_project_id()

return self.requester.request(
method="post",
path=self.get_task_comments_path(projectId=projectId, taskId=taskId),
request_data={"text": text},
)

def get_task_comment(
self,
taskCommentId: int,
taskId: int,
projectId: Optional[int] = None,
):
"""
Get Task Comment.
"""

projectId = projectId or self.get_project_id()

return self.requester.request(
method="get",
path=self.get_task_comments_path(
projectId=projectId, taskId=taskId, taskCommentId=taskCommentId
),
)

def delete_task_comment(
self,
taskCommentId: int,
taskId: int,
projectId: Optional[int] = None,
):
"""
Delete Task Comment.
"""

projectId = projectId or self.get_project_id()

return self.requester.request(
method="delete",
path=self.get_task_comments_path(
projectId=projectId, taskId=taskId, taskCommentId=taskCommentId
),
)

def edit_task_comment(
self,
taskCommentId: int,
data: Iterable[TaskCommentPatchRequest],
taskId: int,
projectId: Optional[int] = None,
):
"""
Edit Task Comment.
"""

projectId = projectId or self.get_project_id()

return self.requester.request(
method="patch",
path=self.get_task_comments_path(
projectId=projectId, taskId=taskId, taskCommentId=taskCommentId
),
request_data=data,
)

def edit_task_archived_status(
self, taskId: int, isArchived: bool = True, projectId: Optional[int] = None
):
Expand Down
8 changes: 8 additions & 0 deletions crowdin_api/api_resources/tasks/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ class EnterpriseTaskSettingsTemplateConfigLanguage(TypedDict):

class EnterpriseTaskSettingsTemplateLanguages(TypedDict):
languages: Iterable[EnterpriseTaskSettingsTemplateConfigLanguage]


# Task comments patch request (moved from removed task_comments package)
class TaskCommentPatchRequest(TypedDict):
value: Any
op: PatchOperation
# For now only /text is supported in edit operations
path: str