Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: external links support #30

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions examples/get_test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ async def main() -> None:
await client.get_attachments_list('TRACKER-1')
await client.get_issue_comments('TRACKER-1')
await client.get_projects_list(expand='queues')
await client.get_external_applications()
await client.get_external_links("TRACKER-1")

await client.stop()

Expand Down
8 changes: 8 additions & 0 deletions ya_tracker_client/domain/entities/external_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ya_tracker_client.domain.entities.base import AbstractEntity


class ExternalApplication(AbstractEntity):
url: str
id: str
type: str
name: str
20 changes: 20 additions & 0 deletions ya_tracker_client/domain/entities/external_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from datetime import datetime

from pydantic import Field

from ya_tracker_client.domain.entities.base import AbstractEntity
from ya_tracker_client.domain.entities.external_object import ExternalObject
from ya_tracker_client.domain.entities.issue_relationship import IssueRelationshipType
from ya_tracker_client.domain.entities.user import UserShort


class ExternalLink(AbstractEntity):
url: str
id: int
type: IssueRelationshipType
direction: str = Field(examples=["outward", "inward"])
object: ExternalObject
created_by: UserShort
updated_by: UserShort
created_at: datetime
updated_at: datetime
9 changes: 9 additions & 0 deletions ya_tracker_client/domain/entities/external_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ya_tracker_client.domain.entities.base import AbstractEntity
from ya_tracker_client.domain.entities.external_application import ExternalApplication


class ExternalObject(AbstractEntity):
url: str
id: str
key: str
application: ExternalApplication
10 changes: 10 additions & 0 deletions ya_tracker_client/domain/repositories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from ya_tracker_client.domain.repositories.attachment import AttachmentRepository
from ya_tracker_client.domain.repositories.bulk_operation import BulkOperationRepository
from ya_tracker_client.domain.repositories.checklist import ChecklistRepository
from ya_tracker_client.domain.repositories.comment import CommentRepository
from ya_tracker_client.domain.repositories.component import ComponentRepository
from ya_tracker_client.domain.repositories.external_link import ExternalLinkRepository
from ya_tracker_client.domain.repositories.importing import ImportingRepository
from ya_tracker_client.domain.repositories.issue import IssueRepository
from ya_tracker_client.domain.repositories.issue_field import IssueFieldRepository
from ya_tracker_client.domain.repositories.issue_relationship import IssueRelationshipRepository
from ya_tracker_client.domain.repositories.macros import MacrosRepository
from ya_tracker_client.domain.repositories.project import ProjectRepository
from ya_tracker_client.domain.repositories.queue import QueueRepository
from ya_tracker_client.domain.repositories.user import UserRepository
Expand All @@ -12,11 +17,16 @@

__all__ = [
"AttachmentRepository",
"BulkOperationRepository",
"ChecklistRepository",
"CommentRepository",
"ComponentRepository",
"ExternalLinkRepository",
"ImportingRepository",
"IssueFieldRepository",
"IssueRelationshipRepository",
"IssueRepository",
"MacrosRepository",
"ProjectRepository",
"QueueRepository",
"UserRepository",
Expand Down
5 changes: 5 additions & 0 deletions ya_tracker_client/domain/repositories/board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ya_tracker_client.domain.repositories.base import EntityRepository


class BoardRepository(EntityRepository):
...
5 changes: 5 additions & 0 deletions ya_tracker_client/domain/repositories/bulk_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ya_tracker_client.domain.repositories.base import EntityRepository


class BulkOperationRepository(EntityRepository):
...
57 changes: 57 additions & 0 deletions ya_tracker_client/domain/repositories/external_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from ya_tracker_client.domain.entities.external_application import ExternalApplication
from ya_tracker_client.domain.entities.external_link import ExternalLink
from ya_tracker_client.domain.repositories.base import EntityRepository


class ExternalLinkRepository(EntityRepository):
async def get_external_applications(self) -> list[ExternalApplication]:
"""
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-applications
"""
raw_response = await self._client.request(
method="GET",
uri="/applications",
)
return self._decode(raw_response, ExternalApplication, plural=True)

async def get_external_links(self, issue_id: str) -> list[ExternalLink]:
"""
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/get-external-links
"""
raw_response = await self._client.request(
method="GET",
uri=f"/issues/{issue_id}/remotelinks",
)
return self._decode(raw_response, ExternalLink, plural=True)

async def add_external_link(
self,
issue_id: str,
key: str,
origin: str,
relationship: str = "RELATES",
backlink: bool | None = None,
) -> ExternalLink:
"""
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/add-external-link
"""
raw_response = await self._client.request(
method="POST",
uri=f"/issues/{issue_id}/remotelinks",
payload={
"key": key,
"origin": origin,
"relationship": relationship,
},
params={"backlink": backlink} if backlink is not None else None,
)
return self._decode(raw_response, ExternalLink)

async def delete_external_link(self, issue_id: str, external_link_id: str | int) -> None:
"""
YC docs: https://cloud.yandex.com/en/docs/tracker/concepts/issues/delete-external-link
"""
await self._client.request(
method="DELETE",
uri=f"/issues/{issue_id}/remotelinks/{external_link_id}",
)
5 changes: 5 additions & 0 deletions ya_tracker_client/domain/repositories/importing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ya_tracker_client.domain.repositories.base import EntityRepository


class ImportingRepository(EntityRepository):
...
5 changes: 5 additions & 0 deletions ya_tracker_client/domain/repositories/issue_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ya_tracker_client.domain.repositories.base import EntityRepository


class IssueFieldRepository(EntityRepository):
...
5 changes: 5 additions & 0 deletions ya_tracker_client/domain/repositories/macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ya_tracker_client.domain.repositories.base import EntityRepository


class MacrosRepository(EntityRepository):
...
14 changes: 12 additions & 2 deletions ya_tracker_client/service/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from ya_tracker_client.domain.repositories import (
AttachmentRepository,
BulkOperationRepository,
ChecklistRepository,
CommentRepository,
ComponentRepository,
ExternalLinkRepository,
ImportingRepository,
IssueFieldRepository,
IssueRelationshipRepository,
IssueRepository,
MacrosRepository,
ProjectRepository,
QueueRepository,
UserRepository,
Expand All @@ -15,15 +20,20 @@

class YaTrackerClient(
AttachmentRepository,
CommentRepository,
BulkOperationRepository,
ChecklistRepository,
CommentRepository,
ComponentRepository,
ExternalLinkRepository,
ImportingRepository,
IssueFieldRepository,
IssueRelationshipRepository,
IssueRepository,
MacrosRepository,
ProjectRepository,
QueueRepository,
UserRepository,
WorklogRepository,
ProjectRepository,
):
def __init__(
self,
Expand Down
Loading