From e9c7736ff83b9003eba960edebd2653bd5a4021f Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Fri, 4 Oct 2024 18:30:17 -0300 Subject: Fix a lot of warnings and add file view --- kodereviewer/data.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'kodereviewer/data.py') diff --git a/kodereviewer/data.py b/kodereviewer/data.py index 82aad94..0d1bef6 100644 --- a/kodereviewer/data.py +++ b/kodereviewer/data.py @@ -49,6 +49,44 @@ class Comment(QObject): self.user = User(data['user']) +class ChangedFileStatus(Enum): + ADDED = 'added' + MODIFIED = 'modified' + DELETED = 'deleted' + + +class ChangedFile(QObject): + """ { + "sha": "bbcd538c8e72b8c175046e27cc8f907076331401", + "filename": "file1.txt", + "status": "added", + "additions": 103, + "deletions": 21, + "changes": 124, + "blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt", + "raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e", + "patch": "@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test" + }""" + + sha: str + filename: str + status: ChangedFileStatus + additions: int + deletions: int + changes: int + patch: str + + def __init__(self, data: dict[str, Any]): + self.sha = data['sha'] + self.filename = data['filename'] + self.status = data['status'] + self.additions = int(data['additions']) + self.deletions = int(data['deletions']) + self.changes = int(data['changes']) + self.patch = data.get('patch', '') + + class State(Enum): OPEN = 'open' CLOSED = 'closed' @@ -71,10 +109,12 @@ class PullRequest(QObject): _labels: list[Label] _comments: list[Comment] + _files: list[ChangedFile] _initial_data: dict[str, Any] commentsLoaded = Signal() + filesLoaded = Signal() def __init__(self, data: dict[str, Any], *args, **kwargs): super().__init__(*args, **kwargs) @@ -96,6 +136,7 @@ class PullRequest(QObject): # At first this is empty until it's updated with a request self._comments = [] + self._files = [] self._initial_data = data @@ -145,12 +186,20 @@ class PullRequest(QObject): def labels(self) -> list[Label]: return self._labels + @Property(list, constant=True) + def files(self) -> list[ChangedFile]: + return self._files + def load_comments(self, response: QByteArray) -> None: - print("loading comments") data = json.loads(response.toStdString()) self._comments = [Comment(comment) for comment in data] self.commentsLoaded.emit() + def load_files(self, response: QByteArray) -> None: + data = json.loads(response.toStdString()) + self._files = [ChangedFile(file) for file in data] + self.filesLoaded.emit() + def copy(self): """Create a copy of a PullRequest with it's initial parameters.""" return PullRequest(deepcopy(self._initial_data)) -- cgit v1.2.3-70-g09d2