-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import Field | ||
|
||
from ya_tracker_client.domain.entities.base import AbstractEntity | ||
from ya_tracker_client.domain.entities.mailing_list import MailingList | ||
from ya_tracker_client.domain.entities.user import UserShort | ||
|
||
|
||
class Comment(AbstractEntity): | ||
url: str | ||
id: int | ||
long_id: str | ||
text: str | ||
created_by: UserShort | ||
created_at: datetime | ||
updated_by: UserShort | ||
updated_at: datetime | ||
summonees: list[UserShort] = Field(default_factory=list) | ||
maillistsummonees: list[MailingList] = Field(default_factory=list) | ||
version: int | ||
type: str = Field(examples=["standard", "incoming", "outcoming"]) | ||
transport: str = Field(examples=["internal", "email"]) | ||
|
||
|
||
class CommentCreate(AbstractEntity): | ||
text: str | ||
attachment_ids: list[str] | None = None | ||
summonees: list[UserShort | str] | None = None | ||
maillistsummonees: list[str] | None = None | ||
|
||
|
||
class CommentEdit(AbstractEntity): | ||
text: str | ||
attachment_ids: list[str] | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from ya_tracker_client.domain.entities.base import AbstractEntity | ||
|
||
|
||
class MailingList(AbstractEntity): | ||
url: str | ||
id: str | ||
display: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from ya_tracker_client.domain.entities.comment import Comment, CommentCreate, CommentEdit | ||
from ya_tracker_client.domain.entities.user import UserShort | ||
from ya_tracker_client.domain.repositories.base import EntityRepository | ||
|
||
|
||
class CommentRepository(EntityRepository): | ||
async def add_comment( | ||
self, | ||
issue_id: str, | ||
text: str, | ||
attachment_ids: list[str] | None = None, | ||
summonees: list[str | UserShort] | None = None, | ||
maillist_summonees: list[str] | None = None, | ||
is_add_to_followers: bool | None = None, | ||
) -> Comment: | ||
""" | ||
Use this method to add a comment to an issue. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/add-comment | ||
""" | ||
raw_response = await self._client.request( | ||
method="POST", | ||
uri=f"/issues/{issue_id}/comments", | ||
payload=CommentCreate( | ||
text=text, | ||
attachment_ids=attachment_ids, | ||
summonees=summonees, | ||
maillist_summonees=maillist_summonees, | ||
).model_dump(exclude_none=True, by_alias=True), | ||
params={"is_add_to_followers": is_add_to_followers} if is_add_to_followers is not None else None, | ||
) | ||
return self._decode(raw_response, Comment) | ||
|
||
async def get_issue_comments(self, issue_id: str) -> list[Comment]: | ||
""" | ||
Use this method to get a list of comments on an issue. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-comments | ||
""" | ||
raw_response = await self._client.request( | ||
method="GET", | ||
uri=f"/issues/{issue_id}/comments", | ||
) | ||
return self._decode(raw_response, Comment, plural=True) | ||
|
||
async def edit_comment( | ||
self, | ||
issue_id: str, | ||
comment_id: str | int, | ||
text: str, | ||
attachment_ids: list[str] | None = None, | ||
) -> Comment: | ||
""" | ||
Use this method to edit comments. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/edit-comment | ||
""" | ||
raw_response = await self._client.request( | ||
method="PATCH", | ||
uri=f"/issues/{issue_id}/comments/{comment_id}", | ||
payload=CommentEdit( | ||
text=text, | ||
attachment_ids=attachment_ids, | ||
).model_dump(exclude_none=True, by_alias=True), | ||
) | ||
return self._decode(raw_response, Comment) | ||
|
||
async def delete_comment( | ||
self, | ||
issue_id: str, | ||
comment_id: str | int, | ||
) -> None: | ||
""" | ||
Use this method to delete issue comments. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/delete-comment | ||
""" | ||
await self._client.request( | ||
method="DELETE", | ||
uri=f"/issues/{issue_id}/comments/{comment_id}", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters