summaryrefslogtreecommitdiff
path: root/kodereviewer/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'kodereviewer/data.py')
-rw-r--r--kodereviewer/data.py96
1 files changed, 82 insertions, 14 deletions
diff --git a/kodereviewer/data.py b/kodereviewer/data.py
index 61f1a01..1598e9d 100644
--- a/kodereviewer/data.py
+++ b/kodereviewer/data.py
@@ -10,13 +10,22 @@ from PySide6.QtQml import QmlElement
class User(QObject):
- username: str
- avatar_url: str
+
+ _username: str
+ _avatar_url: str
def __init__(self, data: dict[str, Any]):
super().__init__()
- self.username = data['login']
- self.avatar_url = data['avatar_url']
+ self._username = data['login']
+ self._avatar_url = data['avatar_url']
+
+ @Property(str, constant=True)
+ def username(self) -> str:
+ return self._username
+
+ @Property(str, constant=True)
+ def avatarUrl(self) -> str:
+ return self._avatar_url
class Label(QObject):
@@ -32,21 +41,68 @@ class Label(QObject):
class Comment(QObject):
- body: str
- reactions: dict[str, int]
+ _body: str
+ _reactions: dict[str, int]
- created_at: datetime
- updated_at: datetime
+ _created_at: datetime
+ _updated_at: datetime
- user: User
+ _user: User
def __init__(self, data: dict[str, Any]):
super().__init__()
- self.body = data['body']
- self.reactions = data['reactions']
- self.created_at = datetime.fromisoformat(data['created_at'])
- self.updated_at = datetime.fromisoformat(data['updated_at'])
- self.user = User(data['user'])
+ self._body = data['body']
+ self._reactions = data['reactions']
+ self._created_at = datetime.fromisoformat(data['created_at'])
+ self._updated_at = datetime.fromisoformat(data['updated_at'])
+ self._user = User(data['user'])
+
+ @Property(str, constant=True)
+ def body(self) -> str:
+ return self._body
+
+ @Property(datetime, constant=True)
+ def created_at(self) -> datetime:
+ return self._created_at
+
+ @Property(datetime, constant=True)
+ def updated_at(self) -> datetime:
+ return self._updated_at
+
+ @Property(User, constant=True)
+ def user(self) -> User:
+ return self._user
+
+
+class ReviewComment(Comment):
+ _id: int
+ _in_reply_to: int | None
+ _diff: str
+ _line: int
+ def __init__(self, data: dict[str, Any]):
+ super().__init__(data)
+ self._id = data['id']
+ self._in_reply_to = data.get('in_reply_to_id')
+ self._diff = data['diff_hunk']
+ self._line = data['line']
+
+ @Property(int, constant=True)
+ def id(self) -> int:
+ return self._id
+
+ @Property(int, constant=True)
+ def in_reply_to(self) -> int:
+ if self._in_reply_to is None:
+ return 0
+ return self._in_reply_to
+
+ @Property(str, constant=True)
+ def diff(self) -> str:
+ return self._diff
+
+ @Property(int, constant=True)
+ def line(self) -> int:
+ return self._line
class ChangedFileStatus(Enum):
@@ -112,12 +168,14 @@ class PullRequest(QObject):
_last_commit: str
_comments: list[Comment]
+ _reviews: list[ReviewComment]
_files: list[ChangedFile]
_initial_data: dict[str, Any]
commentsLoaded = Signal()
filesLoaded = Signal()
+ reviewsLoaded = Signal()
def __init__(self, data: dict[str, Any], *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -146,6 +204,7 @@ class PullRequest(QObject):
# At first this is empty until it's updated with a request
self._comments = []
self._files = []
+ self._reviews = []
self._initial_data = data
@@ -207,6 +266,10 @@ class PullRequest(QObject):
def files(self) -> list[ChangedFile]:
return self._files
+ @Property(list, constant=True)
+ def reviews(self) -> list[ReviewComment]:
+ return self._reviews
+
def load_comments(self, response: QByteArray) -> None:
data = json.loads(response.toStdString())
self._comments = [Comment(comment) for comment in data]
@@ -217,6 +280,11 @@ class PullRequest(QObject):
self._files = [ChangedFile(file) for file in data]
self.filesLoaded.emit()
+ def load_reviews(self, response: QByteArray) -> None:
+ data = json.loads(response.toStdString())
+ self._reviews = [ReviewComment(review) for review in data]
+ self.reviewsLoaded.emit()
+
def copy(self):
"""Create a copy of a PullRequest with it's initial parameters."""
return PullRequest(deepcopy(self._initial_data))