Answer architecture round 3: 0 🔴, 1 🟡; pick the next chunk's item in one function, todo_table.chunk_item, which routing and the preflight both call, so routing names no item where the release after the last cut has none
This commit is contained in:
+25
-9
@@ -1,4 +1,5 @@
|
||||
"""Run git, in the current directory or a given one, and read the checkout, its default branch and its files."""
|
||||
import dataclasses
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
@@ -60,22 +61,37 @@ def origin_head(cwd: str | None, timeout: float | None) -> str | Failure:
|
||||
return Failure("origin names no default branch; set it with `git remote set-head origin --auto`")
|
||||
|
||||
|
||||
def default_branch_todo(root: str, timeout: float) -> str | Failure:
|
||||
"""todo.md on the default branch as last fetched, read in the checkout at root; empty where that branch holds none. Asking origin, where the checkout records no default branch for it, fails after timeout seconds."""
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class DefaultPlan:
|
||||
"""What the default branch, as last fetched, holds for picking the next chunk's item: todo_table.chunk_item's inputs."""
|
||||
ref: str
|
||||
# todo.md's text, empty where the branch holds none.
|
||||
todo: str | Failure
|
||||
# The newest v* tag on the branch, None where it has none.
|
||||
tag: str | None | Failure
|
||||
# How many commits follow the tag, or make up the branch where it has none.
|
||||
commits: int | Failure
|
||||
|
||||
|
||||
def default_plan(root: str, timeout: float) -> DefaultPlan | Failure:
|
||||
"""What the default branch as last fetched holds for the pick, read in the checkout at root. Asking origin, where the checkout records no default branch for it, fails after timeout seconds."""
|
||||
ref = default_ref(root, timeout)
|
||||
return ref if isinstance(ref, Failure) else file_at(ref, "todo.md", root)
|
||||
if isinstance(ref, Failure):
|
||||
return ref
|
||||
tag = newest_release_tag(ref, root)
|
||||
return DefaultPlan(ref, file_at(ref, "todo.md", root), tag, tag if isinstance(tag, Failure) else commits_since(tag, ref, root))
|
||||
|
||||
|
||||
def newest_release_tag(branch: str) -> str | None | Failure:
|
||||
"""The newest `v*` tag merged into branch, None when it has none."""
|
||||
def newest_release_tag(branch: str, cwd: str | None = None) -> str | None | Failure:
|
||||
"""The newest `v*` tag merged into branch, read in cwd, else in the current directory; None when it has none."""
|
||||
# Sorts v1.0.0-rc.1 below v1.0.0.
|
||||
tags = git("-c", "versionsort.suffix=-", "tag", "--list", "v*", "--merged", branch, "--sort=-v:refname")
|
||||
tags = git("-c", "versionsort.suffix=-", "tag", "--list", "v*", "--merged", branch, "--sort=-v:refname", cwd=cwd)
|
||||
return tags if isinstance(tags, Failure) else next(iter(tags.split()), None)
|
||||
|
||||
|
||||
def commits_since(tag: str | None, branch: str) -> int | Failure:
|
||||
"""How many commits branch holds after tag, or holds in all where tag is None."""
|
||||
count = git("rev-list", "--count", f"{tag}..{branch}" if tag else branch)
|
||||
def commits_since(tag: str | None, branch: str, cwd: str | None = None) -> int | Failure:
|
||||
"""How many commits branch holds after tag, or holds in all where tag is None; read in cwd, else in the current directory."""
|
||||
count = git("rev-list", "--count", f"{tag}..{branch}" if tag else branch, cwd=cwd)
|
||||
return count if isinstance(count, Failure) else int(count)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user