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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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}')
|