feat: dossiers-ngi sticky bar vs-main +green/−red diffstat
This commit is contained in:
parent
a4ec0305bc
commit
31af42538a
6 changed files with 134 additions and 32 deletions
|
|
@ -234,6 +234,30 @@ def tip_recorded(editions: Path, slug: str) -> str:
|
|||
return p.read_text(encoding="utf-8").strip()
|
||||
|
||||
|
||||
|
||||
def diff_vs_main(repo: Path, main_tip: str, tip: str) -> tuple[int, int]:
|
||||
"""Insertions/deletions of tip vs main tip (git diff --numstat)."""
|
||||
if not main_tip or not tip or main_tip == tip:
|
||||
return 0, 0
|
||||
cp = git(repo, "diff", "--numstat", main_tip, tip, check=False)
|
||||
if cp.returncode != 0:
|
||||
return 0, 0
|
||||
plus = minus = 0
|
||||
for line in (cp.stdout or "").splitlines():
|
||||
parts = line.split(" ")
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
a, d = parts[0], parts[1]
|
||||
if a == "-" or d == "-":
|
||||
continue
|
||||
try:
|
||||
plus += int(a)
|
||||
minus += int(d)
|
||||
except ValueError:
|
||||
continue
|
||||
return plus, minus
|
||||
|
||||
|
||||
def tip_commit_time(repo: Path, tip: str) -> str:
|
||||
"""Committer ISO time of tip (empty on failure)."""
|
||||
cp = git(repo, "log", "-1", "--format=%cI", tip, check=False)
|
||||
|
|
@ -531,6 +555,10 @@ def build_payload(repo: Path, tips: dict[str, str], rebuild: bool) -> dict:
|
|||
sync_flask_alias(ed_root, tips)
|
||||
|
||||
tip_times = {name: tip_commit_time(repo, tip) for name, tip in tips.items()}
|
||||
main_tip = tips.get("main", "")
|
||||
vs_main = {
|
||||
name: diff_vs_main(repo, main_tip, tip) for name, tip in tips.items()
|
||||
}
|
||||
branches_out = []
|
||||
for row in rows:
|
||||
name = row["branch"]
|
||||
|
|
@ -556,6 +584,11 @@ def build_payload(repo: Path, tips: dict[str, str], rebuild: bool) -> dict:
|
|||
entry["built_at"] = meta["built_at"]
|
||||
if "build_seconds" in meta:
|
||||
entry["build_seconds"] = meta["build_seconds"]
|
||||
# sticky bar: +grün / −rot vs main (omit on main itself)
|
||||
if name != "main" and main_tip:
|
||||
plus, minus = vs_main.get(name, (0, 0))
|
||||
entry["vs_main_plus"] = plus
|
||||
entry["vs_main_minus"] = minus
|
||||
branches_out.append(entry)
|
||||
|
||||
payload = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue