summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matias@deprecated.org>2024-10-21 09:57:10 -0300
committerMatias Linares <matias@deprecated.org>2024-10-21 10:07:17 -0300
commitd349e5014fc60a8ae140a56c457c3f3258959582 (patch)
tree062e51d749e40cdafb36299fd8376c0d0302291a
parentbbe83e74b2c1335a0a726c2f993bb2d8c47ffedc (diff)
downloadkodereviewer-d349e5014fc60a8ae140a56c457c3f3258959582.tar.gz
Adding something
Add reviewer data
-rw-r--r--kodereviewer/app.py3
-rw-r--r--kodereviewer/data.py9
-rw-r--r--kodereviewer/models/__init__.py2
-rw-r--r--kodereviewer/models/reviewer.py74
-rw-r--r--kodereviewer/qml/PullRequestDescription.qml45
5 files changed, 114 insertions, 19 deletions
diff --git a/kodereviewer/app.py b/kodereviewer/app.py
index f7c5b08..bc5a626 100644
--- a/kodereviewer/app.py
+++ b/kodereviewer/app.py
@@ -14,7 +14,7 @@ from kodereviewer.models.file import FileModel
from kodereviewer.network_manager import NetworkManager
from kodereviewer.models import (
CommentModel, TreeFileModel, LabelModel, LineModel, PullRequestModel,
- ProjectModel
+ ProjectModel, ReviewerModel
)
import logging
from rich.logging import RichHandler
@@ -53,6 +53,7 @@ def main():
qmlRegisterType(LabelModel, "org.deprecated.kodereviewer", 1, 0, "LabelModel")
qmlRegisterType(LineModel, "org.deprecated.kodereviewer", 1, 0, "LineModel")
qmlRegisterType(PullRequestModel, "org.deprecated.kodereviewer", 1, 0, "PullRequestModel")
+ qmlRegisterType(ReviewerModel, "org.deprecated.kodereviewer", 1, 0, "ReviewerModel")
qmlRegisterType(NetworkManager, "org.deprecated.kodereviewer", 1, 0, "NetworkManager")
localized_context = KLocalizedContext()
diff --git a/kodereviewer/data.py b/kodereviewer/data.py
index 8c4a0e6..61f1a01 100644
--- a/kodereviewer/data.py
+++ b/kodereviewer/data.py
@@ -106,6 +106,7 @@ class PullRequest(QObject):
_user: User
_assignee: User | None
+ _reviewers: list[User]
_labels: list[Label]
_last_commit: str
@@ -134,6 +135,10 @@ class PullRequest(QObject):
if data['assignee'] is not None:
self._assignee = User(data['assignee'])
+ self._reviewers = [
+ User(user) for user in data['assignees']
+ ]
+
self._labels = [Label(label) for label in data['labels']]
self._last_commit = data['head']['sha']
@@ -187,6 +192,10 @@ class PullRequest(QObject):
return self._user.username
@Property(str, constant=True)
+ def reviewers(self) -> list[User]:
+ return self._reviewers
+
+ @Property(str, constant=True)
def last_commit(self) -> str:
return self._last_commit
diff --git a/kodereviewer/models/__init__.py b/kodereviewer/models/__init__.py
index ad675bf..810d403 100644
--- a/kodereviewer/models/__init__.py
+++ b/kodereviewer/models/__init__.py
@@ -4,6 +4,7 @@ from kodereviewer.models.line_model import LineModel
from kodereviewer.models.project import ProjectModel
from kodereviewer.models.pull_request import PullRequestModel
from kodereviewer.models.label import LabelModel
+from kodereviewer.models.reviewer import ReviewerModel
__all__ = [
'CommentModel',
@@ -13,4 +14,5 @@ __all__ = [
'LineModel',
'ProjectModel',
'PullRequestModel',
+ 'ReviewerModel',
]
diff --git a/kodereviewer/models/reviewer.py b/kodereviewer/models/reviewer.py
new file mode 100644
index 0000000..8e9c21a
--- /dev/null
+++ b/kodereviewer/models/reviewer.py
@@ -0,0 +1,74 @@
+from copy import copy
+from enum import IntEnum, auto
+from typing import Any, Optional
+
+from PySide6.QtCore import QAbstractListModel, QByteArray, QModelIndex, QObject, QPersistentModelIndex, QStandardPaths, QUrl, Qt, Signal, Slot, Property
+from PySide6.QtQml import QmlElement
+
+from kodereviewer.project import Project
+from kodereviewer.data import PullRequest, User
+
+QML_IMPORT_NAME = "org.deprecated.kodereviewer"
+QML_IMPORT_MAJOR_VERSION = 1
+
+
+@QmlElement
+class ReviewerModel(QAbstractListModel):
+ """Model to show pull request labels."""
+
+ _pull_request: Optional[PullRequest]
+
+ class Roles(IntEnum):
+ Username = Qt.ItemDataRole.UserRole + 1
+ Avatar = auto()
+
+ def __init__(self):
+ super().__init__()
+ self._pull_request = None
+
+ pullRequestChanged = Signal()
+
+ def get_pull_request(self) -> Optional[PullRequest]:
+ return self._pull_request
+
+ def set_pull_request(self, pull_request: Optional[PullRequest]) -> None:
+ if pull_request is None:
+ return
+
+ if self._pull_request is not None and self._pull_request == pull_request:
+ return
+
+ self.beginResetModel()
+ self._pull_request = pull_request
+ self.endResetModel()
+ self.pullRequestChanged.emit()
+
+ pullRequest = Property(PullRequest, fget=get_pull_request, fset=set_pull_request,
+ notify=pullRequestChanged)
+
+ def data(self,
+ index: QModelIndex | QPersistentModelIndex,
+ role: int = Qt.ItemDataRole.DisplayRole) -> object:
+ if self._pull_request is None:
+ return None
+
+ reviewer: User = self._pull_request.reviewers[index.row()]
+
+ if role == self.Roles.Username:
+ return reviewer.username
+ if role == self.Roles.Avatar:
+ return reviewer.avatar_url
+ if role == Qt.ItemDataRole.DisplayRole:
+ return reviewer.username
+ return None
+
+ def rowCount(self, parent: QModelIndex | QPersistentModelIndex = QModelIndex()) -> int:
+ if self._pull_request is None:
+ return 0
+ return len(self._pull_request.reviewers)
+
+ def roleNames(self) -> dict[int, QByteArray]:
+ return {
+ self.Roles.Username: QByteArray(b'username'),
+ self.Roles.Avatar: QByteArray(b'avatar'),
+ }
diff --git a/kodereviewer/qml/PullRequestDescription.qml b/kodereviewer/qml/PullRequestDescription.qml
index 075b210..329d288 100644
--- a/kodereviewer/qml/PullRequestDescription.qml
+++ b/kodereviewer/qml/PullRequestDescription.qml
@@ -5,6 +5,7 @@ import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.deprecated.kodereviewer 1.0
import org.kde.kirigami as Kirigami
+import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.formcard as FormCard
Kirigami.FormLayout {
@@ -85,22 +86,6 @@ Kirigami.FormLayout {
}
}
-
- ColumnLayout {
- Layout.fillWidth: false
- Layout.fillHeight: true
-
- Repeater {
- model: 0
-
- delegate: QQC2.Label {
- text: "#Faa"
- }
-
- }
-
- }
-
}
Loader {
@@ -135,11 +120,35 @@ Kirigami.FormLayout {
text: name
color: textColor
}
-
}
-
}
+ }
+ Kirigami.Separator {
+ Kirigami.FormData.isSection: true
+ Kirigami.FormData.label: "Reviewers"
+ }
+
+ Loader {
+ id: reviewerModelLoader
+ active: !!root.pullRequest
+ sourceComponent: ReviewerModel {
+ pullRequest: root.pullRequest
+ }
+ }
+ Column {
+ Repeater {
+ id: reviewersListView
+ model: reviewerModelLoader.item
+ delegate: QQC2.Label {
+ required property string username
+ text: `@${username}`
+ }
+ }
+ }
+ QQC2.Label {
+ visible: reviewersListView.count == 0
+ text: "No reviewers"
}
Kirigami.Separator {