| 106 | |
| 107 | |
| 108 | def format_markdown(notes: Any, payload: dict[str, Any]) -> str: |
| 109 | def get(name: str, default=""): |
| 110 | return getattr( |
| 111 | notes, name, notes.get(name, default) if isinstance(notes, dict) else default |
| 112 | ) |
| 113 | |
| 114 | highlights = get("highlights", []) |
| 115 | notable_files = get("notable_files", []) |
| 116 | documentation_signals = get("documentation_signals", []) |
| 117 | summary = str(get("summary", "")).strip() |
| 118 | branch_summary_prefix = f"Merged branch `{payload['branch_name']}`:" |
| 119 | if summary: |
| 120 | if payload["branch_name"].lower() not in summary.lower(): |
| 121 | summary = f"{branch_summary_prefix} {summary}" |
| 122 | else: |
| 123 | summary = branch_summary_prefix |
| 124 | |
| 125 | lines = [ |
| 126 | f"# {get('title', 'Branch notes')}", |
| 127 | "", |
| 128 | f"**Branch:** {payload['branch_name']}", |
| 129 | f"**PR:** #{payload['pr_number']} {payload['pr_title']}" |
| 130 | if payload.get("pr_number") |
| 131 | else "**PR:** Not available", |
| 132 | f"**Merge SHA:** {payload['merge_sha']}", |
| 133 | "", |
| 134 | "## Summary", |
| 135 | "", |
| 136 | summary, |
| 137 | "", |
| 138 | "## User Impact", |
| 139 | "", |
| 140 | get("user_impact", ""), |
| 141 | "", |
| 142 | ] |
| 143 | if highlights: |
| 144 | lines.extend(["## Highlights", ""]) |
| 145 | lines.extend([f"- {item}" for item in highlights]) |
| 146 | lines.append("") |
| 147 | if notable_files: |
| 148 | lines.extend(["## Notable Files", ""]) |
| 149 | lines.extend([f"- {item}" for item in notable_files]) |
| 150 | lines.append("") |
| 151 | if documentation_signals: |
| 152 | lines.extend(["## Documentation Signals", ""]) |
| 153 | lines.extend([f"- {item}" for item in documentation_signals]) |
| 154 | lines.append("") |
| 155 | lines.extend(["## Raw Commit Subjects", ""]) |
| 156 | lines.extend(payload["commit_subjects"] or ["No non-merge commits found"]) |
| 157 | lines.append("") |
| 158 | return "\n".join(lines) |
| 159 | |
| 160 | |
| 161 | def parse_args(): |