summaryrefslogtreecommitdiff
path: root/kodereviewer/project.py
blob: 669ee90851232033bf4bbe6c3982db06ea427099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
from PySide6.QtCore import QByteArray, QObject, QUrl, Signal, Slot, Property
from PySide6.QtQml import QmlElement

from kodereviewer.data import PullRequest

QML_IMPORT_NAME = "org.deprecated.kodereviewer"
QML_IMPORT_MAJOR_VERSION = 1

@QmlElement
class Project(QObject):
    """Represents a github project"""

    _name: str
    _owner: str
    _url: QUrl
    _pull_requests: list[PullRequest]

    pullRequestChanged = Signal()

    def __init__(self, name: str, owner: str, url: QUrl):
        super().__init__()
        self._name = name
        self._owner = owner
        self._url = url
        self._pull_requests = []

    @Property(str)
    def name(self) -> str:
        return self._name

    @Property(str)
    def owner(self) -> str:
        return self._owner

    @Property(QUrl)
    def url(self) -> QUrl:
        return self._url

    @Property(list)
    def pullRequests(self) -> list[PullRequest]:
        return self._pull_requests

    def load_pull_requests(self, response: QByteArray) -> None:
        data = json.loads(response.toStdString())
        self._pull_requests = [
            PullRequest(pr) for pr in data
        ]
        self.pullRequestChanged.emit()