basstler-stack 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/maintenance/__init__.py +0 -0
- basstler/maintenance/__main__.py +128 -0
- basstler/maintenance/board.py +113 -0
- basstler/maintenance/check_overview.py +80 -0
- basstler/maintenance/commands.py +595 -0
- basstler/maintenance/default_branch_sync.py +444 -0
- basstler/maintenance/exceptions.py +36 -0
- basstler/maintenance/fast_forward.py +223 -0
- basstler/maintenance/finish_summary.py +515 -0
- basstler/maintenance/fork_pull_request_action.py +38 -0
- basstler/maintenance/landed_closing.py +85 -0
- basstler/maintenance/landed_closing_follow_up.py +85 -0
- basstler/maintenance/promotion.py +248 -0
- basstler/maintenance/promotion_context.py +221 -0
- basstler/maintenance/report.py +304 -0
- basstler/maintenance/restack_procedure.py +279 -0
- basstler/maintenance/restack_steps.py +769 -0
- basstler/maintenance/upstream_pull_request_synchronization.py +189 -0
- basstler/maintenance/upstream_read_route.py +37 -0
- basstler/stack/__init__.py +0 -0
- basstler/stack/__main__.py +377 -0
- basstler/stack/branch_status.py +54 -0
- basstler/stack/checkout.py +416 -0
- basstler/stack/commit_move.py +218 -0
- basstler/stack/exceptions.py +233 -0
- basstler/stack/label_write.py +68 -0
- basstler/stack/merge_probe.py +195 -0
- basstler/stack/model.py +696 -0
- basstler/stack/promotability.py +103 -0
- basstler/stack/promotion_link.py +138 -0
- basstler/stack/report.py +304 -0
- basstler/stack/settings.py +453 -0
- basstler/stack/stack.toml +31 -0
- basstler_stack-4.2.0.dist-info/METADATA +16 -0
- basstler_stack-4.2.0.dist-info/RECORD +38 -0
- basstler_stack-4.2.0.dist-info/WHEEL +4 -0
- basstler_stack-4.2.0.dist-info/licenses/LICENSE +202 -0
- basstler_stack-4.2.0.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The finish summary a whole pass prints: what it left for its developer, in markdown.
|
|
3
|
+
|
|
4
|
+
Its size is bounded whatever the size of the stack: every section lists at most a fixed
|
|
5
|
+
number of entries and every conflict a fixed number of files, and the rest is counted. The
|
|
6
|
+
whole report is written to a file beside it, and every conflict and failing check is
|
|
7
|
+
already in a comment on its pull request.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import functools
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from enum import StrEnum
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from urllib.parse import urlsplit
|
|
18
|
+
|
|
19
|
+
from basstler.github.constants import MaintenanceText
|
|
20
|
+
from basstler.github.states import CombinedCheckState
|
|
21
|
+
from basstler.github.tooling_labels import GitHubLabel
|
|
22
|
+
from basstler.maintenance.check_overview import CheckOverview
|
|
23
|
+
from basstler.maintenance.exceptions import MarkdownLinkTargetError
|
|
24
|
+
from basstler.maintenance.report import MaintenanceReport
|
|
25
|
+
from basstler.maintenance.restack_steps import BranchOutcome, RestackOutcome
|
|
26
|
+
from basstler.render_common import AllowedUrlScheme
|
|
27
|
+
from basstler.stack.model import BranchStatus, Stack, StackBranch
|
|
28
|
+
|
|
29
|
+
# %% vocabulary
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class FinishSummaryHeading(StrEnum):
|
|
33
|
+
"""
|
|
34
|
+
The sections of the finish summary, in the order it prints them.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
PENDING_LINKS = (
|
|
38
|
+
f"Upstream pull requests waiting to be created - the link is under "
|
|
39
|
+
f"{MaintenanceText.PROMOTION_HEADING} in each description"
|
|
40
|
+
)
|
|
41
|
+
"""
|
|
42
|
+
Every create-link not yet acted on, built this pass or an earlier one.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
REPORTED = "Reported to their owners"
|
|
46
|
+
"""
|
|
47
|
+
The branches whose owner was told, in a comment, that their branch needs them.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
REPARENTS = "Reparents still to make"
|
|
51
|
+
"""
|
|
52
|
+
The pull requests whose base has landed and still has to be retargeted.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
FORK_BASE = "The fork's base"
|
|
56
|
+
"""
|
|
57
|
+
What became of the fork's base branch.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
CLOSED_AS_LANDED = "Closed as landed"
|
|
61
|
+
"""
|
|
62
|
+
The pull requests this pass closed, because their commits are already in the
|
|
63
|
+
upstream base.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
CLOSING_FOLLOW_UPS = "After closing"
|
|
67
|
+
"""
|
|
68
|
+
What became of the work other distributions do once pull requests were closed.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
LANDED = "Landed but still open"
|
|
72
|
+
"""
|
|
73
|
+
The pull requests whose commits are already in the upstream base and that this pass
|
|
74
|
+
did not close.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
RESTACKED = "Restacked"
|
|
78
|
+
"""
|
|
79
|
+
How many branches were published, and how many were already up to date.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
UNPUBLISHED = "Left unpublished"
|
|
83
|
+
"""
|
|
84
|
+
The branches the pass could not publish and told nobody about.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
WITHHELD = "Withheld"
|
|
88
|
+
"""
|
|
89
|
+
The branches still conflicted from an earlier pass, left untouched.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
FAILING_CHECKS = "Withheld for failing checks"
|
|
93
|
+
"""
|
|
94
|
+
The approved branches promotion would take but for their failed checks.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
LINK_LABELS_CLEARED = "Spent link labels removed"
|
|
98
|
+
"""
|
|
99
|
+
The branches whose link label was dropped because the link was acted on.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
UPSTREAM_PULL_REQUEST_SYNCHRONIZATION = (
|
|
103
|
+
"In-review labels and upstream links updated"
|
|
104
|
+
)
|
|
105
|
+
"""
|
|
106
|
+
The pull requests whose in-review label or upstream link was written to match the
|
|
107
|
+
upstream.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
SKIPPED = "Skipped"
|
|
111
|
+
"""
|
|
112
|
+
The pull requests whose head the pass cannot maintain.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
NOT_ON_THE_FORK = "Not on the fork, so not refreshed"
|
|
116
|
+
"""
|
|
117
|
+
The branches the board names that the fork does not have, whose state may be stale.
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class PassCount(StrEnum):
|
|
122
|
+
"""
|
|
123
|
+
What the line under the status counts, each worded as it follows its number.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
PUSHED = "pushed"
|
|
127
|
+
"""
|
|
128
|
+
Branches the restack published.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
UP_TO_DATE = "up to date"
|
|
132
|
+
"""
|
|
133
|
+
Branches that already held their parent's tip.
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
LEFT_FOR_SOMEBODY = "left for somebody"
|
|
137
|
+
"""
|
|
138
|
+
Branches the pass could not publish.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
LINKS_RECORDED = "upstream links recorded"
|
|
142
|
+
"""
|
|
143
|
+
Branches whose upstream link was recorded this pass.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
FAILING_CHECKS = "failing checks"
|
|
147
|
+
"""
|
|
148
|
+
Open branches whose checks failed.
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
CHECKS_RUNNING = "checks still running"
|
|
152
|
+
"""
|
|
153
|
+
Open branches whose checks have not finished.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
REPARENTS_LEFT = "reparents left"
|
|
157
|
+
"""
|
|
158
|
+
Pull requests whose base still has to be retargeted.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# %% links
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@dataclass(frozen=True)
|
|
166
|
+
class MarkdownLink:
|
|
167
|
+
"""
|
|
168
|
+
A markdown link whose target is a web URL or an anchor on the same page.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
label: str
|
|
172
|
+
"""
|
|
173
|
+
The text the link shows.
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
target: str
|
|
177
|
+
"""
|
|
178
|
+
What the link points at.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
def __post_init__(self) -> None:
|
|
182
|
+
"""
|
|
183
|
+
:raises MarkdownLinkTargetError: If the target is neither a web URL nor an
|
|
184
|
+
anchor, or holds whitespace, which ends a markdown link target early.
|
|
185
|
+
"""
|
|
186
|
+
if any(character.isspace() for character in self.target):
|
|
187
|
+
raise MarkdownLinkTargetError(self.label, self.target)
|
|
188
|
+
if self.target.startswith("#") and len(self.target) > 1:
|
|
189
|
+
return
|
|
190
|
+
parts = urlsplit(self.target)
|
|
191
|
+
if parts.scheme not in set(AllowedUrlScheme) or not parts.netloc:
|
|
192
|
+
raise MarkdownLinkTargetError(self.label, self.target)
|
|
193
|
+
|
|
194
|
+
def __str__(self) -> str:
|
|
195
|
+
""":return: The link, as markdown."""
|
|
196
|
+
return f"[{self.label}]({self.target})"
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# %% the summary
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
@dataclass(frozen=True)
|
|
203
|
+
class FinishSummary:
|
|
204
|
+
"""
|
|
205
|
+
One pass's report, written for the developer who reads it once.
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
report: MaintenanceReport
|
|
209
|
+
"""
|
|
210
|
+
What the pass did.
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
stack: Stack
|
|
214
|
+
"""
|
|
215
|
+
The stack the pass ran over, read for each pull request's number, title and session.
|
|
216
|
+
"""
|
|
217
|
+
|
|
218
|
+
full_report: Path | None = None
|
|
219
|
+
"""
|
|
220
|
+
The file holding the whole report, named under the summary when there is one.
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
entries_per_section: int = 5
|
|
224
|
+
"""
|
|
225
|
+
How many entries a section lists before counting the rest.
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
paths_per_branch: int = 2
|
|
229
|
+
"""
|
|
230
|
+
How many conflicting files an entry names before counting the rest.
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
def heading_line(heading: str) -> str:
|
|
235
|
+
"""
|
|
236
|
+
:param heading: The section's heading.
|
|
237
|
+
:return: The markdown line opening that section.
|
|
238
|
+
"""
|
|
239
|
+
return f"### {heading}"
|
|
240
|
+
|
|
241
|
+
@functools.cached_property
|
|
242
|
+
def branches_by_name(self) -> dict[str, StackBranch]:
|
|
243
|
+
"""
|
|
244
|
+
The stack's branches, by the name a report entry refers to them by.
|
|
245
|
+
"""
|
|
246
|
+
return {branch.name: branch for branch in self.stack.branches}
|
|
247
|
+
|
|
248
|
+
def as_markdown(self) -> str:
|
|
249
|
+
"""
|
|
250
|
+
:return: The status, then every section that has something in it, in the order
|
|
251
|
+
of :class:`FinishSummaryHeading`.
|
|
252
|
+
"""
|
|
253
|
+
sections = {
|
|
254
|
+
FinishSummaryHeading.PENDING_LINKS: self.capped(self.pending_links()),
|
|
255
|
+
FinishSummaryHeading.REPORTED: self.capped(self.reported()),
|
|
256
|
+
FinishSummaryHeading.REPARENTS: self.capped(self.reparents()),
|
|
257
|
+
FinishSummaryHeading.FORK_BASE: self.fork_base(),
|
|
258
|
+
FinishSummaryHeading.CLOSED_AS_LANDED: self.capped(self.closed_as_landed()),
|
|
259
|
+
FinishSummaryHeading.CLOSING_FOLLOW_UPS: list(
|
|
260
|
+
self.report.closing_follow_ups
|
|
261
|
+
),
|
|
262
|
+
FinishSummaryHeading.LANDED: self.capped(self.landed()),
|
|
263
|
+
FinishSummaryHeading.RESTACKED: self.restacked(),
|
|
264
|
+
FinishSummaryHeading.UNPUBLISHED: self.capped(self.unpublished()),
|
|
265
|
+
FinishSummaryHeading.WITHHELD: self.branch_list(RestackOutcome.WITHHELD),
|
|
266
|
+
FinishSummaryHeading.FAILING_CHECKS: self.capped(self.failing_checks()),
|
|
267
|
+
FinishSummaryHeading.LINK_LABELS_CLEARED: self.code_list(
|
|
268
|
+
self.report.promotion_labels_cleared
|
|
269
|
+
),
|
|
270
|
+
FinishSummaryHeading.UPSTREAM_PULL_REQUEST_SYNCHRONIZATION: self.capped(
|
|
271
|
+
self.upstream_pull_request_synchronization_changes()
|
|
272
|
+
),
|
|
273
|
+
FinishSummaryHeading.SKIPPED: self.capped(self.skipped()),
|
|
274
|
+
FinishSummaryHeading.NOT_ON_THE_FORK: self.code_list(
|
|
275
|
+
self.report.fork_refresh.missing_branches
|
|
276
|
+
),
|
|
277
|
+
}
|
|
278
|
+
lines = [
|
|
279
|
+
f"**Maintenance pass:** {self.report.exit_code.name_for_a_caller}",
|
|
280
|
+
self.counts(),
|
|
281
|
+
]
|
|
282
|
+
for heading, entries in sections.items():
|
|
283
|
+
if entries:
|
|
284
|
+
lines += ["", self.heading_line(heading), "", *entries]
|
|
285
|
+
if self.full_report is not None:
|
|
286
|
+
lines += ["", f"Full report: `{self.full_report}`"]
|
|
287
|
+
return "\n".join(lines)
|
|
288
|
+
|
|
289
|
+
def counts(self) -> str:
|
|
290
|
+
"""
|
|
291
|
+
:return: How many branches each part of the pass touched, naming only the parts
|
|
292
|
+
that touched any.
|
|
293
|
+
"""
|
|
294
|
+
report = self.report
|
|
295
|
+
outcomes = [outcome.outcome for outcome in report.restacked]
|
|
296
|
+
checks = CheckOverview(self.stack)
|
|
297
|
+
counted = {
|
|
298
|
+
PassCount.PUSHED: outcomes.count(RestackOutcome.PUSHED),
|
|
299
|
+
PassCount.UP_TO_DATE: outcomes.count(RestackOutcome.UP_TO_DATE),
|
|
300
|
+
PassCount.LEFT_FOR_SOMEBODY: len(report.branches_left_unpublished),
|
|
301
|
+
PassCount.LINKS_RECORDED: len(report.promoted),
|
|
302
|
+
PassCount.FAILING_CHECKS: len(
|
|
303
|
+
checks.branches_in(CombinedCheckState.FAILURE)
|
|
304
|
+
+ checks.branches_in(CombinedCheckState.ERROR)
|
|
305
|
+
),
|
|
306
|
+
PassCount.CHECKS_RUNNING: len(
|
|
307
|
+
checks.branches_in(CombinedCheckState.PENDING)
|
|
308
|
+
+ checks.branches_in(CombinedCheckState.EXPECTED)
|
|
309
|
+
),
|
|
310
|
+
PassCount.REPARENTS_LEFT: len(report.reparents),
|
|
311
|
+
}
|
|
312
|
+
named = [f"{count} {what}" for what, count in counted.items() if count]
|
|
313
|
+
return ", ".join(named) or "nothing to do"
|
|
314
|
+
|
|
315
|
+
def capped(self, entries: list[str]) -> list[str]:
|
|
316
|
+
"""
|
|
317
|
+
:param entries: A section's entries.
|
|
318
|
+
:return: The first :attr:`entries_per_section` of them, and a count of the rest.
|
|
319
|
+
"""
|
|
320
|
+
hidden = len(entries) - self.entries_per_section
|
|
321
|
+
if hidden <= 0:
|
|
322
|
+
return entries
|
|
323
|
+
return [*entries[: self.entries_per_section], f"- and {hidden} more"]
|
|
324
|
+
|
|
325
|
+
def pull_request_link(self, number: int) -> str:
|
|
326
|
+
"""
|
|
327
|
+
:param number: A fork pull request.
|
|
328
|
+
:return: A markdown link to it, labelled by its number.
|
|
329
|
+
"""
|
|
330
|
+
url = self.stack.configuration.fork_repository.pull_request_url(number)
|
|
331
|
+
return str(MarkdownLink(f"#{number}", url))
|
|
332
|
+
|
|
333
|
+
def branch_line(self, branch: StackBranch) -> str:
|
|
334
|
+
"""
|
|
335
|
+
:param branch: A branch of the stack.
|
|
336
|
+
:return: Its pull request, title and name, as an entry opens.
|
|
337
|
+
"""
|
|
338
|
+
return (
|
|
339
|
+
f"- {self.pull_request_link(branch.pull_request_number)} "
|
|
340
|
+
f"{branch.title or branch.name} - `{branch.name}`"
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
def pending_links(self) -> list[str]:
|
|
344
|
+
"""
|
|
345
|
+
:return: One entry per create-link built this pass, then one per link an
|
|
346
|
+
earlier pass built that is not yet acted on, without the link itself: each
|
|
347
|
+
pull request's description carries its own.
|
|
348
|
+
"""
|
|
349
|
+
promoted = [promotion.branch for promotion in self.report.promoted]
|
|
350
|
+
earlier = [
|
|
351
|
+
branch.name
|
|
352
|
+
for branch in self.stack.maintained_branches()
|
|
353
|
+
if branch.name not in promoted
|
|
354
|
+
and GitHubLabel.PROMOTION_LINK_SENT in branch.labels
|
|
355
|
+
and branch.status not in {BranchStatus.IN_REVIEW, BranchStatus.MERGED}
|
|
356
|
+
]
|
|
357
|
+
return [
|
|
358
|
+
self.branch_line(self.branches_by_name[name])
|
|
359
|
+
for name in [*promoted, *earlier]
|
|
360
|
+
]
|
|
361
|
+
|
|
362
|
+
def reported(self) -> list[str]:
|
|
363
|
+
"""
|
|
364
|
+
:return: One entry per branch whose owner was told about it in a comment.
|
|
365
|
+
"""
|
|
366
|
+
entries = []
|
|
367
|
+
for outcome in self.report.restacked:
|
|
368
|
+
if outcome.reported_at is None:
|
|
369
|
+
continue
|
|
370
|
+
branch = self.branches_by_name[outcome.branch]
|
|
371
|
+
addressed = branch.session or "the description names no session"
|
|
372
|
+
entries.append(
|
|
373
|
+
f"{self.branch_line(branch)}: {self.outcome_detail(outcome)} - "
|
|
374
|
+
f"addressed {addressed} - {MarkdownLink('comment', outcome.reported_at)}"
|
|
375
|
+
)
|
|
376
|
+
return entries
|
|
377
|
+
|
|
378
|
+
def reparents(self) -> list[str]:
|
|
379
|
+
"""
|
|
380
|
+
:return: One entry per pull request still to retarget, from base to base.
|
|
381
|
+
"""
|
|
382
|
+
return [
|
|
383
|
+
f"- {self.pull_request_link(reparent.pull_request_number)} "
|
|
384
|
+
f"`{reparent.branch}`: `{reparent.current_base}` -> `{reparent.target_base}`"
|
|
385
|
+
for reparent in self.report.reparents
|
|
386
|
+
]
|
|
387
|
+
|
|
388
|
+
def fork_base(self) -> list[str]:
|
|
389
|
+
"""
|
|
390
|
+
:return: What became of the fork's base, and why when it was refused.
|
|
391
|
+
"""
|
|
392
|
+
report = self.report.fast_forward
|
|
393
|
+
if report is None:
|
|
394
|
+
return []
|
|
395
|
+
lines = [f"`{report.fork_reference}`: {report.outcome} at `{report.commit}`"]
|
|
396
|
+
return lines + ([report.explanation] if report.explanation else [])
|
|
397
|
+
|
|
398
|
+
def closed_as_landed(self) -> list[str]:
|
|
399
|
+
"""
|
|
400
|
+
:return: One entry per pull request closed because its work had landed.
|
|
401
|
+
"""
|
|
402
|
+
return [
|
|
403
|
+
f"- {self.pull_request_link(closed.pull_request_number)} `{closed.branch}`"
|
|
404
|
+
for closed in self.report.closed_as_landed
|
|
405
|
+
]
|
|
406
|
+
|
|
407
|
+
def landed(self) -> list[str]:
|
|
408
|
+
"""
|
|
409
|
+
:return: One entry per landed branch whose pull request is still open.
|
|
410
|
+
"""
|
|
411
|
+
return [
|
|
412
|
+
self.branch_line(self.branches_by_name[name]) for name in self.report.landed
|
|
413
|
+
]
|
|
414
|
+
|
|
415
|
+
def restacked(self) -> list[str]:
|
|
416
|
+
"""
|
|
417
|
+
:return: How many branches were published and how many were already up to
|
|
418
|
+
date, empty when the restack touched none.
|
|
419
|
+
"""
|
|
420
|
+
outcomes = [outcome.outcome for outcome in self.report.restacked]
|
|
421
|
+
pushed = outcomes.count(RestackOutcome.PUSHED)
|
|
422
|
+
up_to_date = outcomes.count(RestackOutcome.UP_TO_DATE)
|
|
423
|
+
if not pushed and not up_to_date:
|
|
424
|
+
return []
|
|
425
|
+
return [f"{pushed} pushed, {up_to_date} already up to date"]
|
|
426
|
+
|
|
427
|
+
def unpublished(self) -> list[str]:
|
|
428
|
+
"""
|
|
429
|
+
:return: One entry per branch left unpublished that no comment told anyone
|
|
430
|
+
about.
|
|
431
|
+
"""
|
|
432
|
+
return [
|
|
433
|
+
f"{self.branch_line(self.branches_by_name[outcome.branch])}: "
|
|
434
|
+
f"{outcome.outcome} - {self.outcome_detail(outcome)}"
|
|
435
|
+
for outcome in self.report.branches_left_unpublished
|
|
436
|
+
if outcome.reported_at is None
|
|
437
|
+
and outcome.outcome is not RestackOutcome.WITHHELD
|
|
438
|
+
]
|
|
439
|
+
|
|
440
|
+
def outcome_detail(self, outcome: BranchOutcome) -> str:
|
|
441
|
+
"""
|
|
442
|
+
:param outcome: What became of a branch the pass could not publish.
|
|
443
|
+
:return: The files, refusals or explanation its owner, or the pass, acts on.
|
|
444
|
+
"""
|
|
445
|
+
if outcome.conflicting_paths:
|
|
446
|
+
paths = outcome.conflicting_paths
|
|
447
|
+
named = ", ".join(f"`{path}`" for path in paths[: self.paths_per_branch])
|
|
448
|
+
hidden = len(paths) - self.paths_per_branch
|
|
449
|
+
return f"conflicts in {named}" + (
|
|
450
|
+
f" and {hidden} more" if hidden > 0 else ""
|
|
451
|
+
)
|
|
452
|
+
if outcome.refusals:
|
|
453
|
+
return ", ".join(outcome.refusals)
|
|
454
|
+
if outcome.outcome is RestackOutcome.INTEGRATION_FAILED:
|
|
455
|
+
return f"the pass's own environment, not the branch: {outcome.explanation}"
|
|
456
|
+
return outcome.explanation or ""
|
|
457
|
+
|
|
458
|
+
def failing_checks(self) -> list[str]:
|
|
459
|
+
"""
|
|
460
|
+
:return: One entry per approved branch withheld for its failed checks, with the
|
|
461
|
+
verdict over them.
|
|
462
|
+
"""
|
|
463
|
+
return [
|
|
464
|
+
f"{self.branch_line(branch)}: {branch.check_state}"
|
|
465
|
+
for branch in self.stack.withheld_by_failing_checks()
|
|
466
|
+
]
|
|
467
|
+
|
|
468
|
+
def upstream_pull_request_synchronization_changes(self) -> list[str]:
|
|
469
|
+
"""
|
|
470
|
+
:return: One entry per in-review label or upstream link written.
|
|
471
|
+
"""
|
|
472
|
+
return [
|
|
473
|
+
f"{self.branch_line(self.branches_by_name[change.branch])}: {change.action}"
|
|
474
|
+
for change in self.report.upstream_pull_request_synchronization_changes
|
|
475
|
+
]
|
|
476
|
+
|
|
477
|
+
def branch_list(self, outcome: RestackOutcome) -> list[str]:
|
|
478
|
+
"""
|
|
479
|
+
:param outcome: The outcome to collect.
|
|
480
|
+
:return: Every branch that had it, on one line.
|
|
481
|
+
"""
|
|
482
|
+
return self.code_list(
|
|
483
|
+
[
|
|
484
|
+
entry.branch
|
|
485
|
+
for entry in self.report.restacked
|
|
486
|
+
if entry.outcome is outcome
|
|
487
|
+
]
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
def code_list(self, names: Sequence[str]) -> list[str]:
|
|
491
|
+
"""
|
|
492
|
+
:param names: Branch names.
|
|
493
|
+
:return: The first :attr:`entries_per_section` of them on one line with a count
|
|
494
|
+
of the rest, empty when there are none.
|
|
495
|
+
"""
|
|
496
|
+
if not names:
|
|
497
|
+
return []
|
|
498
|
+
line = ", ".join(f"`{name}`" for name in names[: self.entries_per_section])
|
|
499
|
+
hidden = len(names) - self.entries_per_section
|
|
500
|
+
return [line + (f" and {hidden} more" if hidden > 0 else "")]
|
|
501
|
+
|
|
502
|
+
def skipped(self) -> list[str]:
|
|
503
|
+
"""
|
|
504
|
+
:return: One entry per pull request the pass left alone, with why and where its
|
|
505
|
+
head lives.
|
|
506
|
+
"""
|
|
507
|
+
entries = []
|
|
508
|
+
for skipped in self.report.skipped:
|
|
509
|
+
pull_request = skipped.pull_request
|
|
510
|
+
where = pull_request.head_repository or "deleted"
|
|
511
|
+
entries.append(
|
|
512
|
+
f"- {self.pull_request_link(pull_request.number)} "
|
|
513
|
+
f"`{pull_request.head}`: {skipped.reason} ({where})"
|
|
514
|
+
)
|
|
515
|
+
return entries
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
What the maintenance actions on a fork's pull requests have in common.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
|
|
11
|
+
from basstler.github.repository_access import ForkPullRequests
|
|
12
|
+
from basstler.github.branch_pull_request import BranchPullRequest
|
|
13
|
+
from basstler.stack.model import Stack
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class ForkPullRequestAction(ABC):
|
|
18
|
+
"""
|
|
19
|
+
An action that reads the derived stack and writes to its fork pull requests.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
stack: Stack
|
|
23
|
+
"""
|
|
24
|
+
The derived stack, which says which branches there are and what became of them.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
fork: ForkPullRequests
|
|
28
|
+
"""
|
|
29
|
+
The fork to read pull requests from and write them back to.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def apply(self) -> Sequence[BranchPullRequest]:
|
|
34
|
+
"""
|
|
35
|
+
Write to the fork's pull requests what this action is for.
|
|
36
|
+
|
|
37
|
+
:return: One entry per pull request written, in dependency order.
|
|
38
|
+
"""
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Closing the open fork pull requests whose work has already landed upstream.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
|
|
9
|
+
from basstler.github.constants import MaintenanceText
|
|
10
|
+
from basstler.github.constants import MaintenanceNotice
|
|
11
|
+
from basstler.maintenance.fork_pull_request_action import ForkPullRequestAction
|
|
12
|
+
from basstler.github.branch_pull_request import BranchPullRequest
|
|
13
|
+
from basstler.stack.checkout import CurrentCheckout
|
|
14
|
+
from basstler.stack.model import StackBranch
|
|
15
|
+
from basstler.standard_streams import StandardStreamHandler
|
|
16
|
+
|
|
17
|
+
logger = StandardStreamHandler.logger_for(__name__)
|
|
18
|
+
"""
|
|
19
|
+
This module's logger, which is also what its command prints through.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# %% what was closed
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class ClosedAsLanded(BranchPullRequest):
|
|
27
|
+
"""
|
|
28
|
+
One fork pull request closed because its work had landed upstream.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# %% closing them
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class LandedPullRequestClosing(ForkPullRequestAction):
|
|
37
|
+
"""
|
|
38
|
+
Closes every open fork pull request whose commits are all in the upstream base.
|
|
39
|
+
|
|
40
|
+
GitHub records no merge for such a pull request when it is based on another branch,
|
|
41
|
+
so it stays open until it is closed. A branch with no commit beyond its base, or whose
|
|
42
|
+
commits cannot be counted (which is warned about), is left open.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def apply(self) -> tuple[ClosedAsLanded, ...]:
|
|
46
|
+
closed = []
|
|
47
|
+
for branch in self.stack.landed_branches():
|
|
48
|
+
if not self.has_commits_of_its_own(branch):
|
|
49
|
+
continue
|
|
50
|
+
self.fork.close_pull_request(branch.pull_request_number)
|
|
51
|
+
self.fork.add_comment(
|
|
52
|
+
branch.pull_request_number,
|
|
53
|
+
MaintenanceText.LANDED_COMMENT.format(
|
|
54
|
+
branch=branch.name, base=self.upstream_base
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
closed.append(ClosedAsLanded(branch.name, branch.pull_request_number))
|
|
58
|
+
return tuple(closed)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def upstream_base(self) -> str:
|
|
62
|
+
"""
|
|
63
|
+
:return: The upstream base reference the landed branches are contained in.
|
|
64
|
+
"""
|
|
65
|
+
configuration = self.stack.configuration
|
|
66
|
+
return f"{configuration.upstream_remote}/{configuration.upstream_base}"
|
|
67
|
+
|
|
68
|
+
def has_commits_of_its_own(self, branch: StackBranch) -> bool:
|
|
69
|
+
"""
|
|
70
|
+
:param branch: A landed branch of the stack.
|
|
71
|
+
:return: Whether the fork's copy of it has a commit its base lacks; ``False``
|
|
72
|
+
when either cannot be read, which is warned about.
|
|
73
|
+
"""
|
|
74
|
+
configuration = self.stack.configuration
|
|
75
|
+
base = configuration.reference_on_fork(branch.parent)
|
|
76
|
+
head = configuration.reference_on_fork(branch.name)
|
|
77
|
+
ahead = CurrentCheckout.commit_count(f"{base}..{head}")
|
|
78
|
+
if ahead is None:
|
|
79
|
+
logger.warning(
|
|
80
|
+
MaintenanceNotice.LANDED_BRANCH_UNREADABLE.format(
|
|
81
|
+
branch=branch.name, base=base, head=head
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
return False
|
|
85
|
+
return ahead > 0
|