Let a project's config name a working branch per epic that chunks branch off and merge into
CI / tests (pull_request) Successful in 5m4s

This commit is contained in:
Lilleman
2026-11-20 19:32:59 +01:00
parent 9531e5c337
commit 72a4d346d7
33 changed files with 991 additions and 56 deletions
+16 -2
View File
@@ -103,6 +103,20 @@ it is true.
`chunk-pr merge` leaves the pull request ready and says it awaits a person's merge. `project-config merge`
prints chunk or human; the full listing shows the setting only where it is human.
`epic-branch` is an optional setting: a template that names the working branch of the Jira epic `plan`
names, with {epic} for the epic's key, such as `epic-branch = "{epic}"` or "epic/{epic}". Each chunk then
branches off that branch, and `chunk-pr` opens its pull request into it and merges it there without a
person, whatever `merge` and `wait-for-approval` say: those guard the default branch. `chunk-preflight`
makes the branch on origin off the default branch, or merges the default branch into it, and stops where
that merge conflicts, which a person resolves. `chunk-pr open-epic` opens the pull request from the branch
into the default branch, which a person merges. Left out, each chunk merges into the default branch.
`review-request-comment` is an optional setting, one line of text: the comment that asks the project's
auto-reviewer for a review, such as "@reviewbot review", for a reviewer that on its own reviews only
pull requests into the default branch. `chunk-pr ready` and `chunk-pr push` post it on a pull request
into the epic's working branch. It requires `epic-branch`. Left out, no comment is posted.
Each of the two is printed with the others only where it is set.
`tooling-on-host` is an optional setting, true or false: whether the loop may run the project's language
runtime, package manager, tests and task runner directly on the host, for a project with no container
setup. Left out, it is false, and they run through the project's container setup.
@@ -151,12 +165,12 @@ and its commits and pull request are titled "ABC-123 - …".
Exit 1, naming each fault on stderr, where no config names the checkout, or its config leaves out a
setting, names an unknown one, misspells a path, a language or a template, sets `coding-conventions` to anything but a list of paths, sets `wait-for-approval` or
`tooling-on-host` to anything but true or false, sets `merge` to anything but chunk or human, sets `notifier` to anything but mattermost or slack or
`tooling-on-host` to anything but true or false, sets `merge` to anything but chunk or human, sets `epic-branch` to anything but a branch name with one {epic}, sets `review-request-comment` to anything but one line of text or without `epic-branch`, sets `notifier` to anything but mattermost or slack or
without `env-file`, sets `jira-finish-transition` or `jira-finish-status` to anything but a name, without the other or
without a `plan` in Jira, names a Jira `plan` and leaves out `jira-score-formula` or `jira-score-bar`, sets
one of those two without a `plan` in Jira, sets the formula to one that doesn't parse or the bar to anything
but a number, sets `readability-floor` to anything but a number
from 1 to 10, sets `parallel-chunks` to anything but a whole number of 1 or more, or sets `jira-finding-type` to anything but a name or without a `plan` in Jira, and where `coding-conventions`, `env-file`, `jira-finish-transition`, `jira-finish-status`, `notifier` or `touch-predictions` is asked for and not set. No path setting has a default.
from 1 to 10, sets `parallel-chunks` to anything but a whole number of 1 or more, or sets `jira-finding-type` to anything but a name or without a `plan` in Jira, and where `coding-conventions`, `env-file`, `epic-branch`, `jira-finish-transition`, `jira-finish-status`, `notifier`, `review-request-comment` or `touch-predictions` is asked for and not set. No path setting has a default.
"""
import pathlib
import sys
+15
View File
@@ -50,6 +50,9 @@ LANGUAGE = "language"
COMMIT_TITLE = "commit-title"
PULL_REQUEST_TITLE = "pull-request-title"
BRANCH = "branch"
# Two optional settings. `epic-branch` names the working branch that an epic's chunks branch off and merge into, `{epic}` standing for the epic's key (docs/decisions.md → `epic-branch: an epic's chunks branch off and merge into a working branch …`). `review-request-comment` is the comment `chunk-pr` posts on a pull request into that branch, to ask a reviewer that reviews only pull requests into the default branch. Three readers, seated as the human who writes the config, a chunk's worker and one of a client's team, picked both spellings from four candidates each, 3-0: `merge-branch` and `working-branch` read as the chunk's own branch, and `base-branch` as replacing the default branch for the whole repo.
EPIC_BRANCH = "epic-branch"
REVIEW_REQUEST_COMMENT = "review-request-comment"
# An optional path setting: main's help says what it places.
TOUCH_PREDICTIONS = "touch-predictions"
# An optional setting: a list of paths, each spelt as SPELLING says, to the files that hold the team's own coding conventions, which each reviewer agent larv-review launches reads. Three readers, seated as the human who writes a client's config, picked the spelling 2-1 from four candidates, over a bare `conventions`, which they confused with `principles` and `working-rules`.
@@ -141,6 +144,10 @@ class ProjectConfig:
commit_title: str = templates.TITLE
pull_request_title: str = templates.TITLE
branch: str = templates.BRANCH
# The config's `epic-branch` template, or None where it sets none.
epic_branch: str | None = None
# The config's `review-request-comment`, or None where it sets none.
review_request_comment: str | None = None
# The config's `coding-conventions`, in its order; empty where it sets none.
coding_conventions: tuple[pathlib.Path, ...] = ()
# The epic whose child issues are the plan, where the config's `plan` names one.
@@ -237,6 +244,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
*(f"`{name}` is set, so `plan` must name a Jira epic" for name in JIRA_PLAN_ONLY if name in values and not epics["plan"]),
*(f"`plan` names a Jira epic, so `{name}` must be set, as `project-config --help` shows" for name in JIRA_SCORE if epics["plan"] and name not in values),
*finish_faults(values),
*([f"`{REVIEW_REQUEST_COMMENT}` is set, so `{EPIC_BRANCH}` must be set: the comment goes on pull requests into that branch"] if REVIEW_REQUEST_COMMENT in values and EPIC_BRANCH not in values else []),
*([f"`{JIRA_SCORE_FORMULA}` is {formula!r}: {fault}"] if JIRA_SCORE_FORMULA in values and (fault := formula_fault(formula)) else []),
*([f"`{JIRA_SCORE_BAR}` is {bar!r}, not a bare number, such as `{JIRA_SCORE_BAR} = 1`"] if JIRA_SCORE_BAR in values and bar_of(bar) is None else []),
]
@@ -359,6 +367,11 @@ def language_fault(value: object) -> str | None:
return None if named else 'not a language\'s English name in words of letters, such as "Swedish" or "Brazilian Portuguese"'
def comment_fault(value: object) -> str | None:
"""Why value is no comment to post on a pull request; None where it is one."""
return None if isinstance(value, str) and value.strip() and "\n" not in value else 'not one line of text, such as "@coderabbitai review"'
# Each one-value setting, in the order `project-config` lists them.
SCALARS = (
Scalar(WAIT_FOR_APPROVAL, "wait_for_approval", switch, lambda on: "true" if on else "false"),
@@ -371,6 +384,8 @@ SCALARS = (
Scalar(COMMIT_TITLE, "commit_title", text_read(templates.title_fault)),
Scalar(PULL_REQUEST_TITLE, "pull_request_title", text_read(templates.title_fault)),
Scalar(BRANCH, "branch", text_read(templates.branch_fault)),
Scalar(EPIC_BRANCH, "epic_branch", text_read(templates.epic_branch_fault)),
Scalar(REVIEW_REQUEST_COMMENT, "review_request_comment", text_read(comment_fault)),
Scalar(JIRA_FINDING_TYPE, "jira_finding_type", text_read(type_fault)),
)
OPTIONAL = tuple(sorted({CODING_CONVENTIONS, ENV_FILE, TOUCH_PREDICTIONS, *JIRA_PLAN_ONLY, *(scalar.name for scalar in SCALARS)}))
+21 -3
View File
@@ -6,6 +6,8 @@ import re
ID = "{id}"
SUMMARY = "{summary}"
# What an `epic-branch` template holds in place of the epic's key.
EPIC = "{epic}"
# What each setting holds where the config leaves it out: a bare summary, and the branch `CLAUDE.md` → "Git, commits, and PRs" names.
TITLE = SUMMARY
BRANCH = "item-{id}"
@@ -40,13 +42,29 @@ def branch_fault(template: object) -> str | None:
return f"not text such as \"feature/{ID}\""
if template.count(ID) != 1 or SUMMARY in template:
return f"without exactly one {ID}, or with a {SUMMARY}"
branch = template.replace(ID, "1")
parts = branch.split("/")
if not BRANCH_TEXT.fullmatch(branch) or branch.startswith("-") or ".." in branch or any(not part or part.startswith(".") or part.endswith((".", ".lock")) for part in parts):
if not git_accepts(template.replace(ID, "1")):
return f"not a branch name git accepts, of letters, digits and . _ / - around {ID}"
return None
def git_accepts(branch: str) -> bool:
return bool(BRANCH_TEXT.fullmatch(branch)) and not branch.startswith("-") and ".." not in branch and not any(not part or part.startswith(".") or part.endswith((".", ".lock")) for part in branch.split("/"))
def epic_branch_fault(template: object) -> str | None:
"""Why template is no `epic-branch` template; None where it is one. It needs the epic's key, or two epics would share a branch."""
if not isinstance(template, str) or template.count(EPIC) != 1:
return f"not text with exactly one {EPIC}, such as \"{EPIC}\" or \"epic/{EPIC}\""
if not git_accepts(template.replace(EPIC, "ABC-1")):
return f"not a branch name git accepts, of letters, digits and . _ / - around {EPIC}"
return None
def epic_branch(template: str, key: str) -> str:
"""The branch template names for the epic with the key key."""
return template.replace(EPIC, key)
def stray_brace(template: str) -> str | None:
stray = re.search(r"\{[^{}]*\}?|\}", PLACEHOLDER.sub("", template))
return f"with {stray[0]}, which is neither {ID} nor {SUMMARY}" if stray else None
+19 -1
View File
@@ -271,6 +271,24 @@ class LoadTest(ConfigCase):
assert isinstance(named, ProjectConfig), named
self.assertEqual(named.notifier, name)
def test_the_epic_branch_and_its_review_request_comment_are_optional(self) -> None:
self.write("acme", CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
assert isinstance(left_out, ProjectConfig), left_out
self.assertEqual((left_out.epic_branch, left_out.review_request_comment), (None, None))
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "epic/{epic}"\nreview-request-comment = "@coderabbitai review"\n')
named = load(self.checkout, self.checkout, self.home)
assert isinstance(named, ProjectConfig), named
self.assertEqual((named.epic_branch, named.review_request_comment), ("epic/{epic}", "@coderabbitai review"))
def test_an_epic_branch_without_the_epic_or_a_comment_without_an_epic_branch_fails_naming_it(self) -> None:
self.write("acme", CLIENT + 'epic-branch = "develop"\n')
self.assertIn("`epic-branch` is 'develop', not text with exactly one {epic}", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'review-request-comment = "@coderabbitai review"\n')
self.assertIn("`review-request-comment` is set, so `epic-branch` must be set", self.failure())
(self.home / ".claude-projects" / "acme" / "config.toml").write_text(CLIENT + 'epic-branch = "{epic}"\nreview-request-comment = " "\n')
self.assertIn("`review-request-comment` is ' ', not one line of text", self.failure())
def test_a_jira_plan_may_name_the_transition_and_status_that_finish_an_item(self) -> None:
self.write("acme", JIRA_CLIENT)
left_out = load(self.checkout, self.checkout, self.home)
@@ -545,7 +563,7 @@ class LoadTest(ConfigCase):
def test_the_failure_for_a_misplaced_env_file_and_a_missing_setting_names_both_and_lists_every_setting(self) -> None:
folder = self.write("acme", "".join(line + "\n" for line in CLIENT.splitlines() if not line.startswith("plan")) + 'env-file = "checkout:.env"\n')
self.assertEqual(self.failure(), f"{folder / 'config.toml'}: `plan` is missing; `env-file` is 'checkout:.env', not {OUTSIDE}. The settings are {', '.join(SETTINGS)}, and optionally branch, coding-conventions, commit-title, env-file, jira-finding-type, jira-finish-status, jira-finish-transition, jira-score-bar, jira-score-formula, language, merge, notifier, parallel-chunks, pull-request-title, readability-floor, tooling-on-host, touch-predictions and wait-for-approval.")
self.assertEqual(self.failure(), f"{folder / 'config.toml'}: `plan` is missing; `env-file` is 'checkout:.env', not {OUTSIDE}. The settings are {', '.join(SETTINGS)}, and optionally branch, coding-conventions, commit-title, env-file, epic-branch, jira-finding-type, jira-finish-status, jira-finish-transition, jira-score-bar, jira-score-formula, language, merge, notifier, parallel-chunks, pull-request-title, readability-floor, review-request-comment, tooling-on-host, touch-predictions and wait-for-approval.")
def test_two_configs_naming_one_checkout_fail_naming_both(self) -> None:
self.write("acme", CLIENT)
+12 -1
View File
@@ -1,6 +1,6 @@
import unittest
from project_config.templates import BARE, branch_fault, branch_fits, branch_of, fits, summary_of, title_fault, Titles
from project_config.templates import BARE, branch_fault, branch_fits, branch_of, epic_branch, epic_branch_fault, fits, summary_of, title_fault, Titles
class TitleTest(unittest.TestCase):
@@ -31,6 +31,17 @@ class TitleTest(unittest.TestCase):
with self.subTest(template):
self.assertIsNotNone(branch_fault(template))
def test_an_epic_branch_template_holds_one_epic_and_names_a_branch_git_accepts(self) -> None:
for template in ("{epic}", "epic/{epic}"):
with self.subTest(template):
self.assertIsNone(epic_branch_fault(template))
for template in ("develop", "{epic}/{epic}", "{id}", "epic {epic}", "-{epic}", "{epic}.lock", 3):
with self.subTest(template):
self.assertIsNotNone(epic_branch_fault(template))
def test_fills_an_epic_branch_with_the_epics_key(self) -> None:
self.assertEqual(epic_branch("epic/{epic}", "ABC-123"), "epic/ABC-123")
def test_fills_a_branch_with_the_items_id(self) -> None:
self.assertEqual(branch_of("item-{id}", 357), "item-357")
self.assertEqual(branch_of("feature/PAY-{id}", 357), "feature/PAY-357")