MCPcopy Index your code
hub / github.com/anomalyco/opencode / format

Function format

script/raw-changelog.ts:198–250  ·  view source on GitHub ↗
(from: string, to: string, list: Commit[], thanks: string[])

Source from the content-addressed store, hash-verified

196}
197
198function 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
252if (import.meta.main) {
253 const { values } = parseArgs({

Callers 1

raw-changelog.tsFile · 0.70

Calls 8

sectionFunction · 0.85
pushMethod · 0.80
atMethod · 0.80
typeFunction · 0.70
refFunction · 0.70
getMethod · 0.65
setMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected