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,595 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The commands the executor answers, and what one run has resolved for them.
|
|
3
|
+
|
|
4
|
+
A command owns its own name, its own flags and its own work, so adding one is writing a
|
|
5
|
+
subclass: :meth:`MaintenanceCommand.every_command` finds it, and nothing else has to be
|
|
6
|
+
told it exists.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
from abc import abstractmethod
|
|
14
|
+
from dataclasses import asdict, dataclass
|
|
15
|
+
from enum import StrEnum
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from basstler.git.remote_branch import RemoteBranch
|
|
19
|
+
from basstler.class_property import classproperty
|
|
20
|
+
from basstler.command_line import Command
|
|
21
|
+
from basstler.exit_codes import StackExitCode
|
|
22
|
+
from basstler.git.commands import GitCommandRunner, ProposedPush
|
|
23
|
+
from basstler.github.remote import GitHubRemote
|
|
24
|
+
from basstler.github.client import GitHubRestClient
|
|
25
|
+
from basstler.github.constants import MaintenanceNotice
|
|
26
|
+
from basstler.github.repository_access import GitHubRepository, PullRequestReader
|
|
27
|
+
from basstler.locations import RepositoryStateLocation
|
|
28
|
+
from basstler.maintenance.board import BoardExport
|
|
29
|
+
from basstler.maintenance.check_overview import CheckOverview
|
|
30
|
+
from basstler.maintenance.fast_forward import fast_forward
|
|
31
|
+
from basstler.maintenance.landed_closing import LandedPullRequestClosing
|
|
32
|
+
from basstler.maintenance.landed_closing_follow_up import LandedClosingFollowUps
|
|
33
|
+
from basstler.maintenance.finish_summary import FinishSummary
|
|
34
|
+
from basstler.maintenance.promotion import (
|
|
35
|
+
PromotionSummaries,
|
|
36
|
+
clear_spent_promotion_labels,
|
|
37
|
+
promote,
|
|
38
|
+
)
|
|
39
|
+
from basstler.maintenance.promotion_context import PromotionContextReader
|
|
40
|
+
from basstler.maintenance.report import MaintenanceReport
|
|
41
|
+
from basstler.maintenance.restack_procedure import restack
|
|
42
|
+
from basstler.maintenance.upstream_pull_request_synchronization import (
|
|
43
|
+
UpstreamPullRequestSynchronization,
|
|
44
|
+
)
|
|
45
|
+
from basstler.maintenance.upstream_read_route import UpstreamReadRoute
|
|
46
|
+
from basstler.stack.commit_move import (
|
|
47
|
+
BranchAncestry,
|
|
48
|
+
CommitMoveAction,
|
|
49
|
+
CommitMoveChecks,
|
|
50
|
+
ProposedCommitMove,
|
|
51
|
+
)
|
|
52
|
+
from basstler.stack.model import Stack
|
|
53
|
+
from basstler.stack.settings import Configuration
|
|
54
|
+
from basstler.standard_streams import StandardStreamHandler
|
|
55
|
+
from basstler.text_file import TextFile
|
|
56
|
+
from basstler.upstream_reviews.action.branch import ActionBranch
|
|
57
|
+
from basstler.upstream_reviews.action.open_pull_requests import (
|
|
58
|
+
OpenPullRequestsAnswer,
|
|
59
|
+
OpenPullRequestsRequest,
|
|
60
|
+
UpstreamPullRequests,
|
|
61
|
+
)
|
|
62
|
+
from basstler.upstream_reviews.action.read import ActionRead
|
|
63
|
+
|
|
64
|
+
logger = StandardStreamHandler.logger_for(__name__)
|
|
65
|
+
"""
|
|
66
|
+
This module's logger, which is also what its command prints through.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True)
|
|
71
|
+
class MaintenancePass:
|
|
72
|
+
"""
|
|
73
|
+
What one run has resolved so far, built lazily as a command asks for it.
|
|
74
|
+
|
|
75
|
+
Every command that needs the stack derives it from a board it exports itself, so no
|
|
76
|
+
command depends on a file an earlier one wrote or a later one discarded.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
configuration: Configuration
|
|
80
|
+
"""
|
|
81
|
+
The resolved configuration naming both repositories and every label.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
git: GitCommandRunner
|
|
85
|
+
"""
|
|
86
|
+
The runner every git command goes through.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
board: Path
|
|
90
|
+
"""
|
|
91
|
+
Where :class:`BoardCommand` writes the board for a person to read; no command derives
|
|
92
|
+
its stack from it, and a whole pass discards it.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
upstream_read: UpstreamReadRoute = UpstreamReadRoute.DIRECT
|
|
96
|
+
"""
|
|
97
|
+
How this run reads the upstream's open pull requests.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
action_timeout: float = 480
|
|
101
|
+
"""
|
|
102
|
+
How many seconds a read through the fork's Action waits for its run.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
closing_follow_ups: LandedClosingFollowUps = LandedClosingFollowUps()
|
|
106
|
+
"""
|
|
107
|
+
What a whole pass runs after closing pull requests whose work landed.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def full_report(self) -> Path:
|
|
112
|
+
"""
|
|
113
|
+
Where a whole pass writes everything it did, beside :attr:`board`.
|
|
114
|
+
"""
|
|
115
|
+
return self.board.with_name(RepositoryStateLocation.MAINTENANCE_REPORT.name)
|
|
116
|
+
|
|
117
|
+
def fork(self) -> GitHubRepository:
|
|
118
|
+
""":return: The fork, as this run's credential can read and write it."""
|
|
119
|
+
return GitHubRepository.from_environment(self.configuration.fork_repository)
|
|
120
|
+
|
|
121
|
+
def upstream(self) -> PullRequestReader:
|
|
122
|
+
""":return: The upstream, as this run's credential can read it."""
|
|
123
|
+
return GitHubRepository.from_environment(self.configuration.upstream_repository)
|
|
124
|
+
|
|
125
|
+
def upstream_pull_requests(self) -> UpstreamPullRequests:
|
|
126
|
+
"""
|
|
127
|
+
:return: The upstream's open pull requests opened from the fork's branches, read
|
|
128
|
+
the way :attr:`upstream_read` names; none for a project with no upstream.
|
|
129
|
+
:raises ActionUnavailable: If that is the fork's Action and it cannot answer.
|
|
130
|
+
"""
|
|
131
|
+
fork = self.configuration.fork_repository
|
|
132
|
+
if not self.configuration.has_upstream:
|
|
133
|
+
logger.warning(MaintenanceNotice.NO_UPSTREAM)
|
|
134
|
+
return UpstreamPullRequests(fork, {})
|
|
135
|
+
if self.upstream_read is UpstreamReadRoute.DIRECT:
|
|
136
|
+
return UpstreamPullRequests.from_api_records(
|
|
137
|
+
self.upstream().open_pull_requests(), fork
|
|
138
|
+
)
|
|
139
|
+
read = ActionRead(
|
|
140
|
+
RemoteBranch(
|
|
141
|
+
GitHubRemote(self.git, self.configuration.fork_remote),
|
|
142
|
+
ActionBranch.NAME,
|
|
143
|
+
),
|
|
144
|
+
OpenPullRequestsRequest.fresh(self.configuration.upstream_repository, fork),
|
|
145
|
+
GitHubRestClient(),
|
|
146
|
+
answer_type=OpenPullRequestsAnswer,
|
|
147
|
+
)
|
|
148
|
+
return read.wait(self.action_timeout, read.send()).upstream_pull_requests
|
|
149
|
+
|
|
150
|
+
def export_board(self) -> BoardExport:
|
|
151
|
+
""":return: The fork's open pull requests, each with the upstream pull request
|
|
152
|
+
reviewing it and the verdict over its head's checks."""
|
|
153
|
+
fork = self.fork()
|
|
154
|
+
upstream_pull_requests = self.upstream_pull_requests()
|
|
155
|
+
return BoardExport.from_api_records(
|
|
156
|
+
fork.open_pull_requests(), upstream_pull_requests, fork
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def fresh_stack(self) -> Stack:
|
|
160
|
+
""":return: The stack derived from a board exported just now, never from a file
|
|
161
|
+
an earlier command left behind."""
|
|
162
|
+
return Stack.from_pull_requests(list(self.export_board().pull_requests))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class PreparationKey(StrEnum):
|
|
166
|
+
"""
|
|
167
|
+
The keys of the document :class:`PrepareCommand` prints.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
REPARENTS = "reparents"
|
|
171
|
+
"""
|
|
172
|
+
The pull requests whose base the session retargets before the pass.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
TO_SUMMARIZE = "to_summarize"
|
|
176
|
+
"""
|
|
177
|
+
The context of every branch whose upstream summary the session writes.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@dataclass(frozen=True)
|
|
182
|
+
class MaintenanceCommand(Command):
|
|
183
|
+
"""
|
|
184
|
+
One command this executor answers.
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
@abstractmethod
|
|
188
|
+
def run(
|
|
189
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
190
|
+
) -> StackExitCode:
|
|
191
|
+
"""
|
|
192
|
+
Perform the command.
|
|
193
|
+
|
|
194
|
+
:param maintenance: What this run has resolved.
|
|
195
|
+
:param arguments: The parsed command line.
|
|
196
|
+
:return: The process exit code.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@dataclass(frozen=True)
|
|
201
|
+
class BoardCommand(MaintenanceCommand):
|
|
202
|
+
"""
|
|
203
|
+
Fetches the fork's open pull requests and exports them as the board, each with the
|
|
204
|
+
upstream pull request reviewing it and the verdict over its head's checks.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
@classproperty
|
|
208
|
+
def description(cls) -> str:
|
|
209
|
+
"""
|
|
210
|
+
What it does, as ``--help`` puts it.
|
|
211
|
+
"""
|
|
212
|
+
return (
|
|
213
|
+
"export the fork's open pull requests, with their upstream review and "
|
|
214
|
+
"checks"
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
def declare_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
218
|
+
""":param parser: The subparser to declare ``--write`` on."""
|
|
219
|
+
parser.add_argument(
|
|
220
|
+
"--write",
|
|
221
|
+
action="store_true",
|
|
222
|
+
help="write board.json rather than printing the export",
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
def run(
|
|
226
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
227
|
+
) -> StackExitCode:
|
|
228
|
+
""":param maintenance: What this run has resolved.
|
|
229
|
+
:param arguments: The parsed command line.
|
|
230
|
+
:return: The process exit code."""
|
|
231
|
+
export = maintenance.export_board()
|
|
232
|
+
if not arguments.write:
|
|
233
|
+
logger.info(export.as_json())
|
|
234
|
+
return StackExitCode.SUCCESS
|
|
235
|
+
written_to = export.write(maintenance.board)
|
|
236
|
+
logger.info(f"{len(export.pull_requests)} open pull request(s) -> {written_to}")
|
|
237
|
+
return StackExitCode.SUCCESS
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class StackScopeArgument:
|
|
241
|
+
"""
|
|
242
|
+
Declares the ``--stacked-on`` argument of a command that passes over every branch,
|
|
243
|
+
or only over one branch's stack.
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
def declare_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
247
|
+
""":param parser: The subparser to declare ``--stacked-on`` on."""
|
|
248
|
+
parser.add_argument(
|
|
249
|
+
"--stacked-on",
|
|
250
|
+
help=(
|
|
251
|
+
"pass only over this branch's stack: the branch, the branches it is "
|
|
252
|
+
"stacked on and the branches stacked on it"
|
|
253
|
+
),
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@dataclass(frozen=True)
|
|
258
|
+
class PrepareCommand(StackScopeArgument, MaintenanceCommand):
|
|
259
|
+
"""
|
|
260
|
+
Exports the board and lists everything a session does before the pass: the bases
|
|
261
|
+
to retarget and the upstream summaries to write.
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
@classproperty
|
|
265
|
+
def description(cls) -> str:
|
|
266
|
+
"""
|
|
267
|
+
What it does, as ``--help`` puts it.
|
|
268
|
+
"""
|
|
269
|
+
return (
|
|
270
|
+
"export the board, then list the reparents to make and what each "
|
|
271
|
+
"upstream summary to write is written from"
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
def run(
|
|
275
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
276
|
+
) -> StackExitCode:
|
|
277
|
+
""":param maintenance: What this run has resolved.
|
|
278
|
+
:param arguments: The parsed command line.
|
|
279
|
+
:return: The process exit code."""
|
|
280
|
+
stack = maintenance.fresh_stack().scoped_to(arguments.stacked_on)
|
|
281
|
+
contexts = PromotionContextReader(
|
|
282
|
+
stack, maintenance.git, maintenance.fork()
|
|
283
|
+
).read()
|
|
284
|
+
document = {
|
|
285
|
+
PreparationKey.REPARENTS: [asdict(entry) for entry in stack.reparents()],
|
|
286
|
+
PreparationKey.TO_SUMMARIZE: [asdict(context) for context in contexts],
|
|
287
|
+
}
|
|
288
|
+
logger.info(json.dumps(document, ensure_ascii=False, default=str))
|
|
289
|
+
return StackExitCode.SUCCESS
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@dataclass(frozen=True)
|
|
293
|
+
class FastForwardCommand(MaintenanceCommand):
|
|
294
|
+
"""
|
|
295
|
+
Moves the fork's base branch onto the upstream, refusing to force.
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
@classproperty
|
|
299
|
+
def description(cls) -> str:
|
|
300
|
+
"""
|
|
301
|
+
What it does, as ``--help`` puts it.
|
|
302
|
+
"""
|
|
303
|
+
return "move the fork's base branch onto the upstream"
|
|
304
|
+
|
|
305
|
+
def run(
|
|
306
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
307
|
+
) -> StackExitCode:
|
|
308
|
+
""":param maintenance: What this run has resolved.
|
|
309
|
+
:param arguments: The parsed command line.
|
|
310
|
+
:return: The process exit code."""
|
|
311
|
+
report = MaintenanceReport(
|
|
312
|
+
fast_forward=fast_forward(maintenance.configuration, maintenance.git)
|
|
313
|
+
)
|
|
314
|
+
report.print_summary()
|
|
315
|
+
return report.exit_code
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
@dataclass(frozen=True)
|
|
319
|
+
class RestackCommand(MaintenanceCommand):
|
|
320
|
+
"""
|
|
321
|
+
Integrates every moved parent and publishes what merged cleanly.
|
|
322
|
+
"""
|
|
323
|
+
|
|
324
|
+
@classproperty
|
|
325
|
+
def description(cls) -> str:
|
|
326
|
+
"""
|
|
327
|
+
What it does, as ``--help`` puts it.
|
|
328
|
+
"""
|
|
329
|
+
return "integrate every moved parent and publish the result"
|
|
330
|
+
|
|
331
|
+
def declare_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
332
|
+
""":param parser: The subparser to declare ``--stacked-on`` on."""
|
|
333
|
+
parser.add_argument(
|
|
334
|
+
"--stacked-on",
|
|
335
|
+
help=(
|
|
336
|
+
"carry only this branch into what is stacked on it, leaving the rest "
|
|
337
|
+
"of the board alone and handing any collision back rather than "
|
|
338
|
+
"reporting it to the branch's owner"
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
def run(
|
|
343
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
344
|
+
) -> StackExitCode:
|
|
345
|
+
""":param maintenance: What this run has resolved.
|
|
346
|
+
:param arguments: The parsed command line.
|
|
347
|
+
:return: The process exit code."""
|
|
348
|
+
stack = maintenance.fresh_stack()
|
|
349
|
+
report = MaintenanceReport(
|
|
350
|
+
restacked=tuple(
|
|
351
|
+
restack(
|
|
352
|
+
stack, maintenance.git, maintenance.fork(), arguments.stacked_on
|
|
353
|
+
)
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
if not report.restacked:
|
|
357
|
+
logger.info(RestackCommand.nothing_to_restack(arguments.stacked_on))
|
|
358
|
+
report.print_summary()
|
|
359
|
+
return report.exit_code
|
|
360
|
+
|
|
361
|
+
@staticmethod
|
|
362
|
+
def nothing_to_restack(stacked_on: str | None) -> str:
|
|
363
|
+
"""
|
|
364
|
+
:param stacked_on: The branch whose stack was asked for, ``None`` for every
|
|
365
|
+
branch.
|
|
366
|
+
:return: The line saying the restack had no branch to carry anything into.
|
|
367
|
+
"""
|
|
368
|
+
if stacked_on is None:
|
|
369
|
+
return "no open pull request needs restacking"
|
|
370
|
+
return f"no open pull request is stacked on {stacked_on}; nothing to carry"
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
@dataclass(frozen=True)
|
|
374
|
+
class PushCommand(MaintenanceCommand):
|
|
375
|
+
"""
|
|
376
|
+
Publishes the checked-out branch to the same branch on the fork, only once the move
|
|
377
|
+
checks a restack's push is put through find it clear.
|
|
378
|
+
"""
|
|
379
|
+
|
|
380
|
+
@classproperty
|
|
381
|
+
def description(cls) -> str:
|
|
382
|
+
"""
|
|
383
|
+
What it does, as ``--help`` puts it.
|
|
384
|
+
"""
|
|
385
|
+
return (
|
|
386
|
+
"publish the checked-out branch to the fork, unless the move checks "
|
|
387
|
+
"refuse it"
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
def run(
|
|
391
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
392
|
+
) -> StackExitCode:
|
|
393
|
+
""":param maintenance: What this run has resolved.
|
|
394
|
+
:param arguments: The parsed command line.
|
|
395
|
+
:return: The process exit code: success only when the branch was published.
|
|
396
|
+
:raises GitCommandFailed: If the fork rejects the push."""
|
|
397
|
+
git = maintenance.git
|
|
398
|
+
stack = maintenance.fresh_stack()
|
|
399
|
+
branch = git.checked_out_branch()
|
|
400
|
+
fork_remote = stack.configuration.fork_remote
|
|
401
|
+
checks = CommitMoveChecks(
|
|
402
|
+
stack=stack,
|
|
403
|
+
checked_out_branch=branch,
|
|
404
|
+
is_ancestor=BranchAncestry(stack.configuration, git).is_ancestor,
|
|
405
|
+
)
|
|
406
|
+
verdict = checks.print_verdict(
|
|
407
|
+
ProposedCommitMove(
|
|
408
|
+
action=CommitMoveAction.PUSH,
|
|
409
|
+
source=branch,
|
|
410
|
+
destination=branch,
|
|
411
|
+
destination_remote=fork_remote,
|
|
412
|
+
)
|
|
413
|
+
)
|
|
414
|
+
if verdict is not StackExitCode.SUCCESS:
|
|
415
|
+
return verdict
|
|
416
|
+
git.push(
|
|
417
|
+
ProposedPush(remote=fork_remote, refspec=f"{branch}:{branch}")
|
|
418
|
+
).raise_if_failed()
|
|
419
|
+
logger.info(f"pushed {branch} to {fork_remote}/{branch}")
|
|
420
|
+
return StackExitCode.SUCCESS
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
@dataclass(frozen=True)
|
|
424
|
+
class PromoteCommand(MaintenanceCommand):
|
|
425
|
+
"""
|
|
426
|
+
Records the upstream link on every branch ready to be promoted, and keeps every
|
|
427
|
+
in-review label in step with the upstream.
|
|
428
|
+
"""
|
|
429
|
+
|
|
430
|
+
@classproperty
|
|
431
|
+
def description(cls) -> str:
|
|
432
|
+
"""
|
|
433
|
+
What it does, as ``--help`` puts it.
|
|
434
|
+
"""
|
|
435
|
+
return "record the upstream link on every promotable branch"
|
|
436
|
+
|
|
437
|
+
def declare_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
438
|
+
""":param parser: The subparser to declare ``--summaries`` on."""
|
|
439
|
+
parser.add_argument(
|
|
440
|
+
"--summaries",
|
|
441
|
+
type=Path,
|
|
442
|
+
help=(
|
|
443
|
+
"a JSON document keyed by fork pull request number, each entry giving "
|
|
444
|
+
"the 'points' and optionally the 'title' its upstream pull request "
|
|
445
|
+
"opens with"
|
|
446
|
+
),
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
def run(
|
|
450
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
451
|
+
) -> StackExitCode:
|
|
452
|
+
""":param maintenance: What this run has resolved.
|
|
453
|
+
:param arguments: The parsed command line.
|
|
454
|
+
:return: The process exit code."""
|
|
455
|
+
stack = maintenance.fresh_stack()
|
|
456
|
+
fork = maintenance.fork()
|
|
457
|
+
report = MaintenanceReport(
|
|
458
|
+
promoted=tuple(
|
|
459
|
+
promote(stack, fork, PromotionSummaries.read_from(arguments.summaries))
|
|
460
|
+
),
|
|
461
|
+
promotion_labels_cleared=tuple(clear_spent_promotion_labels(stack, fork)),
|
|
462
|
+
upstream_pull_request_synchronization_changes=tuple(
|
|
463
|
+
UpstreamPullRequestSynchronization(stack, fork).apply()
|
|
464
|
+
),
|
|
465
|
+
)
|
|
466
|
+
report.print_summary()
|
|
467
|
+
return report.exit_code
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
@dataclass(frozen=True)
|
|
471
|
+
class ChecksCommand(MaintenanceCommand):
|
|
472
|
+
"""
|
|
473
|
+
Exports the board and reports the verdict over every open branch's checks.
|
|
474
|
+
"""
|
|
475
|
+
|
|
476
|
+
@classproperty
|
|
477
|
+
def description(cls) -> str:
|
|
478
|
+
"""
|
|
479
|
+
What it does, as ``--help`` puts it.
|
|
480
|
+
"""
|
|
481
|
+
return (
|
|
482
|
+
"report how many open branches' checks pass, run or fail, naming the rest"
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
def run(
|
|
486
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
487
|
+
) -> StackExitCode:
|
|
488
|
+
""":param maintenance: What this run has resolved.
|
|
489
|
+
:param arguments: The parsed command line.
|
|
490
|
+
:return: The process exit code."""
|
|
491
|
+
logger.info("\n".join(CheckOverview(maintenance.fresh_stack()).as_lines()))
|
|
492
|
+
maintenance.board.unlink(missing_ok=True)
|
|
493
|
+
return StackExitCode.SUCCESS
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
@dataclass(frozen=True)
|
|
497
|
+
class RunReportCommand(StackScopeArgument, MaintenanceCommand):
|
|
498
|
+
"""
|
|
499
|
+
Performs the whole pass and reports it as one document.
|
|
500
|
+
"""
|
|
501
|
+
|
|
502
|
+
@classproperty
|
|
503
|
+
def description(cls) -> str:
|
|
504
|
+
"""
|
|
505
|
+
What it does, as ``--help`` puts it.
|
|
506
|
+
"""
|
|
507
|
+
return "perform the whole pass and report it"
|
|
508
|
+
|
|
509
|
+
def declare_arguments(self, parser: argparse.ArgumentParser) -> None:
|
|
510
|
+
""":param parser: The subparser to declare ``--json``, ``--stacked-on`` and the
|
|
511
|
+
promotion's own arguments on."""
|
|
512
|
+
super().declare_arguments(parser)
|
|
513
|
+
PromoteCommand().declare_arguments(parser)
|
|
514
|
+
parser.add_argument(
|
|
515
|
+
"--json",
|
|
516
|
+
action="store_true",
|
|
517
|
+
help="emit the machine-readable document rather than the finish summary",
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
def run(
|
|
521
|
+
self, maintenance: MaintenancePass, arguments: argparse.Namespace
|
|
522
|
+
) -> StackExitCode:
|
|
523
|
+
"""
|
|
524
|
+
:param maintenance: What this run has resolved.
|
|
525
|
+
:param arguments: The parsed command line.
|
|
526
|
+
:return: The process exit code.
|
|
527
|
+
"""
|
|
528
|
+
return self.perform(
|
|
529
|
+
maintenance,
|
|
530
|
+
as_json=arguments.json,
|
|
531
|
+
summaries=PromotionSummaries.read_from(arguments.summaries),
|
|
532
|
+
stacked_on=arguments.stacked_on,
|
|
533
|
+
).exit_code
|
|
534
|
+
|
|
535
|
+
def perform(
|
|
536
|
+
self,
|
|
537
|
+
maintenance: MaintenancePass,
|
|
538
|
+
as_json: bool,
|
|
539
|
+
summaries: PromotionSummaries,
|
|
540
|
+
stacked_on: str | None = None,
|
|
541
|
+
) -> MaintenanceReport:
|
|
542
|
+
"""
|
|
543
|
+
Export the board, perform every step of the pass, write the whole report and
|
|
544
|
+
print its summary, then discard the board.
|
|
545
|
+
|
|
546
|
+
The board is a snapshot of one moment's open pull requests, and a stale one read
|
|
547
|
+
by a later run is worse than none at all - so a whole pass begins by exporting
|
|
548
|
+
one and ends without it.
|
|
549
|
+
|
|
550
|
+
The checks on the board are those on each branch's tip as the pass found it, so
|
|
551
|
+
what an earlier pass pushed has finished being checked by now; what this pass
|
|
552
|
+
pushes is read by the next.
|
|
553
|
+
|
|
554
|
+
:param maintenance: What this run has resolved.
|
|
555
|
+
:param as_json: Whether to print the machine-readable document rather than the
|
|
556
|
+
finish summary.
|
|
557
|
+
:param summaries: What each upstream pull request opens with, where anybody wrote
|
|
558
|
+
it.
|
|
559
|
+
:param stacked_on: The branch whose stack to pass over, or ``None`` for every
|
|
560
|
+
branch.
|
|
561
|
+
:return: What the pass did.
|
|
562
|
+
"""
|
|
563
|
+
stack = maintenance.fresh_stack().scoped_to(stacked_on)
|
|
564
|
+
fork = maintenance.fork()
|
|
565
|
+
fast_forward_report = fast_forward(stack.configuration, maintenance.git)
|
|
566
|
+
restacked = restack(stack, maintenance.git, fork)
|
|
567
|
+
promoted = promote(stack, fork, summaries)
|
|
568
|
+
labels_cleared = clear_spent_promotion_labels(stack, fork)
|
|
569
|
+
synchronization = UpstreamPullRequestSynchronization(stack, fork).apply()
|
|
570
|
+
closed_as_landed = LandedPullRequestClosing(stack, fork).apply()
|
|
571
|
+
closing_follow_ups = maintenance.closing_follow_ups.respond_to_closing(
|
|
572
|
+
closed_as_landed
|
|
573
|
+
)
|
|
574
|
+
report = MaintenanceReport.of_pass(
|
|
575
|
+
stack,
|
|
576
|
+
fast_forward_report,
|
|
577
|
+
restacked,
|
|
578
|
+
promoted,
|
|
579
|
+
labels_cleared,
|
|
580
|
+
synchronization,
|
|
581
|
+
closed_as_landed,
|
|
582
|
+
closing_follow_ups,
|
|
583
|
+
)
|
|
584
|
+
maintenance.board.unlink(missing_ok=True)
|
|
585
|
+
TextFile(maintenance.full_report).write(report.as_json() + "\n")
|
|
586
|
+
if as_json:
|
|
587
|
+
logger.info(report.as_json())
|
|
588
|
+
return report
|
|
589
|
+
logger.info(FinishSummary(report, stack, maintenance.full_report).as_markdown())
|
|
590
|
+
return report
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
# Built now rather than on first use, so a command that cannot say what it is called is
|
|
594
|
+
# refused as this module is imported.
|
|
595
|
+
MaintenanceCommand.every_command()
|