Commit 1fd2d1a61c
Unsigned
Layout: unified · split
lib/generate-changelog.py +51 −13
| @@ -1,5 +1,4 @@ | |||
| 1 | """Generates .github/changelog.json from git history of awesome-privacy.yml. | 1 | """Generates .github/changelog.json from git history of awesome-privacy.yml. |
| 2 | |||
| 3 | Walks the first-parent commit history, diffs consecutive YAML versions, | 2 | Walks the first-parent commit history, diffs consecutive YAML versions, |
| 4 | and enriches entries with GitHub PR metadata. | 3 | and enriches entries with GitHub PR metadata. |
| 5 | """ | 4 | """ |
| @@ -58,10 +57,27 @@ def get_commits(): | |||
| 58 | 57 | ||
| 59 | 58 | ||
| 60 | def is_sync_merge(message): | 59 | def 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).""" |
| 62 | return message.startswith("Merge branch 'main'") or message.startswith("Merge branch 'master'") | 61 | return message.startswith("Merge branch 'main'") or message.startswith("Merge branch 'master'") |
| 63 | 62 | ||
| 64 | 63 | ||
| 64 | def 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 | |||
| 65 | def extract_pr_from_message(message): | 81 | def extract_pr_from_message(message): |
| 66 | """Extract PR info from a commit message. Returns dict or None.""" | 82 | """Extract PR info from a commit message. Returns dict or None.""" |
| 67 | m = re.match(r'^Merge pull request #(\d+) from ([^/]+)/', message) | 83 | m = re.match(r'^Merge pull request #(\d+) from ([^/]+)/', message) |
| @@ -337,7 +353,7 @@ def main(): | |||
| 337 | trimmed.append(c) | 353 | trimmed.append(c) |
| 338 | if c["sha"] == FIRST_COMMIT: | 354 | if c["sha"] == FIRST_COMMIT: |
| 339 | break | 355 | break |
| 340 | commits = [c for c in trimmed if not is_sync_merge(c["message"])] | 356 | commits = trimmed |
| 341 | 357 | ||
| 342 | new_commits = [c for c in commits if c["sha"] not in processed_shas] | 358 | new_commits = [c for c in commits if c["sha"] not in processed_shas] |
| 343 | new_entries = [] | 359 | new_entries = [] |
| @@ -353,6 +369,17 @@ def main(): | |||
| 353 | 369 | ||
| 354 | pr_numbers_to_fetch = set() | 370 | pr_numbers_to_fetch = set() |
| 355 | 371 | ||
| 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 | |||
| 356 | for i, c in enumerate(new_commits, 1): | 383 | for i, c in enumerate(new_commits, 1): |
| 357 | new_processed.add(c["sha"]) | 384 | new_processed.add(c["sha"]) |
| 358 | parent = sha_to_parent.get(c["sha"]) | 385 | parent = sha_to_parent.get(c["sha"]) |
| @@ -360,20 +387,31 @@ def main(): | |||
| 360 | continue | 387 | continue |
| 361 | 388 | ||
| 362 | changes = diff_commits(c["sha"], parent) | 389 | changes = diff_commits(c["sha"], parent) |
| 390 | prefix = f" [{i}/{len(new_commits)}]" | ||
| 363 | if changes is None: | 391 | 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) |
| 365 | continue | 393 | continue |
| 366 | 394 | ||
| 367 | sv = changes.get("services", {}) | 395 | # Sync merges pull content in via their 2nd parent, so their own message |
| 368 | counts = (f"+{len(sv.get('added', []))} -{len(sv.get('removed', []))} " | 396 | # carries no PR number. Fan out to per-PR entries so each PR gets its own. |
| 369 | f"~{len(sv.get('modified', []))} »{len(sv.get('moved', []))} " | 397 | # If the chain has PR merges, we trust them to cover the content — even if |
| 370 | f"≈{len(sv.get('renamed', []))}") | 398 | # all are already processed — and skip the default emit to avoid duplicates. |
| 371 | print(f" [{i}/{len(new_commits)}] {c['date'][:10]} {counts} {c['message'][:60]}", flush=True) | 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 | ||
| 372 | 412 | ||
| 373 | pr = extract_pr_from_message(c["message"]) | 413 | counts = emit(c["sha"], c["date"], c["message"], changes) |
| 374 | if pr: | 414 | print(f"{prefix} {c['date'][:10]} {counts} {c['message'][:60]}", flush=True) |
| 375 | pr_numbers_to_fetch.add(pr["number"]) | ||
| 376 | new_entries.append({"date": c["date"][:10], "sha": c["sha"], "pr": pr, "changes": changes}) | ||
| 377 | 415 | ||
| 378 | # Enrich entries missing full avatar data | 416 | # Enrich entries missing full avatar data |
| 379 | for e in existing_entries: | 417 | for e in existing_entries: |