| 190 | } |
| 191 | |
| 192 | function formatJSON(tag, prevTag, sections, plain = true) { |
| 193 | const lines = [ |
| 194 | "", |
| 195 | flags.changelogOnly |
| 196 | ? "" |
| 197 | : `Changes since [${prevTag}](https://github.com/${owner}/${repo}/releases/tag/${prevTag})`, |
| 198 | "", |
| 199 | ]; |
| 200 | |
| 201 | // todo: split into function |
| 202 | for (const [type, list] of Object.entries(sections)) { |
| 203 | if (list.length === 0) continue; |
| 204 | const header = plain |
| 205 | ? `## ${type}` |
| 206 | : `## ${emojis[type]}${type[0].toUpperCase() + type.slice(1)}`; |
| 207 | lines.push(header, "", list.join("\n"), ""); |
| 208 | } |
| 209 | return JSON.stringify( |
| 210 | { |
| 211 | release: tag, |
| 212 | previous: prevTag, |
| 213 | sections: Object.fromEntries( |
| 214 | Object.entries(sections).filter(([_, v]) => v.length), |
| 215 | ), |
| 216 | notes: lines.join("\n"), |
| 217 | }, |
| 218 | null, |
| 219 | 2, |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | async function main() { |
| 224 | log(`🔍 Generating release notes for ${owner}/${repo} @ ${currentTag}...`); |