import logging from typing import Literal from PySide6.QtCore import Property, QObject, Signal, Slot from kodereviewer.data import PullRequest QML_IMPORT_NAME = "org.deprecated.kodereviewer" QML_IMPORT_MAJOR_VERSION = 1 logger = logging.getLogger(__name__) class Comment(QObject): _path: str _body: str _position: int | None = None _line: int | None = None _side: str | None = None _start_line: int | None = None _end_line: int | None = None def __init__(self, path: str, body: str, position: int | None = None, line: int | None = None, side: str | None = None, start_line: int | None = None, end_line: int | None = None): super().__init__() self._path = path self._body = body self._position = position self._line = line self._side = side self._start_line = start_line self._end_line = end_line class Review(QObject): _pull_request_number: int _commit_id: str _body: str _event: Literal["APPROVE"] | Literal["REQUEST_CHANGES"] | Literal["COMMENT"] | Literal[''] _comments = list[Comment] def __init__(self, pull_request_number, commit_id, body, event = ''): super().__init__() self._pull_request_number = pull_request_number self._commit_id = commit_id self._body = body self._event = event self._comments = [] class ReviewHelper(QObject): _pull_request: PullRequest | None _review: Review | None def __init__(self): super().__init__() self._pull_request = None self._review = None def get_pull_request(self) -> PullRequest | None: return self._pull_request def set_pull_request(self, pull_request: PullRequest | None) -> None: if pull_request is None: return if self._pull_request is not None and self._pull_request == pull_request: return self._pull_request = pull_request self._review = Review(pull_request.number, pull_request._last_commit, '') self.pullRequestChanged.emit() pullRequestChanged = Signal() pullRequest = Property(PullRequest, fget=get_pull_request, fset=set_pull_request, notify=pullRequestChanged) @Slot(str, str, int) def addFileReview(self, path: str, body: str, position: int) -> None: logger.info("Adding review to %s%d: %s", path, position, body) if self._review is None: return comment = Comment(path, body, position=position) self._review._comments.append(comment) logger.info(f'{self._review._comments}')