basstler-github 4.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- basstler/github/__init__.py +0 -0
- basstler/github/actions_budget.py +428 -0
- basstler/github/actions_secret.py +25 -0
- basstler/github/actions_settings.py +162 -0
- basstler/github/actions_usage.py +297 -0
- basstler/github/basstler_project.py +75 -0
- basstler/github/branch_pull_request.py +24 -0
- basstler/github/client.py +452 -0
- basstler/github/comparison.py +60 -0
- basstler/github/constants.py +197 -0
- basstler/github/credential.py +85 -0
- basstler/github/exceptions.py +264 -0
- basstler/github/file_proposal.py +440 -0
- basstler/github/fork_sync.py +44 -0
- basstler/github/git_objects.py +57 -0
- basstler/github/graphql.py +101 -0
- basstler/github/issue.py +221 -0
- basstler/github/label.py +78 -0
- basstler/github/login_lending.py +46 -0
- basstler/github/main_failure.py +289 -0
- basstler/github/permission_level.py +33 -0
- basstler/github/pull_request.py +74 -0
- basstler/github/pull_request_changes.py +141 -0
- basstler/github/pull_request_description.py +145 -0
- basstler/github/pull_request_ends.py +58 -0
- basstler/github/pull_request_form.py +136 -0
- basstler/github/pull_request_models.py +321 -0
- basstler/github/pull_request_record.py +369 -0
- basstler/github/pull_request_source.py +395 -0
- basstler/github/pull_request_state.py +437 -0
- basstler/github/queries/pull_request_for_branch.graphql +17 -0
- basstler/github/queries/review_threads_page.graphql +72 -0
- basstler/github/query_documents.py +37 -0
- basstler/github/release_version.py +565 -0
- basstler/github/remote.py +36 -0
- basstler/github/repository.py +532 -0
- basstler/github/repository_access.py +459 -0
- basstler/github/repository_attachment.py +95 -0
- basstler/github/repository_details.py +98 -0
- basstler/github/repository_option.py +43 -0
- basstler/github/repository_resources.py +133 -0
- basstler/github/rest_models.py +353 -0
- basstler/github/review_models.py +223 -0
- basstler/github/run_listing.py +148 -0
- basstler/github/stack_configuration.py +178 -0
- basstler/github/states.py +257 -0
- basstler/github/token_form.py +360 -0
- basstler/github/tooling_labels.py +83 -0
- basstler/github/user_steps.py +170 -0
- basstler/github/web_form.py +56 -0
- basstler/github/web_page.py +33 -0
- basstler/github/wire_form.py +159 -0
- basstler/github/workflow_run.py +126 -0
- basstler/github/workflows.py +561 -0
- basstler/templates/actions_budget.py.jinja +26 -0
- basstler_github-4.2.0.dist-info/METADATA +16 -0
- basstler_github-4.2.0.dist-info/RECORD +60 -0
- basstler_github-4.2.0.dist-info/WHEEL +4 -0
- basstler_github-4.2.0.dist-info/licenses/LICENSE +202 -0
- basstler_github-4.2.0.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Reading one REST resource of a repository into the model of its type, and writing a
|
|
3
|
+
resource or a setting with the step that takes it by hand when GitHub refuses.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import Any, get_args, get_origin
|
|
11
|
+
|
|
12
|
+
from basstler.class_property import classproperty
|
|
13
|
+
from basstler.github.client import GitHubAttemptReader, GitHubResponse, RepositoryWrite
|
|
14
|
+
from basstler.github.repository import HasRepository
|
|
15
|
+
from basstler.github.user_steps import UserStep
|
|
16
|
+
from basstler.json_model import ValidatedJSONModel
|
|
17
|
+
|
|
18
|
+
# %% the type a read or a write is bound to
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TypeBinding:
|
|
22
|
+
"""
|
|
23
|
+
A class whose subclasses each bind a generic base's parameter to the type they
|
|
24
|
+
handle.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def bound_type_argument(cls, generic_base: type) -> type[Any]:
|
|
29
|
+
"""
|
|
30
|
+
:param generic_base: The generic class whose parameter is bound.
|
|
31
|
+
:return: The type this class binds it to, directly or through a base.
|
|
32
|
+
:raises TypeError: If this class leaves the parameter unbound.
|
|
33
|
+
"""
|
|
34
|
+
for klass in cls.__mro__:
|
|
35
|
+
for base in klass.__dict__.get("__orig_bases__", ()):
|
|
36
|
+
origin = get_origin(base)
|
|
37
|
+
if isinstance(origin, type) and issubclass(origin, generic_base):
|
|
38
|
+
(argument,) = get_args(base)
|
|
39
|
+
if isinstance(argument, type):
|
|
40
|
+
return argument
|
|
41
|
+
raise TypeError(f"{cls.__name__} binds no type to {generic_base.__name__}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# %% reading a resource
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True)
|
|
48
|
+
class ResourceReading[ResourceType: ValidatedJSONModel]:
|
|
49
|
+
"""
|
|
50
|
+
GitHub's answer to one read, with the resource parsed when it was served.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
response: GitHubResponse
|
|
54
|
+
"""
|
|
55
|
+
GitHub's answer.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
resource: ResourceType | None
|
|
59
|
+
"""
|
|
60
|
+
The resource read, ``None`` when GitHub refused or found none.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class RepositoryRead[ResourceType: ValidatedJSONModel](HasRepository, TypeBinding, ABC):
|
|
66
|
+
"""
|
|
67
|
+
A read of one REST resource of a repository, bound to the model the resource parses
|
|
68
|
+
into.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
@abstractmethod
|
|
73
|
+
def path(self) -> str:
|
|
74
|
+
"""
|
|
75
|
+
The resource's REST path.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
@classproperty
|
|
79
|
+
def resource_type(cls) -> type[ResourceType]:
|
|
80
|
+
"""
|
|
81
|
+
The model this read is bound to.
|
|
82
|
+
"""
|
|
83
|
+
return cls.bound_type_argument(RepositoryRead)
|
|
84
|
+
|
|
85
|
+
def parse(self, body: Any) -> ResourceType:
|
|
86
|
+
"""
|
|
87
|
+
:param body: GitHub's answer, served.
|
|
88
|
+
:return: The resource it describes.
|
|
89
|
+
"""
|
|
90
|
+
return self.resource_type.from_json(body, self)
|
|
91
|
+
|
|
92
|
+
def attempt(self, client: GitHubAttemptReader) -> ResourceReading[ResourceType]:
|
|
93
|
+
"""
|
|
94
|
+
:param client: Reads the repository.
|
|
95
|
+
:return: GitHub's answer, with the resource parsed when it was served.
|
|
96
|
+
"""
|
|
97
|
+
response = client.attempt_get(self.path)
|
|
98
|
+
if response.failure is not None:
|
|
99
|
+
return ResourceReading(response, None)
|
|
100
|
+
return ResourceReading(response, self.parse(response.body))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# %% writing a resource
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ResourceWrite[ResourceType: ValidatedJSONModel](
|
|
107
|
+
TypeBinding, RepositoryWrite, ABC
|
|
108
|
+
):
|
|
109
|
+
"""
|
|
110
|
+
A change to one resource of a repository, bound to the model of the resource it
|
|
111
|
+
changes.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
@classproperty
|
|
115
|
+
def resource_type(cls) -> type[ResourceType]:
|
|
116
|
+
"""
|
|
117
|
+
The model of the resource this write changes.
|
|
118
|
+
"""
|
|
119
|
+
return cls.bound_type_argument(ResourceWrite)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class SettingWrite[ResourceType: ValidatedJSONModel](ResourceWrite[ResourceType], ABC):
|
|
123
|
+
"""
|
|
124
|
+
A change to one setting of a repository, which the user can make by hand where
|
|
125
|
+
GitHub refuses it.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
@abstractmethod
|
|
130
|
+
def manual_step(self) -> UserStep:
|
|
131
|
+
"""
|
|
132
|
+
The same change, as the step the user takes when GitHub refuses the write.
|
|
133
|
+
"""
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Models of a pull request's REST responses, each parsed into the same models a GraphQL
|
|
3
|
+
read builds.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
from typing import Annotated, Any
|
|
11
|
+
|
|
12
|
+
from pydantic import Field
|
|
13
|
+
|
|
14
|
+
from basstler.github.pull_request_models import (
|
|
15
|
+
CheckResult,
|
|
16
|
+
)
|
|
17
|
+
from basstler.github.review_models import (
|
|
18
|
+
Author,
|
|
19
|
+
BranchPullRequest,
|
|
20
|
+
Review,
|
|
21
|
+
ReviewThread,
|
|
22
|
+
ThreadComment,
|
|
23
|
+
)
|
|
24
|
+
from basstler.github.states import ConclusionOutcome, PullRequestState, ReviewState
|
|
25
|
+
from basstler.git.branch import Branch
|
|
26
|
+
from basstler.github.wire_form import WireForm
|
|
27
|
+
from basstler.github.exceptions import RepositoryUnknown
|
|
28
|
+
from basstler.github.repository import HasRepository, Repository
|
|
29
|
+
from basstler.github.web_page import AbsentAsEmpty, WebPage
|
|
30
|
+
from basstler.json_model import ObjectReader, ValidatedJSONModel
|
|
31
|
+
|
|
32
|
+
# %% models mirroring the REST data
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RestResponse:
|
|
36
|
+
"""
|
|
37
|
+
A model of one whole response a REST read parses, not of an object nested in one.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class RestPullRequestState(StrEnum):
|
|
42
|
+
"""
|
|
43
|
+
The two states REST reports a pull request in; a merged one reads as closed.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
OPEN = "open"
|
|
47
|
+
CLOSED = "closed"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class PullRequestEnd(Branch[Repository]):
|
|
52
|
+
"""
|
|
53
|
+
One end of a pull request - the branch it is opened from or merges into - at the
|
|
54
|
+
commit the branch pointed at when it was read.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
commit: str
|
|
58
|
+
"""
|
|
59
|
+
The hash of the commit the branch pointed at.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class PullRequestEndForm(WireForm[PullRequestEnd], ObjectReader):
|
|
64
|
+
"""
|
|
65
|
+
A pull request's end, written as the object REST names it with: the branch, its
|
|
66
|
+
commit and the repository it is of, ``null`` once that repository is deleted.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def read_keys(self) -> frozenset[str]:
|
|
71
|
+
return frozenset({"ref", "sha", "repo", "full_name"})
|
|
72
|
+
|
|
73
|
+
def read(self, value: Any, read: HasRepository | None) -> PullRequestEnd:
|
|
74
|
+
if value["repo"] is None:
|
|
75
|
+
raise RepositoryUnknown(value["ref"])
|
|
76
|
+
return PullRequestEnd(
|
|
77
|
+
Repository.parse(value["repo"]["full_name"]), value["ref"], value["sha"]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def write(self, owned: PullRequestEnd) -> dict[str, Any]:
|
|
81
|
+
return {
|
|
82
|
+
"ref": owned.name,
|
|
83
|
+
"sha": owned.commit,
|
|
84
|
+
"repo": {"full_name": owned.repository.full_name},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class PullRequestNumber(ValidatedJSONModel):
|
|
89
|
+
"""
|
|
90
|
+
A pull request as every REST resource of one names it: by its number.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
number: int
|
|
94
|
+
"""
|
|
95
|
+
Its number on the repository it is opened on.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class PullRequestPage(PullRequestNumber, WebPage):
|
|
100
|
+
"""
|
|
101
|
+
A pull request named by its number and its page.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class PullRequestAtHead(PullRequestNumber):
|
|
106
|
+
"""
|
|
107
|
+
A pull request and the commit its branch points at.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
head: Annotated[PullRequestEnd, PullRequestEndForm()]
|
|
111
|
+
"""
|
|
112
|
+
The branch it was opened from.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def is_at(self, other: PullRequestAtHead) -> bool:
|
|
116
|
+
"""
|
|
117
|
+
:param other: A pull request.
|
|
118
|
+
:return: Whether it is the same pull request at the same head commit.
|
|
119
|
+
"""
|
|
120
|
+
return self.number == other.number and self.head.commit == other.head.commit
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class RestPullRequestSummary(RestResponse, PullRequestAtHead, PullRequestPage):
|
|
124
|
+
"""
|
|
125
|
+
One pull request as REST describes it, whether listed or read on its own.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
title: str
|
|
129
|
+
"""
|
|
130
|
+
Its title.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
state: RestPullRequestState
|
|
134
|
+
"""
|
|
135
|
+
Whether it is open or closed.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
merged_at: str | None
|
|
139
|
+
"""
|
|
140
|
+
When it merged, as an ISO 8601 timestamp, absent unless it closed by merging.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
base: Annotated[PullRequestEnd, PullRequestEndForm()]
|
|
144
|
+
"""
|
|
145
|
+
The branch it merges into.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def merged(self) -> bool:
|
|
150
|
+
""":return: Whether it closed by merging."""
|
|
151
|
+
return self.merged_at is not None
|
|
152
|
+
|
|
153
|
+
@property
|
|
154
|
+
def branch_pull_request(self) -> BranchPullRequest:
|
|
155
|
+
"""
|
|
156
|
+
:return: The summary a branch search compares, in the lifecycle GraphQL names.
|
|
157
|
+
"""
|
|
158
|
+
if self.merged:
|
|
159
|
+
state = PullRequestState.MERGED
|
|
160
|
+
else:
|
|
161
|
+
state = PullRequestState[self.state.name]
|
|
162
|
+
return BranchPullRequest(
|
|
163
|
+
number=self.number,
|
|
164
|
+
state=state,
|
|
165
|
+
head_owner=Author(login=self.head.repository.owner),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class RestReview(RestResponse, ValidatedJSONModel):
|
|
170
|
+
"""
|
|
171
|
+
One review, as REST lists it, whose body and submission time are null until it is
|
|
172
|
+
submitted.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
author: Annotated[Author, Field(alias="user")]
|
|
176
|
+
"""
|
|
177
|
+
Whoever submitted the review.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
state: ReviewState
|
|
181
|
+
"""
|
|
182
|
+
The verdict the reviewer submitted.
|
|
183
|
+
"""
|
|
184
|
+
|
|
185
|
+
body: str | None
|
|
186
|
+
"""
|
|
187
|
+
The review's summary text.
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
submitted_at: str | None
|
|
191
|
+
"""
|
|
192
|
+
When the review was submitted, as an ISO 8601 timestamp.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
@property
|
|
196
|
+
def review(self) -> Review:
|
|
197
|
+
""":return: The review, as the report reads it."""
|
|
198
|
+
return Review(
|
|
199
|
+
author=self.author,
|
|
200
|
+
state=self.state,
|
|
201
|
+
body=self.body or "",
|
|
202
|
+
submitted_at=self.submitted_at or "",
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class RestReviewComment(RestResponse, WebPage):
|
|
207
|
+
"""
|
|
208
|
+
One review comment, as REST lists every comment on a pull request.
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
identifier: Annotated[int, Field(alias="id")]
|
|
212
|
+
"""
|
|
213
|
+
GitHub's numeric identifier, the one that appears in comment permalinks.
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
author: Annotated[Author, Field(alias="user")]
|
|
217
|
+
"""
|
|
218
|
+
Whoever wrote the comment.
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
body: str
|
|
222
|
+
"""
|
|
223
|
+
The comment text, exactly as written.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
created_at: str
|
|
227
|
+
"""
|
|
228
|
+
When the comment was posted, as an ISO 8601 timestamp.
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def comment(self) -> ThreadComment:
|
|
233
|
+
""":return: The comment, as the report reads it."""
|
|
234
|
+
return ThreadComment(
|
|
235
|
+
database_identifier=self.identifier,
|
|
236
|
+
author=self.author,
|
|
237
|
+
body=self.body,
|
|
238
|
+
created_at=self.created_at,
|
|
239
|
+
page_url=self.page_url,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class RestReviewThread(RestResponse, ValidatedJSONModel):
|
|
244
|
+
"""
|
|
245
|
+
One review thread, as a Claude Code session's proxy reports it: its state and
|
|
246
|
+
location, and the comments in it named by identifier only.
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
is_resolved: Annotated[bool, Field(alias="resolved")]
|
|
250
|
+
"""
|
|
251
|
+
Whether a reviewer has marked the thread resolved.
|
|
252
|
+
"""
|
|
253
|
+
|
|
254
|
+
is_outdated: Annotated[bool, Field(alias="outdated")]
|
|
255
|
+
"""
|
|
256
|
+
Whether the diff hunk the thread was anchored to has since changed.
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
path: str
|
|
260
|
+
"""
|
|
261
|
+
The file the thread is attached to.
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
line: int | None
|
|
265
|
+
"""
|
|
266
|
+
The line the thread is attached to, absent once the hunk is outdated.
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
comment_identifiers: Annotated[list[int], Field(alias="comment_ids")]
|
|
270
|
+
"""
|
|
271
|
+
The comments in the thread, oldest first.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
def thread(self, comments: dict[int, ThreadComment]) -> ReviewThread:
|
|
275
|
+
"""
|
|
276
|
+
Fill the thread in with its comments.
|
|
277
|
+
|
|
278
|
+
The route carries no identifier of the thread's own, so its first comment's
|
|
279
|
+
stands in for one. A comment deleted since the comments were listed is left out
|
|
280
|
+
rather than failing the whole read.
|
|
281
|
+
|
|
282
|
+
:param comments: Every comment on the pull request, by identifier.
|
|
283
|
+
:return: The thread, as the report reads it.
|
|
284
|
+
"""
|
|
285
|
+
return ReviewThread(
|
|
286
|
+
identifier=str(self.comment_identifiers[0]),
|
|
287
|
+
is_resolved=self.is_resolved,
|
|
288
|
+
is_outdated=self.is_outdated,
|
|
289
|
+
path=self.path,
|
|
290
|
+
line=self.line,
|
|
291
|
+
comments=[
|
|
292
|
+
comments[identifier]
|
|
293
|
+
for identifier in self.comment_identifiers
|
|
294
|
+
if identifier in comments
|
|
295
|
+
],
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class RestCheckRun(CheckResult):
|
|
300
|
+
"""
|
|
301
|
+
A check run, as the REST check-runs listing returns it.
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
outcome: Annotated[ConclusionOutcome, Field(alias="conclusion")]
|
|
305
|
+
"""
|
|
306
|
+
Where the run stands, pending while it has no conclusion.
|
|
307
|
+
"""
|
|
308
|
+
|
|
309
|
+
target_url: Annotated[str, AbsentAsEmpty(), Field(alias="details_url")]
|
|
310
|
+
"""
|
|
311
|
+
The run's page, empty when it has none.
|
|
312
|
+
"""
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class RestCommitStatus(CheckResult):
|
|
316
|
+
"""
|
|
317
|
+
A commit status, as the REST combined-status response lists it.
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
name: Annotated[str, Field(alias="context")]
|
|
321
|
+
"""
|
|
322
|
+
The context the status was posted under, which names it.
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
outcome: Annotated[ConclusionOutcome, Field(alias="state")]
|
|
326
|
+
"""
|
|
327
|
+
The state the status was posted with.
|
|
328
|
+
"""
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
class RestCheckRunPage(RestResponse, ValidatedJSONModel):
|
|
332
|
+
"""
|
|
333
|
+
One page of the check runs reported against a commit.
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
check_runs: list[RestCheckRun]
|
|
337
|
+
"""
|
|
338
|
+
The check runs on this page.
|
|
339
|
+
"""
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
class RestCombinedStatusPage(RestResponse, ValidatedJSONModel):
|
|
343
|
+
"""
|
|
344
|
+
One page of the statuses posted against a commit.
|
|
345
|
+
|
|
346
|
+
Its own combined state is left unread: GitHub reports it pending when nothing has
|
|
347
|
+
posted at all, which would misreport a commit no status applies to.
|
|
348
|
+
"""
|
|
349
|
+
|
|
350
|
+
statuses: list[RestCommitStatus]
|
|
351
|
+
"""
|
|
352
|
+
The statuses on this page.
|
|
353
|
+
"""
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Models of a pull request's reviews and review threads, as GitHub's GraphQL API returns
|
|
3
|
+
them.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from enum import StrEnum
|
|
9
|
+
from typing import Annotated, Any
|
|
10
|
+
|
|
11
|
+
from pydantic import Field, model_validator
|
|
12
|
+
|
|
13
|
+
from basstler.class_property import classproperty
|
|
14
|
+
from basstler.github.graphql import GraphQLConnection
|
|
15
|
+
from basstler.github.states import PullRequestState, ReviewState
|
|
16
|
+
from basstler.json_model import ValidatedJSONModel
|
|
17
|
+
|
|
18
|
+
# %% the report's thread markers
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ThreadMarker(StrEnum):
|
|
22
|
+
"""
|
|
23
|
+
The annotations a thread can carry in the report.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
RESOLVED = "resolved"
|
|
27
|
+
OUTDATED = "outdated"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# %% models mirroring the data
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Author(ValidatedJSONModel):
|
|
34
|
+
"""
|
|
35
|
+
Whoever wrote a comment or submitted a review.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
login: str
|
|
39
|
+
"""
|
|
40
|
+
Their GitHub login, or a placeholder when the account is gone.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
@classproperty
|
|
44
|
+
def unknown_login(cls) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Stands in for the author of a comment whose account no longer exists.
|
|
47
|
+
"""
|
|
48
|
+
return "(unknown)"
|
|
49
|
+
|
|
50
|
+
@model_validator(mode="before")
|
|
51
|
+
@classmethod
|
|
52
|
+
def read_deleted_account(cls, data: Any) -> Any:
|
|
53
|
+
"""
|
|
54
|
+
:param data: The ``author`` object, which GitHub reports as null for a deleted
|
|
55
|
+
account.
|
|
56
|
+
:return: The object, with :attr:`unknown_login` standing in for a deleted one.
|
|
57
|
+
"""
|
|
58
|
+
if data is None:
|
|
59
|
+
return {"login": cls.unknown_login}
|
|
60
|
+
return data
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ThreadComment(ValidatedJSONModel):
|
|
64
|
+
"""
|
|
65
|
+
One comment inside a review thread.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
database_identifier: Annotated[int, Field(alias="databaseId")]
|
|
69
|
+
"""
|
|
70
|
+
GitHub's numeric identifier, the one that appears in comment permalinks.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
author: Author
|
|
74
|
+
"""
|
|
75
|
+
Whoever wrote the comment.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
body: str
|
|
79
|
+
"""
|
|
80
|
+
The comment text, exactly as written.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
created_at: Annotated[str, Field(alias="createdAt")]
|
|
84
|
+
"""
|
|
85
|
+
When the comment was posted, as an ISO 8601 timestamp.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
page_url: Annotated[str, Field(alias="url")]
|
|
89
|
+
"""
|
|
90
|
+
The permalink to this comment.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ReviewThread(ValidatedJSONModel):
|
|
95
|
+
"""
|
|
96
|
+
A conversation anchored to one location in the pull request's diff.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
identifier: Annotated[str, Field(alias="id")]
|
|
100
|
+
"""
|
|
101
|
+
GitHub's node identifier for the thread.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
is_resolved: Annotated[bool, Field(alias="isResolved")]
|
|
105
|
+
"""
|
|
106
|
+
Whether a reviewer has marked the thread resolved.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
is_outdated: Annotated[bool, Field(alias="isOutdated")]
|
|
110
|
+
"""
|
|
111
|
+
Whether the diff hunk the thread was anchored to has since changed.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
path: str
|
|
115
|
+
"""
|
|
116
|
+
The file the thread is attached to.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
line: int | None
|
|
120
|
+
"""
|
|
121
|
+
The line the thread is attached to, absent once the hunk is outdated.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
comments: GraphQLConnection[ThreadComment]
|
|
125
|
+
"""
|
|
126
|
+
Every comment in the thread, oldest first.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def location(self) -> str:
|
|
131
|
+
""":return: The thread's ``path:line``, or just its path when it is outdated."""
|
|
132
|
+
if self.line is None:
|
|
133
|
+
return self.path
|
|
134
|
+
return f"{self.path}:{self.line}"
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
def markers(self) -> list[ThreadMarker]:
|
|
138
|
+
""":return: The annotations this thread carries."""
|
|
139
|
+
carried = []
|
|
140
|
+
if self.is_resolved:
|
|
141
|
+
carried.append(ThreadMarker.RESOLVED)
|
|
142
|
+
if self.is_outdated:
|
|
143
|
+
carried.append(ThreadMarker.OUTDATED)
|
|
144
|
+
return carried
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class Review(ValidatedJSONModel):
|
|
148
|
+
"""
|
|
149
|
+
A submitted review, separate from the threads it may have opened.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
author: Author
|
|
153
|
+
"""
|
|
154
|
+
Whoever submitted the review.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
state: ReviewState
|
|
158
|
+
"""
|
|
159
|
+
The verdict the reviewer submitted.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
body: str
|
|
163
|
+
"""
|
|
164
|
+
The review's summary text, which is often empty.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
submitted_at: Annotated[str, Field(alias="submittedAt")]
|
|
168
|
+
"""
|
|
169
|
+
When the review was submitted, as an ISO 8601 timestamp.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class BranchPullRequest(ValidatedJSONModel):
|
|
174
|
+
"""
|
|
175
|
+
One pull request found by searching the upstream for a head branch.
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
number: int
|
|
179
|
+
"""
|
|
180
|
+
Its number on the upstream repository.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
state: PullRequestState
|
|
184
|
+
"""
|
|
185
|
+
Its lifecycle state.
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
head_owner: Annotated[Author, Field(alias="headRepositoryOwner")]
|
|
189
|
+
"""
|
|
190
|
+
The owner of the repository the head branch lives in.
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class PageInfo(ValidatedJSONModel):
|
|
195
|
+
"""
|
|
196
|
+
Where one page of a paged list stands in the whole list.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
has_next_page: Annotated[bool, Field(alias="hasNextPage")]
|
|
200
|
+
"""
|
|
201
|
+
Whether another page follows.
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
end_cursor: Annotated[str | None, Field(alias="endCursor")]
|
|
205
|
+
"""
|
|
206
|
+
The cursor to request that next page with.
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
class ReviewThreadPage(ValidatedJSONModel):
|
|
211
|
+
"""
|
|
212
|
+
One page of review threads, with where it stands in the whole list.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
threads: Annotated[list[ReviewThread], Field(alias="nodes")]
|
|
216
|
+
"""
|
|
217
|
+
The threads on this page.
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
page_info: Annotated[PageInfo, Field(alias="pageInfo")]
|
|
221
|
+
"""
|
|
222
|
+
Whether another page follows, and the cursor to request it with.
|
|
223
|
+
"""
|