Count a dated CHANGELOG heading as cut without a tag, read only regular files in rule-hook, stamp asks in ISO UTC, give workers the reading rule, and record the 200k window's measurement

This commit is contained in:
2026-11-04 21:11:09 +01:00
parent b1bbc2490a
commit 5b1f903471
19 changed files with 176 additions and 81 deletions
+40 -14
View File
@@ -4,10 +4,10 @@ import re
from git_repo import commits_since, file_at, git, newest_release_tag
from failure import Failure
from todo_table import Item, items, next_item, release_of, renames
from todo_table import Item, items, next_item, release_of, renames, version
from markdown_text import sections
# The version a branch with no v* tag counts as cut: below every release, 0.0.0 included, so that every release todo.md names comes after it.
# The version a branch with no v* tag and no dated CHANGELOG.md heading counts as cut: below every release, 0.0.0 included, so that every release todo.md names comes after it.
BEFORE_FIRST_RELEASE = (-1, 0, 0)
@@ -94,14 +94,19 @@ 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)
reviewed = tag if isinstance(tag, Failure) else release_reviewed(tag, ref, root)
return DefaultPlan(file_at(ref, "todo.md", root), LastCut(tag, file_at(ref, "CHANGELOG.md", root), commits, todos_since(tag, ref, root), reviewed))
changelog = file_at(ref, "CHANGELOG.md", root)
after = max(dated_headings(changelog), default=None) if tag is None else None
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 release_reviewed(tag: str | None, ref: str, cwd: str) -> 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>`."""
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)
return titles if isinstance(titles, Failure) else any(title.startswith("Release review of ") for title in titles.splitlines())
if isinstance(titles, Failure):
return titles
reviews = [title.removeprefix("Release review of ") for title in titles.splitlines() if title.startswith("Release review of ")]
return any(after is None or (re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", review) and release_of(review) > after) for review in reviews)
def todos_since(tag: str | None | Failure, ref: str, cwd: str) -> list[str] | Failure:
@@ -130,23 +135,44 @@ def next_release(found: list[Item], cut: LastCut) -> Upcoming | Cut | Unknown:
"""The next release after cut, and whether work has landed towards it. found holds the plan's items.
Cut where the plan files items under the last cut's version or earlier, and Unknown where todo.md's texts since the cut cannot be read.
Where the branch has no tag, the cut counts as BEFORE_FIRST_RELEASE, so a release todo.md named whose items are all done still reads as the next release.
Where the branch has no tag, the cut is cut_version's, so a release todo.md named whose items are all done still reads as the next release.
"""
earliest = min((item.release for item in found), default=None)
untagged = cut.tag is None
cut_version = BEFORE_FIRST_RELEASE if untagged else version_of(cut.tag)
if cut_version is None:
version = cut_version(cut)
if version is None:
return Upcoming(earliest, True, landed(cut))
if earliest is not None and earliest <= cut_version:
if earliest is not None and earliest <= version:
return Cut(earliest)
named = named_releases(cut.todos_since)
if isinstance(named, Failure):
return Unknown()
after = {release for release in named if release > cut_version}
after = {release for release in named if release > version}
if earliest is not None:
after.add(earliest)
release = min(after, default=None)
return Upcoming(release, earliest == release and (earliest is not None or untagged), landed(cut))
return Upcoming(release, earliest == release and (earliest is not None or version == BEFORE_FIRST_RELEASE), landed(cut))
def cut_version(cut: LastCut) -> tuple[int, int, int] | None:
"""The version cut counts as cut: its tag's; on a branch with no tag, the newest under a dated CHANGELOG.md heading, else BEFORE_FIRST_RELEASE. None where the tag names no version."""
if cut.tag is None:
return max(dated_headings(cut.changelog), default=BEFORE_FIRST_RELEASE)
return version_of(cut.tag)
def cut_name(cut: LastCut) -> str | None:
"""How the preflight names cut_version's cut: the tag, or the version under its dated heading; None where nothing is cut."""
if cut.tag is not None:
return None if isinstance(cut.tag, Failure) else cut.tag
headed = max(dated_headings(cut.changelog), default=None)
return None if headed is None else f"{version(headed)}, under CHANGELOG.md's dated heading"
def dated_headings(changelog: str | Failure) -> list[tuple[int, int, int]]:
"""Each version CHANGELOG.md heads `## X.Y.Z - YYYY-MM-DD`, the heading a cut release takes; an undated heading is not cut."""
if isinstance(changelog, Failure):
return []
return [release_of(dated[1]) for heading in sections(changelog) if (dated := re.fullmatch(r"([0-9]+\.[0-9]+\.[0-9]+) - [0-9]{4}-[0-9]{2}-[0-9]{2}", heading))]
def version_of(tag: str | None | Failure) -> tuple[int, int, int] | None: