Skip to content

Commit 0a7d02c

Browse files
authored
feat: group changelog bugfixes (anomalyco#25597)
1 parent e77867e commit 0a7d02c

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

.opencode/command/changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ Do not use `git log` or author metadata when deciding attribution.
1818

1919
Rules:
2020

21-
- Write the final file with sections in this order:
21+
- Write the final file with release sections in this order:
2222
`## Core`, `## TUI`, `## Desktop`, `## SDK`, `## Extensions`
2323
- Only include sections that have at least one notable entry
24+
- Within each release section, keep bug fixes grouped under `### Bugfixes`
25+
- Keep other notable entries under `### Improvements` when a section has bug fixes too
26+
- Omit empty subsections
2427
- Keep one bullet per commit you keep
2528
- Skip commits that are entirely internal, CI, tests, refactors, or otherwise not user-facing
2629
- Start each bullet with a capital letter

script/raw-changelog.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ function section(areas: Set<string>) {
8282
return "Core"
8383
}
8484

85+
function type(message: string) {
86+
if (message.match(/fix/i)) return "Bugfixes"
87+
return "Improvements"
88+
}
89+
8590
function reverted(commits: Commit[]) {
8691
const seen = new Map<string, Commit>()
8792

@@ -193,13 +198,20 @@ async function thanks(from: string, to: string, reuse: boolean) {
193198
}
194199

195200
function format(from: string, to: string, list: Commit[], thanks: string[]) {
196-
const grouped = new Map<string, string[]>()
197-
for (const title of order) grouped.set(title, [])
201+
const grouped = new Map<string, Map<string, string[]>>()
202+
for (const title of order) {
203+
grouped.set(
204+
title,
205+
new Map([
206+
["Improvements", []],
207+
["Bugfixes", []],
208+
]),
209+
)
210+
}
198211

199212
for (const commit of list) {
200-
const title = section(commit.areas)
201213
const attr = commit.author && !team.includes(commit.author) ? ` (@${commit.author})` : ""
202-
grouped.get(title)!.push(`- \`${commit.hash}\` ${commit.message}${attr}`)
214+
grouped.get(section(commit.areas))!.get(type(commit.message))!.push(`- \`${commit.hash}\` ${commit.message}${attr}`)
203215
}
204216

205217
const lines = [`Last release: ${ref(from)}`, `Target ref: ${to}`, ""]
@@ -209,11 +221,23 @@ function format(from: string, to: string, list: Commit[], thanks: string[]) {
209221
}
210222

211223
for (const title of order) {
212-
const entries = grouped.get(title)
213-
if (!entries || entries.length === 0) continue
224+
const groups = grouped.get(title)
225+
if (!groups || [...groups.values()].every((entries) => entries.length === 0)) continue
214226
lines.push(`## ${title}`)
215-
lines.push(...entries)
216-
lines.push("")
227+
const improvements = groups.get("Improvements")!
228+
const bugfixes = groups.get("Bugfixes")!
229+
if (bugfixes.length === 0) {
230+
lines.push(...improvements)
231+
lines.push("")
232+
continue
233+
}
234+
235+
for (const [subtitle, entries] of groups) {
236+
if (entries.length === 0) continue
237+
lines.push(`### ${subtitle}`)
238+
lines.push(...entries)
239+
lines.push("")
240+
}
217241
}
218242

219243
if (thanks.length > 0) {

0 commit comments

Comments
 (0)