Answer principles round 1: 2 🔴, 9 🟡 (0 misread); explicit record versions in place of the Confluence store's hidden state, the routing ruling filed as item 393 for 0.12.0, rule-hook catching heavy runs through uv, poetry, sudo and doas, one unreleased heading, one owner of the no-item message, typed Jira issues, a turn that gives its failure as a value, outcome tests for the Atlassian client, an Emptied reason type, an injected clock and git in touch-predictions, and paired record names
This commit is contained in:
+25
-20
@@ -91,6 +91,7 @@ from chunk_preflight.gathered import Forge
|
||||
from chunk_preflight.choices import forge_of
|
||||
from project_config.main import located
|
||||
from project_config.settings import ProjectConfig
|
||||
from plan_store.plans import says_no_item
|
||||
from project_config import templates
|
||||
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
@@ -331,13 +332,8 @@ def merged(run: Run, config: Config, sleep: typing.Callable[[float], None] = tim
|
||||
file = pathlib.Path(queue[0]) / QUEUE
|
||||
pull_request = Merging(forge, number, method, str(base), required, waits)
|
||||
while True:
|
||||
try:
|
||||
with turn(file, number, sleep):
|
||||
taken = merge_turn(pull_request, finishes, loaded, run, sleep)
|
||||
except Held as held:
|
||||
return Failure(f"the merge queue stayed held for {QUEUE_SECONDS // 60} minutes, last by pull request #{held.args[0] or '?'}, so this one took no turn; run chunk-pr merge again")
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot take a turn in the merge queue, {file}: {failure.strerror}")
|
||||
with turn(file, number, sleep) as untaken:
|
||||
taken = untaken or merge_turn(pull_request, finishes, loaded, run, sleep)
|
||||
if not isinstance(taken, AwaitsApproval):
|
||||
return taken if isinstance(taken, Failure) else taken + absent
|
||||
# Out of the queue, so the project's other chunks merge while this one waits.
|
||||
@@ -388,20 +384,28 @@ def unplanned(run: Run, finishes: typing.Sequence[list[str]]) -> str | Failure:
|
||||
absent = []
|
||||
for finish in finishes:
|
||||
shown = run([str(BIN / "todo-item"), "show", finish[0]])
|
||||
if isinstance(shown, Failure) and f"holds no item {finish[0]}" not in shown.reason:
|
||||
if isinstance(shown, Failure) and not says_no_item(shown.reason, finish[0]):
|
||||
return shown
|
||||
absent += [finish[0]] if isinstance(shown, Failure) else []
|
||||
return f" The plan held no item {', '.join(absent)} when merge began, so merge left the plan as it was there." if absent else ""
|
||||
|
||||
|
||||
class Held(Exception):
|
||||
"""Other merges kept the queue for QUEUE_SECONDS; the argument is the number of the pull request that held it last."""
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def turn(queue: pathlib.Path, number: str, sleep: typing.Callable[[float], None]) -> typing.Iterator[None]:
|
||||
"""Hold the project's merge queue as pull request number: wait until no other chunk-pr merge on this machine holds it, and free it on the way out, however that is. Raises Held where another one still holds it after QUEUE_SECONDS, and OSError where the file cannot be opened or locked."""
|
||||
fd = os.open(queue, os.O_RDWR | os.O_CREAT, 0o644)
|
||||
def turn(queue: pathlib.Path, number: str, sleep: typing.Callable[[float], None]) -> typing.Iterator[Failure | None]:
|
||||
"""Hold the project's merge queue as pull request number: wait until no other chunk-pr merge on this machine holds it, and free it on the way out, however that is. Gives None while it holds the queue; a Failure, without the queue, where another merge still holds it after QUEUE_SECONDS or the file cannot be opened or locked."""
|
||||
try:
|
||||
fd = os.open(queue, os.O_RDWR | os.O_CREAT, 0o644)
|
||||
except OSError as failure:
|
||||
yield Failure(f"cannot take a turn in the merge queue, {queue}: {failure.strerror}")
|
||||
return
|
||||
try:
|
||||
yield held_turn(fd, queue, number, sleep)
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
|
||||
def held_turn(fd: int, queue: pathlib.Path, number: str, sleep: typing.Callable[[float], None]) -> Failure | None:
|
||||
"""Lock the open queue file fd for pull request number and write its number there, for a merge that waits to name; None once held, else why it isn't."""
|
||||
try:
|
||||
for waited in range(0, QUEUE_SECONDS + 1, QUEUE_POLL_SECONDS):
|
||||
try:
|
||||
@@ -409,13 +413,14 @@ def turn(queue: pathlib.Path, number: str, sleep: typing.Callable[[float], None]
|
||||
break
|
||||
except BlockingIOError:
|
||||
if waited == QUEUE_SECONDS:
|
||||
raise Held(os.pread(fd, 20, 0).decode(errors="replace").strip()) from None
|
||||
holder = os.pread(fd, 20, 0).decode(errors="replace").strip()
|
||||
return Failure(f"the merge queue stayed held for {QUEUE_SECONDS // 60} minutes, last by pull request #{holder or '?'}, so this one took no turn; run chunk-pr merge again")
|
||||
sleep(QUEUE_POLL_SECONDS)
|
||||
os.ftruncate(fd, 0)
|
||||
os.pwrite(fd, number.encode(), 0)
|
||||
yield
|
||||
finally:
|
||||
os.close(fd)
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot take a turn in the merge queue, {queue}: {failure.strerror}")
|
||||
return None
|
||||
|
||||
|
||||
def levelled_and_finished(run: Run, base: str, finishes: typing.Sequence[list[str]], config: ProjectConfig) -> str | Failure:
|
||||
@@ -444,7 +449,7 @@ def levelled_and_finished(run: Run, base: str, finishes: typing.Sequence[list[st
|
||||
def finished(run: Run, branch: str, finish: list[str], config: ProjectConfig) -> Failure | None:
|
||||
"""Finish one plan item with `todo-item finish` and commit what that changed. An item the plan no longer holds was finished by an earlier run of merge, which may have stopped before its commit: so the plan and the changelog are committed either way."""
|
||||
shown = run([str(BIN / "todo-item"), "show", finish[0]])
|
||||
if isinstance(shown, Failure) and f"holds no item {finish[0]}" not in shown.reason:
|
||||
if isinstance(shown, Failure) and not says_no_item(shown.reason, finish[0]):
|
||||
return shown
|
||||
finishing = "" if isinstance(shown, Failure) else run([str(BIN / "todo-item"), "finish", *finish])
|
||||
if isinstance(finishing, Failure):
|
||||
|
||||
Reference in New Issue
Block a user