diff options
Diffstat (limited to 'kodereviewer/network_manager.py')
-rw-r--r-- | kodereviewer/network_manager.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/kodereviewer/network_manager.py b/kodereviewer/network_manager.py index ebc2797..3296153 100644 --- a/kodereviewer/network_manager.py +++ b/kodereviewer/network_manager.py @@ -1,4 +1,7 @@ +import json +import logging import re +from enum import StrEnum from typing import Optional from PySide6.QtCore import QObject, QSettings, Signal, Slot, Property, qDebug @@ -14,6 +17,15 @@ QML_IMPORT_MAJOR_VERSION = 1 PULL_REQUEST_LIST_URL = re.compile(r'/pulls$') COMMENT_LIST_URL = re.compile(r'/issues/(\d+)/comments') FILE_LIST_URL = re.compile(r'/pulls/(\d+)/files') +CREATE_REVIEW_URL = re.compile(r'/pulls/(\d+)/reviews') + +logger = logging.getLogger(__name__) + + +class ReviewEvent(StrEnum): + APPROVE = 'APPROVE' + REQUEST_CHANGES = 'REQUEST_CHANGES' + COMMENT = 'COMMENT' @QmlElement @@ -76,8 +88,10 @@ class NetworkManager(QObject): pull_request: Optional[PullRequest] = self._project.find_pull_request(pull_request_number) if pull_request is not None: pull_request.load_files(response_body) + elif (match := CREATE_REVIEW_URL.search(reply.url().toString())): + logger.info(f'Got review reply: {response_body}') else: - print(f"Can't handle {reply.url()}") + logger.info(f"Can't handle {reply.url()}") @Slot() def getPullRequests(self) -> None: @@ -85,8 +99,30 @@ class NetworkManager(QObject): @Slot(int) def getPullRequestComments(self, number: int) -> None: - self._manager.get(self._request_factory.createRequest(f'/issues/{number}/comments')) + self._manager.get( + self._request_factory.createRequest(f'/issues/{number}/comments') + ) @Slot(int) def getFiles(self, pull_request_number) -> None: - self._manager.get(self._request_factory.createRequest(f'/pulls/{pull_request_number}/files')) + self._manager.get( + self._request_factory.createRequest( + f'/pulls/{pull_request_number}/files' + ) + ) + + @Slot(int, str, str, str) + def createReview( + self, pull_request_number: str, commit_id: str, + body: str, event: ReviewEvent + ) -> None: + request = self._request_factory.createRequest( + f'/pulls/{pull_request_number}/reviews' + ) + data = { + 'commit_id': commit_id, + 'body': body, + 'event': event, + 'comments': [] + } + self._manager.post(request, json.dumps(data).encode()) |