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
CI / tests (pull_request) Successful in 5m4s
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user