From 2ef76e8acee23c344335b0118aadd5de96a7dfff Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 4 Nov 2024 09:31:26 -0300 Subject: [WIP] Add review functionality --- kodereviewer/review.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 kodereviewer/review.py (limited to 'kodereviewer/review.py') diff --git a/kodereviewer/review.py b/kodereviewer/review.py new file mode 100644 index 0000000..b55b149 --- /dev/null +++ b/kodereviewer/review.py @@ -0,0 +1,91 @@ + +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}') + -- cgit v1.2.3-70-g09d2