Commit 1fd2d1a61c

1fd2d1a61c9aeda537bdf0c792ac9382842575cf

parent: 1c92c50334

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-04-19 20:33 UTC

Fixes changelog gen, PR author branched off old commit

Layout: unified · split

lib/generate-changelog.py +51 −13
@@ -1,5 +1,4 @@
11"""Generates .github/changelog.json from git history of awesome-privacy.yml.
2
32Walks the first-parent commit history, diffs consecutive YAML versions,
43and enriches entries with GitHub PR metadata.
54"""
@@ -58,10 +57,27 @@ def get_commits():
5857
5958
6059def is_sync_merge(message):
61 """Return True for branch-sync merges that don't introduce content changes."""
60 """Return True for branch-sync merges (no PR number in message)."""
6261 return message.startswith("Merge branch 'main'") or message.startswith("Merge branch 'master'")
6362
6463
64def pr_merges_in_second_parent(sha):
65 """`Merge pull request #N` commits the sync merge pulled in via its 2nd parent."""
66 try:
67 result = subprocess.run(
68 ["git", "log", "--merges", "--format=%H%x00%aI%x00%s", f"{sha}^1..{sha}^2"],
69 capture_output=True, text=True, check=True, cwd=PROJECT_ROOT,
70 )
71 except subprocess.CalledProcessError:
72 return []
73 out = []
74 for line in result.stdout.splitlines():
75 parts = line.split("\x00", 2)
76 if len(parts) == 3 and parts[2].startswith("Merge pull request #"):
77 out.append({"sha": parts[0], "date": parts[1], "message": parts[2]})
78 return out
79
80
6581def extract_pr_from_message(message):
6682 """Extract PR info from a commit message. Returns dict or None."""
6783 m = re.match(r'^Merge pull request #(\d+) from ([^/]+)/', message)
@@ -337,7 +353,7 @@ def main():
337353 trimmed.append(c)
338354 if c["sha"] == FIRST_COMMIT:
339355 break
340 commits = [c for c in trimmed if not is_sync_merge(c["message"])]
356 commits = trimmed
341357
342358 new_commits = [c for c in commits if c["sha"] not in processed_shas]
343359 new_entries = []
@@ -353,6 +369,17 @@ def main():
353369
354370 pr_numbers_to_fetch = set()
355371
372 def emit(sha, date, message, changes):
373 """Append an entry, register its PR for metadata fetch, return counts summary."""
374 pr = extract_pr_from_message(message)
375 if pr:
376 pr_numbers_to_fetch.add(pr["number"])
377 new_entries.append({"date": date[:10], "sha": sha, "pr": pr, "changes": changes})
378 sv = changes.get("services", {})
379 return (f"+{len(sv.get('added', []))} -{len(sv.get('removed', []))} "
380 f"~{len(sv.get('modified', []))} »{len(sv.get('moved', []))} "
381 f"≈{len(sv.get('renamed', []))}")
382
356383 for i, c in enumerate(new_commits, 1):
357384 new_processed.add(c["sha"])
358385 parent = sha_to_parent.get(c["sha"])
@@ -360,20 +387,31 @@ def main():
360387 continue
361388
362389 changes = diff_commits(c["sha"], parent)
390 prefix = f" [{i}/{len(new_commits)}]"
363391 if changes is None:
364 print(f" [{i}/{len(new_commits)}] {c['date'][:10]} (no data changes)", flush=True)
392 print(f"{prefix} {c['date'][:10]} (no data changes)", flush=True)
365393 continue
366394
367 sv = changes.get("services", {})
368 counts = (f"+{len(sv.get('added', []))} -{len(sv.get('removed', []))} "
369 f"~{len(sv.get('modified', []))} »{len(sv.get('moved', []))} "
370 f"≈{len(sv.get('renamed', []))}")
371 print(f" [{i}/{len(new_commits)}] {c['date'][:10]} {counts} {c['message'][:60]}", flush=True)
395 # Sync merges pull content in via their 2nd parent, so their own message
396 # carries no PR number. Fan out to per-PR entries so each PR gets its own.
397 # If the chain has PR merges, we trust them to cover the content — even if
398 # all are already processed — and skip the default emit to avoid duplicates.
399 if is_sync_merge(c["message"]):
400 prs = pr_merges_in_second_parent(c["sha"])
401 if prs:
402 for pm in prs:
403 if pm["sha"] in processed_shas or pm["sha"] in new_processed:
404 continue
405 pm_changes = diff_commits(pm["sha"], pm["sha"] + "^1")
406 if pm_changes is None:
407 continue
408 new_processed.add(pm["sha"])
409 counts = emit(pm["sha"], pm["date"], pm["message"], pm_changes)
410 print(f"{prefix} {pm['date'][:10]} {counts} (via sync) {pm['message'][:50]}", flush=True)
411 continue
372412
373 pr = extract_pr_from_message(c["message"])
374 if pr:
375 pr_numbers_to_fetch.add(pr["number"])
376 new_entries.append({"date": c["date"][:10], "sha": c["sha"], "pr": pr, "changes": changes})
413 counts = emit(c["sha"], c["date"], c["message"], changes)
414 print(f"{prefix} {c['date'][:10]} {counts} {c['message'][:60]}", flush=True)
377415
378416 # Enrich entries missing full avatar data
379417 for e in existing_entries: