Answer product-owner round 1: 0 🔴, 2 🟡 (0 misread); count an untagged branch's unreleased commits from the commit that dated its heading, and drop the changelog's advice to restart loops

This commit is contained in:
2026-11-04 21:14:51 +01:00
parent 6f9155c1d0
commit 45007d54f2
6 changed files with 23 additions and 9 deletions
+9 -2
View File
@@ -18,7 +18,7 @@ class LastCut:
tag: str | None | Failure
# CHANGELOG.md's text, empty where the branch holds none.
changelog: str | Failure
# How many commits follow the tag, or make up the branch where it has none.
# How many commits follow the tag; on a branch with no tag, those after the commit that added the newest dated CHANGELOG.md heading, or all of them where it has none.
commits: int | Failure
# todo.md's text at the tag and at each later commit that changed it, oldest first, as named_releases reads them; where the branch has no tag, at each commit that changed it. Empty where the tags cannot be read.
todos_since: list[str] | Failure
@@ -93,13 +93,20 @@ class DefaultPlan:
def default_plan(root: str, ref: str) -> DefaultPlan:
"""What ref, the default branch as last fetched, holds for the pick, read in the checkout at root."""
tag = newest_release_tag(ref, root)
commits = tag if isinstance(tag, Failure) else commits_since(tag, ref, root)
changelog = file_at(ref, "CHANGELOG.md", root)
after = max(dated_headings(changelog), default=None) if tag is None else None
since = tag if after is None else heading_commit(after, ref, root)
commits = since if isinstance(since, Failure) else commits_since(since, ref, root)
reviewed = tag if isinstance(tag, Failure) else release_reviewed(tag, ref, root, after)
return DefaultPlan(file_at(ref, "todo.md", root), LastCut(tag, changelog, commits, todos_since(tag, ref, root), reviewed))
def heading_commit(release: tuple[int, int, int], ref: str, cwd: str) -> str | None | Failure:
"""The oldest commit on ref that added release's dated heading to CHANGELOG.md, which a branch with no tag counts the unreleased commits from; None where git finds none."""
added = git("log", "--reverse", "--format=%H", "-S", f"## {version(release)} - ", ref, "--", "CHANGELOG.md", cwd=cwd)
return added if isinstance(added, Failure) else next(iter(added.split()), None)
def release_reviewed(tag: str | None, ref: str, cwd: str, after: tuple[int, int, int] | None = None) -> bool | Failure:
"""Whether ref holds, after tag or in all where tag is None, a commit titled as a release review opens: `Release review of <release>`. Where after is given, the version a branch with no tag counts as cut, a title counts only where its release is later."""
titles = git("log", "--format=%s", f"{tag}..{ref}" if tag else ref, cwd=cwd)