Skip to content

Commit

Permalink
Add relations to issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kaar committed May 2, 2024
1 parent 6818b4b commit 128a728
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 128a728

Please sign in to comment.