summaryrefslogtreecommitdiff
path: root/kodereviewer/review.py
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2024-11-04 09:31:26 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2024-11-24 11:21:41 -0300
commit2ef76e8acee23c344335b0118aadd5de96a7dfff (patch)
tree1eb1fa059ddf07d00834f569611f1ca2e33a961a /kodereviewer/review.py
parent45f03bfb30ea29dd62c0aba3fbe0c002dcdc807a (diff)
downloadkodereviewer-main.tar.gz
[WIP] Add review functionalitytranslationsmain
Diffstat (limited to 'kodereviewer/review.py')
-rw-r--r--kodereviewer/review.py91
1 files changed, 91 insertions, 0 deletions
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}')
+