| 24 | } |
| 25 | |
| 26 | function getUnreleasedSection(content: string): string[] { |
| 27 | const lines = content.split('\n'); |
| 28 | |
| 29 | const unreleasedIndex = lines.findIndex(line => line.trim() === '## Unreleased'); |
| 30 | if (unreleasedIndex === -1) { |
| 31 | // eslint-disable-next-line no-console |
| 32 | console.error('Could not find "## Unreleased" section in CHANGELOG.md'); |
| 33 | process.exit(1); |
| 34 | } |
| 35 | |
| 36 | const nextVersionIndex = lines.findIndex((line, index) => index > unreleasedIndex && /^## \d+\.\d+\.\d+/.test(line)); |
| 37 | if (nextVersionIndex === -1) { |
| 38 | // eslint-disable-next-line no-console |
| 39 | console.error('Could not find next version section after "## Unreleased"'); |
| 40 | process.exit(1); |
| 41 | } |
| 42 | |
| 43 | return lines.slice(unreleasedIndex + 1, nextVersionIndex); |
| 44 | } |
| 45 | |
| 46 | function createEntry(content: string, type: EntryType): ChangelogEntry { |
| 47 | const firstLine = content.split('\n')[0] ?? content; |