summaryrefslogtreecommitdiff
path: root/kodereviewer/data.py
blob: 7d3b73abd508b4486aa294ca5fc3f4841d01f2cb (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from datetime import datetime
from enum import Enum
from typing import Any, Optional

from PySide6.QtCore import QObject, QSettings, Signal, Slot, Property, qDebug
from PySide6.QtNetwork import QHttpHeaders, QNetworkAccessManager, QNetworkReply, QNetworkRequestFactory
from PySide6.QtQml import QmlElement


class User(QObject):
    username: str
    avatar_url: str

    def __init__(self, data: dict[str, Any]):
        super().__init__()
        self.username = data['login']
        self.avatar_url = data['avatar_url']


class Label(QObject):
    name: str
    color: str
    description: str

    def __init__(self, data: dict[str, Any]):
        super().__init__()
        self.name = data['name']
        self.color = data['color']
        self.description = data['description']



class State(Enum):
    OPEN = 'open'
    CLOSED = 'closed'
    DRAFT = 'draft'


class PullRequest(QObject):

    number: int
    title: str
    state: State
    url: str
    body: str | None
    created_at: datetime
    updated_at: datetime

    user: User
    assignee: User | None
    labels: list[str]


    def __init__(self, data: dict[str, Any]):
        super().__init__()
        self.number = data['number']
        self.state = data['state']
        self.title = data['title']
        self.url = data['html_url']
        self.body = data['body']
        self.created_at = datetime.fromisoformat(data['created_at'])
        self.updated_at = datetime.fromisoformat(data['updated_at'])

        self.user = User(data['user'])
        self.assignee = None
        if data['assignee'] is not None:
            self.assignee = User(data['assignee'])

        labels = [Label(label) for label in data['labels']]