diff options
author | Matias Linares <matias.linares@comprandoengrupo.net> | 2024-11-04 09:31:26 -0300 |
---|---|---|
committer | Matias Linares <matias.linares@comprandoengrupo.net> | 2024-11-24 11:21:41 -0300 |
commit | 2ef76e8acee23c344335b0118aadd5de96a7dfff (patch) | |
tree | 1eb1fa059ddf07d00834f569611f1ca2e33a961a | |
parent | 45f03bfb30ea29dd62c0aba3fbe0c002dcdc807a (diff) | |
download | kodereviewer-main.tar.gz |
[WIP] Add review functionalitytranslationsmain
-rw-r--r-- | kodereviewer/app.py | 7 | ||||
-rw-r--r-- | kodereviewer/qml/.CommentPage.qml.kate-swp | bin | 0 -> 232 bytes | |||
-rw-r--r-- | kodereviewer/qml/CommentPage.qml | 3 | ||||
-rw-r--r-- | kodereviewer/qml/FilesChangedPage.qml | 48 | ||||
-rw-r--r-- | kodereviewer/qml/Main.qml | 4 | ||||
-rw-r--r-- | kodereviewer/qml/ReviewList.qml | 22 | ||||
-rw-r--r-- | kodereviewer/review.py | 91 |
7 files changed, 169 insertions, 6 deletions
diff --git a/kodereviewer/app.py b/kodereviewer/app.py index bb1080f..e188923 100644 --- a/kodereviewer/app.py +++ b/kodereviewer/app.py @@ -3,13 +3,14 @@ import os import sys import signal -import gettext +import logging from KI18n import KLocalizedContext, KLocalizedString from PySide6.QtGui import QGuiApplication from PySide6.QtCore import QUrl, QByteArray from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType from PySide6.QtQuickControls2 import QQuickStyle +from rich.logging import RichHandler from kodereviewer.data import PullRequest from kodereviewer.models.file import FileModel @@ -18,8 +19,7 @@ from kodereviewer.models import ( CommentModel, TreeFileModel, LabelModel, LineModel, PullRequestModel, ProjectModel, ReviewerModel, ReviewModel ) -import logging -from rich.logging import RichHandler +from kodereviewer.review import ReviewHelper FORMAT = "%(message)s" logging.basicConfig( @@ -64,6 +64,7 @@ def main(): qmlRegisterType(NetworkManager, "org.deprecated.kodereviewer", 1, 0, "NetworkManager") qmlRegisterType(PullRequest, "org.deprecated.kodereviewer", 1, 0, "PullRequest") + qmlRegisterType(ReviewHelper, "org.deprecated.kodereviewer", 1, 0, "ReviewHelper") localized_context = KLocalizedContext() engine.rootContext().setContextObject(localized_context) diff --git a/kodereviewer/qml/.CommentPage.qml.kate-swp b/kodereviewer/qml/.CommentPage.qml.kate-swp Binary files differnew file mode 100644 index 0000000..a72cf10 --- /dev/null +++ b/kodereviewer/qml/.CommentPage.qml.kate-swp diff --git a/kodereviewer/qml/CommentPage.qml b/kodereviewer/qml/CommentPage.qml index 8c297bc..756f5da 100644 --- a/kodereviewer/qml/CommentPage.qml +++ b/kodereviewer/qml/CommentPage.qml @@ -57,6 +57,7 @@ Kirigami.ScrollablePage { delegate: CommentDelegate {} footerPositioning: ListView.InlineFooter footer: Item { + id: rootFooter anchors.left: parent.left anchors.right: parent.right height: footerLayout.implicitHeight @@ -64,6 +65,7 @@ Kirigami.ScrollablePage { id: footerLayout anchors.fill: parent anchors.topMargin: Kirigami.Units.largeSpacing * 2 + MarkdownTextArea { id: newCommentTextArea Layout.fillWidth: true @@ -71,6 +73,7 @@ Kirigami.ScrollablePage { QQC2.Button { icon.name: "document-send-symbolic" enabled: newCommentTextArea.text != '' + Layout.fillHeight: true onClicked: { if (newCommentTextArea.text == '') { diff --git a/kodereviewer/qml/FilesChangedPage.qml b/kodereviewer/qml/FilesChangedPage.qml index 9f55add..fe2aaf6 100644 --- a/kodereviewer/qml/FilesChangedPage.qml +++ b/kodereviewer/qml/FilesChangedPage.qml @@ -21,6 +21,9 @@ Kirigami.ScrollablePage { title: pullRequest ? `#${pullRequest.number}` : "" + property ReviewHelper reviewHelper: applicationWindow().reviewHelper + + property string currentFile: "" property string currentText: "" @@ -49,6 +52,25 @@ Kirigami.ScrollablePage { } ] + Kirigami.Dialog { + id: popup + popupType: QQC2.Popup.Window + focus: true + title: i18n("Add review to " + root.currentFile) + showCloseButton: false + preferredWidth: Kirigami.Units.gridUnit * 20 + preferredHeight: Kirigami.Units.gridUnit * 20 + padding: Kirigami.Units.largeSpacing + MarkdownTextArea { + id: reviewTextArea + } + standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel + + onAccepted: { + root.reviewHelper.addFileReview(root.currentFile, reviewTextArea.text, editor.selectionEndLine()) + } + } + Kirigami.PlaceholderMessage { visible: root.currentFile == '' anchors.centerIn: parent @@ -65,6 +87,32 @@ Kirigami.ScrollablePage { Layout.fillHeight: true file: root.currentFile text: root.currentText + + MouseArea { + anchors.fill: parent + //propagateComposedEvents: true + acceptedButtons: Qt.RightButton + cursorShape: Qt.IBeamCursor + + onClicked: event => { + if (event.button === Qt.RightButton) { // 'mouse' is a MouseEvent argument passed into the onClicked signal handler + editorMenu.popup() + } + } + + QQC2.Menu { + id: editorMenu + QQC2.MenuItem { + text: "Add review" + icon.name: "preview-symbolic" + onTriggered: { + console.log("triggered review") + console.log(`start line: ${editor.selectionStartLine()} to ${editor.selectionEndLine()}`) + popup.open() + } + } + } + } } } diff --git a/kodereviewer/qml/Main.qml b/kodereviewer/qml/Main.qml index 6c13d1e..855b14b 100644 --- a/kodereviewer/qml/Main.qml +++ b/kodereviewer/qml/Main.qml @@ -30,6 +30,10 @@ Kirigami.ApplicationWindow { property PullRequest pullRequest + property ReviewHelper reviewHelper: ReviewHelper { + pullRequest: root.pullRequest + } + Settings { id: settings property alias width: root.width diff --git a/kodereviewer/qml/ReviewList.qml b/kodereviewer/qml/ReviewList.qml index 275e433..77a00e0 100644 --- a/kodereviewer/qml/ReviewList.qml +++ b/kodereviewer/qml/ReviewList.qml @@ -73,9 +73,25 @@ Kirigami.CardsListView { } } - MarkdownTextArea { - id: addComment - Layout.fillWidth: true + RowLayout { + MarkdownTextArea { + id: addComment + Layout.fillWidth: true + } + QQC2.Button { + icon.name: "document-send-symbolic" + enabled: addComment.text != '' + + onClicked: { + if (addComment.text == '') { + return + } + + root.connection.createComment(root.pullRequest.number, newCommentTextArea.text) + newCommentTextArea.text == '' + getCommentsTimer.restart() + } + } } } } 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}') + |