32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from git_repo import commits_since, file_at, full_history, git, newest_release_tag
|
|
from failure import Failure
|
|
from comprehension_history import HISTORY, HistoryChange
|
|
|
|
|
|
def history_changes(default: str) -> list[HistoryChange] | Failure:
|
|
"""Each merged change on the default branch that touched the history, newest first; a merge commit counts as one change against its first parent."""
|
|
if partial := full_history():
|
|
return partial
|
|
commits = git("log", "--first-parent", "--format=%H", default, "--", HISTORY)
|
|
if isinstance(commits, Failure):
|
|
return commits
|
|
changes = []
|
|
for commit in commits.split():
|
|
before = file_at(f"{commit}^1", HISTORY)
|
|
if isinstance(before, Failure):
|
|
return before
|
|
after = file_at(commit, HISTORY)
|
|
if isinstance(after, Failure):
|
|
return after
|
|
changes.append(HistoryChange(commit, before, after))
|
|
return changes
|
|
|
|
|
|
def landed_since_release(default: str) -> bool | Failure:
|
|
"""Whether the default branch holds a commit after its newest `v*` tag, or any commit when it has none."""
|
|
newest = newest_release_tag(default)
|
|
if isinstance(newest, Failure):
|
|
return newest
|
|
count = commits_since(newest, default)
|
|
return count if isinstance(count, Failure) else count > 0
|