-
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
16 changed files
with
211 additions
and
43 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,39 @@ | ||
import os | ||
from asyncio import run | ||
|
||
from dotenv import load_dotenv | ||
|
||
from ya_tracker_client import YaTrackerClient | ||
|
||
|
||
load_dotenv() | ||
# from registered application at Yandex OAuth - https://oauth.yandex.ru/ | ||
API_TOKEN = os.getenv("API_TOKEN") | ||
# from admin panel at Yandex Tracker - https://tracker.yandex.ru/admin/orgs | ||
API_ORGANISATION_ID = os.getenv("API_ORGANISATION_ID") | ||
|
||
|
||
async def main() -> None: | ||
client = YaTrackerClient( | ||
organisation_id=API_ORGANISATION_ID, | ||
oauth_token=API_TOKEN, | ||
) | ||
|
||
# requests for tests | ||
me = await client.get_myself() | ||
await client.get_user(uid=me.uid) | ||
await client.get_users() | ||
await client.get_issue('TRACKER-1') | ||
await client.get_queue('TRACKER') | ||
await client.get_issue_relationships('TRACKER-1') | ||
await client.get_checklist_items("TRACKER-1") | ||
await client.get_components() | ||
await client.get_worklog("TRACKER-1") | ||
await client.get_worklog_records_by_parameters(me.login) | ||
await client.get_attachments_list('TRACKER-1') | ||
|
||
await client.stop() | ||
|
||
|
||
if __name__ == "__main__": | ||
run(main()) |
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,23 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import Field | ||
|
||
from ya_tracker_client.domain.entities.base import AbstractEntity | ||
from ya_tracker_client.domain.entities.user import UserShort | ||
|
||
|
||
class AttachmentMetadata(AbstractEntity): | ||
size: str | ||
|
||
|
||
class Attachment(AbstractEntity): | ||
url: str | ||
id: int | ||
name: str | ||
content: str | ||
thumbnail: str | None = None | ||
created_by: UserShort | ||
created_at: datetime | ||
mimetype: str = Field(..., examples=["text/plain", "image/png"]) | ||
size: int | ||
metadata: AttachmentMetadata | 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
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,105 @@ | ||
from typing import BinaryIO | ||
|
||
from aiohttp import FormData | ||
|
||
from ya_tracker_client.domain.entities.attachment import Attachment | ||
from ya_tracker_client.domain.repositories.base import EntityRepository | ||
|
||
|
||
class AttachmentRepository(EntityRepository): | ||
async def get_attachments_list(self, issue_id: str) -> list[Attachment]: | ||
""" | ||
Use this request to get a list of files attached to an issue and to comments below it. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-attachments-list | ||
""" | ||
raw_response = await self._client.request( | ||
method="GET", | ||
uri=f"/issues/{issue_id}/attachments", | ||
) | ||
return self._decode(raw_response, Attachment, plural=True) | ||
|
||
async def download_attachment( | ||
self, | ||
issue_id: str, | ||
attachment_id: str | int, | ||
filename: str, | ||
) -> bytes: | ||
""" | ||
Use this request to download files attached to issues. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-attachment | ||
""" | ||
return await self._client.request( | ||
method="GET", | ||
uri=f"/issues/{issue_id}/attachments/{attachment_id}/{filename}", | ||
) | ||
|
||
async def download_thumbnail( | ||
self, | ||
issue_id: str, | ||
attachment_id: str | int, | ||
) -> bytes: | ||
""" | ||
Get thumbnails of image files attached to issues. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-attachment-preview | ||
""" | ||
return await self._client.request( | ||
method="GET", | ||
uri=f"/issues/{issue_id}/thumbnails/{attachment_id}", | ||
) | ||
|
||
async def attach_file( | ||
self, | ||
issue_id: str, | ||
file: BinaryIO, | ||
filename: str | None = None, | ||
) -> Attachment: | ||
""" | ||
Attach a file to an issue. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/post-attachment | ||
""" | ||
form = FormData(fields={"file_data": file}) | ||
raw_response = await self._client.request( | ||
method="POST", | ||
uri=f"/issues/{issue_id}/attachments", | ||
params={"filename": filename} if filename else None, | ||
form=form, | ||
) | ||
return self._decode(raw_response, Attachment) | ||
|
||
async def upload_temp_file( | ||
self, | ||
file: BinaryIO, | ||
filename: str | None = None, | ||
) -> Attachment: | ||
""" | ||
Upload temporary file. | ||
Use this request to upload a file to Tracker first, and then | ||
attach it when creating an issue or adding a comment. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/temp-attachment | ||
""" | ||
form = FormData() | ||
form.add_field("file_data", file) | ||
raw_response = await self._client.request( | ||
method="POST", | ||
uri="/attachments/", | ||
params={"filename": filename} if filename else None, | ||
form=form, | ||
) | ||
return self._decode(raw_response, Attachment) | ||
|
||
async def delete_attachment(self, issue_id: str, attachment_id: str | int) -> None: | ||
""" | ||
Delete attached file. | ||
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/delete-attachment | ||
""" | ||
await self._client.request( | ||
method="DELETE", | ||
uri=f"/issues/{issue_id}/attachments/{attachment_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
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
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
Oops, something went wrong.