| | """Release notes generation — three-tier strategy.""" |
| |
|
| | from __future__ import annotations |
| |
|
| | from github.Repository import Repository |
| |
|
| | from .github_client import GHClient |
| |
|
| |
|
| | def build_notes( |
| | version: str, |
| | hf_repo: str | None, |
| | gh_client: GHClient | None, |
| | gh_repo_obj: Repository | None, |
| | previous_tag: str | None = None, |
| | notes_file: str | None = None, |
| | ) -> str: |
| | |
| | if notes_file: |
| | try: |
| | with open(notes_file) as f: |
| | return f.read() |
| | except OSError: |
| | pass |
| |
|
| | |
| | if gh_client and gh_repo_obj: |
| | notes = gh_client.generate_notes(gh_repo_obj, version, previous_tag) |
| | if notes: |
| | return _append_ml_artifacts(notes, version, hf_repo, gh_repo_obj.full_name) |
| |
|
| | |
| | parts = [f"Release {version}"] |
| | if hf_repo: |
| | parts.append(f"\n\n**Hugging Face Hub:** https://huggingface.co/{hf_repo}") |
| | if gh_repo_obj: |
| | parts.append(f"\n**GitHub:** https://github.com/{gh_repo_obj.full_name}/releases/tag/{version}") |
| | return "".join(parts) |
| |
|
| |
|
| | def _append_ml_artifacts(body: str, version: str, hf_repo: str | None, gh_repo: str) -> str: |
| | rows = [] |
| | if hf_repo: |
| | rows.append( |
| | f"| Hugging Face Hub | [Model files](https://huggingface.co/{hf_repo}/tree/{version}) |" |
| | ) |
| | rows.append( |
| | f"| Model Card | [README](https://huggingface.co/{hf_repo}) |" |
| | ) |
| | rows.append( |
| | f"| GitHub | [Release](https://github.com/{gh_repo}/releases/tag/{version}) |" |
| | ) |
| |
|
| | section = ( |
| | "\n\n## ML Artifacts\n\n" |
| | "| Platform | Link |\n" |
| | "|----------|------|\n" |
| | + "\n".join(rows) |
| | ) |
| | return body + section |
| |
|