Answer stability round 1: 1 🔴, 13 🟡 (1 misread); end a detail only at a ### <ID>. heading, print the whole help, refuse an empty bullet, an unreadable changelog and ### categories under Unreleased, take a heading saying unreleased as the section, and test one behaviour each; the README module map is left as it is, as the PR says
This commit is contained in:
+16
-9
@@ -5,13 +5,15 @@ from release_plan.todo_table import cells, DETAILS, items_table, Table
|
||||
from failure import Failure
|
||||
from release_plan.ranking import stated
|
||||
|
||||
# A line that would end the item's detail, or open another one, inside ## Details.
|
||||
HEADING = re.compile(r"^#{1,3} ", re.M)
|
||||
# A line that would end ## Details (##) or could open another item's detail (###).
|
||||
HEADING = re.compile(r"^#{2,3} ", re.M)
|
||||
UNRELEASED = "## Unreleased"
|
||||
# The changelog's section for news not yet released: ## Unreleased, or a release heading such as `## 0.6.0 (unreleased)`.
|
||||
UNRELEASED_SECTION = re.compile(r"^## .*unreleased.*\n+", re.M | re.I)
|
||||
|
||||
|
||||
def added(todo: str, named: dict[str, str], detail: str) -> tuple[int, str] | Failure:
|
||||
"""todo with an item filed under Next ID, and that ID; named holds its cells by column name, its Item cell a plain tagline."""
|
||||
"""todo with an item filed under Next ID, and that ID; named holds its cells by column name, its Item cell the tagline, bold or not."""
|
||||
next_id = stated(todo, "Next ID")
|
||||
if isinstance(next_id, Failure):
|
||||
return next_id
|
||||
@@ -21,7 +23,7 @@ def added(todo: str, named: dict[str, str], detail: str) -> tuple[int, str] | Fa
|
||||
if "\n" in tagline:
|
||||
return Failure("the tagline holds a line break; keep it on one line")
|
||||
if HEADING.search(detail):
|
||||
return Failure("the detail holds a markdown heading, which would split ## Details; drop the #s")
|
||||
return Failure("the detail holds a ## or ### heading, which would split ## Details; use #### or drop the #s")
|
||||
id_ = int(next_id)
|
||||
lines = re.sub(r"^`Next ID = [0-9]+`$", f"`Next ID = {id_ + 1}`", todo, count=1, flags=re.M).split("\n")
|
||||
table = held_table(lines)
|
||||
@@ -58,19 +60,24 @@ def finished(todo: str, id_: int) -> str | Failure:
|
||||
section = DETAILS.search(text)
|
||||
if section is None:
|
||||
return text
|
||||
body = re.sub(rf"^### {id_}\. .*?(?=^### |\Z)", "", section.group(1), count=1, flags=re.M | re.S)
|
||||
body = re.sub(rf"^### {id_}\. .*?(?=^### \d+\. |\Z)", "", section.group(1), count=1, flags=re.M | re.S)
|
||||
return text[:section.start(1)] + body + text[section.end(1):]
|
||||
|
||||
|
||||
def with_bullet(changelog: str, bullet: str) -> str | Failure:
|
||||
"""changelog with bullet first under ## Unreleased, which goes above the first release where missing; a new changelog where changelog is empty."""
|
||||
line = "- " + bullet.strip().removeprefix("- ")
|
||||
if "\n" in line:
|
||||
"""changelog with bullet first under its UNRELEASED_SECTION, adding ## Unreleased above the first release heading where it has none; a new changelog where changelog is empty. Failure where that section holds ### subsections, since the bullet belongs under one of them."""
|
||||
text = bullet.strip().removeprefix("- ").strip()
|
||||
if not text:
|
||||
return Failure("the changelog bullet is empty")
|
||||
if "\n" in text:
|
||||
return Failure("the changelog bullet holds a line break; keep it on one line")
|
||||
line = f"- {text}"
|
||||
if not changelog.strip():
|
||||
return f"# Changelog\n\n{UNRELEASED}\n\n{line}\n"
|
||||
if section := re.search(rf"^{UNRELEASED}\n+", changelog, re.M):
|
||||
if section := UNRELEASED_SECTION.search(changelog):
|
||||
rest = changelog[section.end():]
|
||||
if re.search(r"^### ", re.split(r"^## ", rest, maxsplit=1, flags=re.M)[0], re.M):
|
||||
return Failure(f"CHANGELOG.md's {section.group().strip()} holds ### subsections; add the bullet under the right one by hand, then finish with --no-changelog")
|
||||
return changelog[:section.end()] + line + "\n" + ("" if rest.startswith("- ") or not rest else "\n") + rest
|
||||
if release := re.search(r"^## ", changelog, re.M):
|
||||
return changelog[:release.start()] + f"{UNRELEASED}\n\n{line}\n\n" + changelog[release.start():]
|
||||
|
||||
Reference in New Issue
Block a user