Files
jobtrackingapp/scripts/gitea_audit_inventory.py
T
cesnimda c05d6f8906
CI and Deploy / test (pull_request) Failing after 7m16s
CI and Deploy / deploy (pull_request) Has been skipped
Establish Gitea backlog workflow and reconcile Project 1
2026-12-02 18:30:39 +01:00

72 lines
3.7 KiB
Python

"""Rebuild the migration's source census from pinned Git objects, without checking out application branches."""
import collections
import csv
import hashlib
import json
from pathlib import Path
import re
import subprocess
OUT = Path(__file__).resolve().parents[1] / "docs/gitea-backlog"
REVS = {
"main": "5f835e54a9b74e6b71418422e28431b2af06453f",
"integration": "ac64d2ee221859c481dfd62e8fe83084af4c6764",
"roadmap": "b8d26aab2b52750cffa8de00578b982899942892",
"recovery": "908295c634075e99c15964f482a4147d69fd9dc4",
"discovery-plan": "0ec9f98e6ed4a646fc5e017d8eb6fade07653f37",
}
PATTERNS = {
"unchecked": re.compile(r"^\s*[-*]\s+\[ \]"),
"markers": re.compile(r"\b(?:TODO|FIXME|HACK|XXX)\b|NotImplementedException|(?:ponytail|shortcut):", re.I),
"conditional_tests": re.compile(r"(?:test|describe|it|pytest)(?:\.mark)?\.(?:skip|skipif|fixme)\b|(?:Fact|Theory)\s*\(\s*Skip\s*=|unittest\.skip"),
"flags": re.compile(r"GetValue.{0,100}(?:Enabled|FeatureFlag)|FeatureGate|FeatureFlag", re.I),
"endpoint": re.compile(r"\[(?:Http(Get|Post|Put|Delete|Patch)|Route)\b"),
}
SOURCE = {".md", ".cs", ".csproj", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".sh", ".ps1", ".yml", ".yaml", ".toml", ".conf", ".sql", ".json"}
def run():
blobs = collections.defaultdict(list)
counts = {}
for lane, rev in REVS.items():
tree = subprocess.check_output(["git", "ls-tree", "-rz", rev]).decode().split("\0")
total = 0
for entry in filter(None, tree):
meta, name = entry.split("\t", 1)
total += 1
path = Path(name)
if (path.suffix.lower() not in SOURCE and "Dockerfile" not in path.name
or "evidence/" in name.lower() and path.suffix != ".md"
or path.name in ("package-lock.json", "graph.json") or "graphify-out/" in name
or any(s.startswith(".env") for s in path.parts)):
continue
blobs[(name, meta.split()[-1])].append(lane)
counts[lane] = {"commit": rev, "tracked_paths": total}
process = subprocess.Popen(["git", "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
summary = collections.Counter()
with (OUT / "source-census.tsv").open("w", encoding="utf-8", newline="") as f:
writer = csv.writer(f, delimiter="\t", lineterminator="\n", quoting=csv.QUOTE_ALL)
writer.writerow(["lanes", "path", "blob", *PATTERNS])
for (path, blob), lanes in sorted(blobs.items()):
process.stdin.write((blob + "\n").encode())
process.stdin.flush()
size = int(process.stdout.readline().split()[-1])
data = process.stdout.read(size)
assert process.stdout.read(1) == b"\n"
lines = data.decode("utf-8", "replace").splitlines()
fields = []
for field, regex in PATTERNS.items():
hits = [str(n) for n, line in enumerate(lines, 1) if regex.search(line)]
fields.append(",".join(hits))
summary[field] += len(hits)
writer.writerow([",".join(lanes), path, blob, *fields])
process.stdin.close()
assert process.wait() == 0
output = {"revisions": counts, "distinct_path_blob_pairs": len(blobs), "line_matches": summary,
"scope": "Tracked source and documentation, including archives; binary evidence, large generated graph/lock data and environment files excluded from text scanning. Counts identify review candidates, not defects.",
"sha256": hashlib.sha256((OUT / "source-census.tsv").read_bytes()).hexdigest()}
(OUT / "source-audit.json").write_text(json.dumps(output, indent=2) + "\n", encoding="utf-8")
print(json.dumps(output, indent=2))
if __name__ == "__main__":
run()