summaryrefslogtreecommitdiff
path: root/kodereviewer/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'kodereviewer/data.py')
-rw-r--r--kodereviewer/data.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/kodereviewer/data.py b/kodereviewer/data.py
index eb86097..82aad94 100644
--- a/kodereviewer/data.py
+++ b/kodereviewer/data.py
@@ -1,3 +1,4 @@
+from copy import deepcopy
from datetime import datetime
from enum import Enum
import json
@@ -63,6 +64,7 @@ class PullRequest(QObject):
_body: str | None
_created_at: datetime
_updated_at: datetime
+ _draft: bool
_user: User
_assignee: User | None
@@ -70,10 +72,12 @@ class PullRequest(QObject):
_comments: list[Comment]
+ _initial_data: dict[str, Any]
+
commentsLoaded = Signal()
- def __init__(self, data: dict[str, Any]):
- super().__init__()
+ def __init__(self, data: dict[str, Any], *args, **kwargs):
+ super().__init__(*args, **kwargs)
self._number = data['number']
self._state = data['state']
self._title = data['title']
@@ -81,6 +85,7 @@ class PullRequest(QObject):
self._body = data['body']
self._created_at = datetime.fromisoformat(data['created_at'])
self._updated_at = datetime.fromisoformat(data['updated_at'])
+ self._draft = data['draft']
self._user = User(data['user'])
self._assignee = None
@@ -92,6 +97,8 @@ class PullRequest(QObject):
# At first this is empty until it's updated with a request
self._comments = []
+ self._initial_data = data
+
def __eq__(self, other: object) -> bool:
if isinstance(other, PullRequest):
return self._number == other._number
@@ -110,7 +117,7 @@ class PullRequest(QObject):
@Property(str, constant=True)
def state(self) -> str:
- return self._state.value
+ return self._state
@Property(str, constant=True)
def url(self) -> str:
@@ -126,12 +133,24 @@ class PullRequest(QObject):
def created_at(self) -> datetime:
return self._created_at
+ @Property(bool, constant=True)
+ def draft(self) -> bool:
+ return self._draft
+
@Property(str, constant=True)
def username(self) -> str:
return self._user.username
+ @Property(list, constant=True)
+ def labels(self) -> list[Label]:
+ return self._labels
+
def load_comments(self, response: QByteArray) -> None:
+ print("loading comments")
data = json.loads(response.toStdString())
self._comments = [Comment(comment) for comment in data]
- print(f'emiting new comments {len(self._comments)}')
self.commentsLoaded.emit()
+
+ def copy(self):
+ """Create a copy of a PullRequest with it's initial parameters."""
+ return PullRequest(deepcopy(self._initial_data))