Process update report and generate draft PRs. Returns number of PRs created.
(report: dict, dry_run: bool = False)
| 456 | # --------------------------------------------------------------------------- |
| 457 | |
| 458 | def process_updates(report: dict, dry_run: bool = False) -> int: |
| 459 | """Process update report and generate draft PRs. Returns number of PRs created.""" |
| 460 | updates = report.get("updates", []) |
| 461 | if not updates: |
| 462 | print("No updates to process.") |
| 463 | return 0 |
| 464 | |
| 465 | timestamp = datetime.now().strftime("%Y%m%d_%H%M") |
| 466 | branch_name = f"auto/content-updates-{timestamp}" |
| 467 | generated_files: list[Path] = [] |
| 468 | pr_body_sections: list[str] = [] |
| 469 | |
| 470 | print(f"\nProcessing {len(updates)} update(s)...") |
| 471 | |
| 472 | for update in updates: |
| 473 | source_id = update.get("source_id", "unknown") |
| 474 | name = update.get("name", "Unknown") |
| 475 | category = update.get("category", "") |
| 476 | print(f"\n [{category}] {name}") |
| 477 | |
| 478 | generator = select_generator(update) |
| 479 | en_content, zh_content = generator(update) |
| 480 | en_path, zh_path = get_draft_paths(update, timestamp) |
| 481 | |
| 482 | if dry_run: |
| 483 | print(f" [DRY RUN] Would create: {en_path.relative_to(ROOT)}") |
| 484 | print(f" [DRY RUN] Would create: {zh_path.relative_to(ROOT)}") |
| 485 | else: |
| 486 | en_path.parent.mkdir(parents=True, exist_ok=True) |
| 487 | zh_path.parent.mkdir(parents=True, exist_ok=True) |
| 488 | en_path.write_text(en_content, encoding="utf-8") |
| 489 | zh_path.write_text(zh_content, encoding="utf-8") |
| 490 | generated_files.extend([en_path, zh_path]) |
| 491 | print(f" Created: {en_path.relative_to(ROOT)}") |
| 492 | print(f" Created: {zh_path.relative_to(ROOT)}") |
| 493 | |
| 494 | pr_body_sections.append( |
| 495 | f"- **[{category}]** {name}\n" |
| 496 | f" - Source: {update.get('url', '')}\n" |
| 497 | f" - Note: {update.get('note', 'Manual review required')}" |
| 498 | ) |
| 499 | |
| 500 | if dry_run: |
| 501 | print(f"\n[DRY RUN] Would create branch: {branch_name}") |
| 502 | print(f"[DRY RUN] Would commit {len(updates) * 2} draft files") |
| 503 | print(f"[DRY RUN] Would open PR: 'chore: auto-detected regulatory updates {timestamp}'") |
| 504 | return len(updates) |
| 505 | |
| 506 | if not generated_files: |
| 507 | print("No files generated.") |
| 508 | return 0 |
| 509 | |
| 510 | # Create branch and commit |
| 511 | print(f"\nCreating branch: {branch_name}") |
| 512 | if not create_branch(branch_name): |
| 513 | return 0 |
| 514 | |
| 515 | commit_msg = f"chore: auto-detected regulatory content drafts ({timestamp})\n\nGenerated by generate_content_pr.py" |
no test coverage detected