Make chunk-pr merge wait for the human approval a project's config requires
CI / tests (pull_request) Failing after 3m11s

This commit is contained in:
2026-11-14 00:43:54 +01:00
parent 89a85f88df
commit 6cdbcbc08b
11 changed files with 205 additions and 16 deletions
+9 -3
View File
@@ -15,6 +15,8 @@ SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehensio
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
# The one setting a project may leave out: the file of KEY=value credentials its tools read. It has no default either: a project without it asks for no credentials, and never reads another project's.
ENV_FILE = "env-file"
# The other optional setting: whether `chunk-pr merge` waits for a human's approval of the pull request. It is a boolean, false where left out, so a project that doesn't set it merges as soon as its checks pass.
WAIT_FOR_APPROVAL = "wait-for-approval"
OUTSIDE = "a path that starts with / or ~/ and lies outside the checkout and the config's folder, so that no git remote receives the credentials"
# Where a project keeps a file, for a tool that reads it at a commit: a path from the checkout's top, as git names it; or, outside the checkout, the file itself, which the tool reads as it stands, since the checkout's commits hold no version of it.
@@ -30,6 +32,8 @@ class ProjectConfig:
paths: dict[str, pathlib.Path]
# The config's `env-file`, or None where it sets none.
env_file: pathlib.Path | None = None
# The config's `wait-for-approval`, false where it sets none.
wait_for_approval: bool = False
def tracked(self, setting: str) -> str | None:
"""setting's path from top, as git names a file in a commit; None where the config puts it outside the checkout, whose commits hold no version of it."""
@@ -61,15 +65,17 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
paths = {name: placed(values[name], top, file.parent, home) for name in SETTINGS if name in values}
env_file = anywhere(values.get(ENV_FILE), home)
misplaced = ENV_FILE in values and (env_file is None or lies_in(env_file, top, main, file.parent))
waits = values.get(WAIT_FOR_APPROVAL, False)
faults = [
*(f"`{name}` is missing" for name in SETTINGS if name not in values),
*(f"`{name}` is not a setting" for name in values if name not in (*SETTINGS, ENV_FILE)),
*(f"`{name}` is not a setting" for name in values if name not in (*SETTINGS, ENV_FILE, WAIT_FOR_APPROVAL)),
*(f"`{name}` is {values[name]!r}, not {SPELLING}" for name, path in paths.items() if path is None),
*([f"`{ENV_FILE}` is {values[ENV_FILE]!r}, not {OUTSIDE}"] if misplaced else []),
*([f"`{WAIT_FOR_APPROVAL}` is {waits!r}, not true or false"] if not isinstance(waits, bool) else []),
]
if faults:
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {ENV_FILE}.")
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file)
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {ENV_FILE} and {WAIT_FOR_APPROVAL}.")
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file, waits is True)
def lies_in(path: pathlib.Path, *places: pathlib.Path) -> bool: