diff options
Diffstat (limited to 'kodereviewer/network_manager.py')
-rw-r--r-- | kodereviewer/network_manager.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/kodereviewer/network_manager.py b/kodereviewer/network_manager.py index 2d8b8aa..62b6047 100644 --- a/kodereviewer/network_manager.py +++ b/kodereviewer/network_manager.py @@ -1,3 +1,4 @@ +import re from typing import Optional from PySide6.QtCore import QObject, QSettings, Signal, Slot, Property, qDebug @@ -9,6 +10,10 @@ from kodereviewer.project import Project QML_IMPORT_NAME = "org.deprecated.kodereviewer" QML_IMPORT_MAJOR_VERSION = 1 +PULL_REQUEST_LIST_URL = re.compile(r'/pulls$') +COMMENT_LIST_URL = re.compile(r'/issues/(\d+)/comments') + + @QmlElement class NetworkManager(QObject): @@ -51,8 +56,26 @@ class NetworkManager(QObject): project = Property(Project, fget=project, fset=set_project) def reply_finished(self, reply: QNetworkReply): - self._project.load_pull_requests(reply.readAll()) + if self._project is None: + print('Project not set') + return + + response_body = reply.readAll() + + if PULL_REQUEST_LIST_URL.search(reply.url().toString()): + self._project.load_pull_requests(response_body) + elif (match := COMMENT_LIST_URL.search(reply.url().toString())): + pull_request_number = int(match.groups()[0]) + pull_request = self._project.find_pull_request(pull_request_number) + if pull_request is not None: + pull_request.load_comments(response_body) + else: + print(f"Can't handle {reply.url()}") @Slot() def getPullRequests(self) -> None: self._manager.get(self._request_factory.createRequest("/pulls")) + + @Slot(int) + def getPullRequestComments(self, number: int) -> None: + self._manager.get(self._request_factory.createRequest(f'/issues/{number}/comments')) |