38 lines
1.9 KiB
Python
38 lines
1.9 KiB
Python
import datetime
|
|
|
|
from review_rules.comprehension_history import entries
|
|
from failure import Failure
|
|
from git_cli.git_repo import git
|
|
from record_store.stores import held_at, RecordStore
|
|
|
|
|
|
def unmeasured_cut(default: str, history: RecordStore, checkout: str) -> str | None | Failure:
|
|
"""Whether the default branch's newest release was cut unmeasured, as `v0.7.0, cut with no scoring run since v0.6.0`. It was where no scoring run in the default branch's comprehension history is newer than the second-newest v* tag. None where the branch holds fewer than two such tags, or a run since the earlier one.
|
|
|
|
The reason ends once a run follows the earlier tag, so it asks only after a release was cut with none; it lets the chunk that finds the gap record the run.
|
|
|
|
A scoring run counts by the time its history heading records, against the tag's commit time; a heading whose time doesn't parse doesn't count, so the run is asked for again.
|
|
"""
|
|
# Sorts v1.0.0-rc.1 below v1.0.0, as release.newest_tag does.
|
|
tags = git("-c", "versionsort.suffix=-", "tag", "--list", "v*", "--merged", default, "--sort=-v:refname", cwd=checkout)
|
|
if isinstance(tags, Failure):
|
|
return tags
|
|
newest, earlier, *_ = [*tags.split(), None, None]
|
|
if earlier is None:
|
|
return None
|
|
since = git("log", "-1", "--format=%ct", earlier, cwd=checkout)
|
|
text = held_at(default, history, checkout)
|
|
if isinstance(since, Failure) or isinstance(text, Failure):
|
|
return since if isinstance(since, Failure) else text
|
|
if any(at > int(since) for at in (seconds(entry.time) for entry in entries(text) if not entry.paired)):
|
|
return None
|
|
return f"{newest}, cut with no scoring run since {earlier}"
|
|
|
|
|
|
def seconds(heading_time: str) -> float:
|
|
"""A history heading's UTC time as seconds since the epoch; 0 where it doesn't parse."""
|
|
try:
|
|
return datetime.datetime.strptime(heading_time, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=datetime.timezone.utc).timestamp()
|
|
except ValueError:
|
|
return 0
|