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

Add relations to issues #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions src/linear/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ class Comment:
user_name: str


@dataclass
class IssueRelation:
id: str
type: str

@staticmethod
def from_gql(relation: dict) -> "IssueRelation":
return IssueRelation(
id=relation["id"],
type=relation["type"],
)


@dataclass
class Issue:
id: str
Expand All @@ -61,6 +74,7 @@ class Issue:
children: list["Issue"]
comments: Optional[list["Comment"]]
assignee: Optional["User"] = None
relations: Optional[list[IssueRelation]] = None

@staticmethod
def gql_fields(include_children=False) -> str:
Expand Down Expand Up @@ -102,6 +116,12 @@ def gql_fields(include_children=False) -> str:
}
}
}
relations {
nodes {
id
type
}
}
%s
""" % (
children_query
Expand Down Expand Up @@ -137,6 +157,10 @@ def from_gql(issue: dict) -> "Issue":
)
for comment in issue.get("comments", {}).get("nodes", [])
],
relations=[
IssueRelation.from_gql(relation)
for relation in issue.get("relations", {}).get("nodes", [])
],
assignee=User.from_gql(issue["assignee"]) if has_assignee else None,
)

Expand Down