| 196 | } |
| 197 | |
| 198 | function format(from: string, to: string, list: Commit[], thanks: string[]) { |
| 199 | const grouped = new Map<string, Map<string, string[]>>() |
| 200 | for (const title of order) { |
| 201 | grouped.set( |
| 202 | title, |
| 203 | new Map([ |
| 204 | ["Improvements", []], |
| 205 | ["Bugfixes", []], |
| 206 | ]), |
| 207 | ) |
| 208 | } |
| 209 | |
| 210 | for (const commit of list) { |
| 211 | const attr = commit.author && !team.includes(commit.author) ? ` (@${commit.author})` : "" |
| 212 | grouped.get(section(commit.areas))!.get(type(commit.message))!.push(`- \`${commit.hash}\` ${commit.message}${attr}`) |
| 213 | } |
| 214 | |
| 215 | const lines = [`Last release: ${ref(from)}`, `Target ref: ${to}`, ""] |
| 216 | |
| 217 | if (list.length === 0) { |
| 218 | lines.push("No notable changes.") |
| 219 | } |
| 220 | |
| 221 | for (const title of order) { |
| 222 | const groups = grouped.get(title) |
| 223 | if (!groups || [...groups.values()].every((entries) => entries.length === 0)) continue |
| 224 | lines.push(`## ${title}`) |
| 225 | const improvements = groups.get("Improvements")! |
| 226 | const bugfixes = groups.get("Bugfixes")! |
| 227 | if (bugfixes.length === 0) { |
| 228 | lines.push(...improvements) |
| 229 | lines.push("") |
| 230 | continue |
| 231 | } |
| 232 | |
| 233 | for (const [subtitle, entries] of groups) { |
| 234 | if (entries.length === 0) continue |
| 235 | lines.push(`### ${subtitle}`) |
| 236 | lines.push(...entries) |
| 237 | lines.push("") |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if (thanks.length > 0) { |
| 242 | if (lines.at(-1) !== "") lines.push("") |
| 243 | lines.push("## Community Contributors Input") |
| 244 | lines.push("") |
| 245 | lines.push(...thanks) |
| 246 | } |
| 247 | |
| 248 | if (lines.at(-1) === "") lines.pop() |
| 249 | return lines.join("\n") |
| 250 | } |
| 251 | |
| 252 | if (import.meta.main) { |
| 253 | const { values } = parseArgs({ |