parse method
Parse a full CHANGELOG.md into structured entries.
Returns a list of ChangelogEntry objects sorted from newest to oldest (the order in which they appear in the file).
Implementation
List<ChangelogEntry> parse(String changelogContent) {
if (changelogContent.trim().isEmpty) {
Logger.debug('ChangelogParser: empty changelog content');
return [];
}
final entries = <ChangelogEntry>[];
// Find all version heading positions.
final matches = _versionHeadingPattern.allMatches(changelogContent).toList();
if (matches.isEmpty) {
Logger.debug('ChangelogParser: no version headings found');
return [];
}
for (var i = 0; i < matches.length; i++) {
final match = matches[i];
final version = match.group(1)!;
final date = match.group(2);
// Extract the section content between this heading and the next.
final sectionStart = match.end;
final sectionEnd =
(i + 1 < matches.length) ? matches[i + 1].start : changelogContent.length;
final sectionContent = changelogContent.substring(sectionStart, sectionEnd).trim();
// Parse individual change lines (bullets and numbered items).
final changes = _extractChangeLines(sectionContent);
// Detect and parse breaking changes.
final breakingChanges = _extractBreakingChanges(version, sectionContent);
entries.add(ChangelogEntry(
version: version,
date: date,
content: sectionContent,
hasBreakingChanges: breakingChanges.isNotEmpty,
breakingChanges: breakingChanges,
changes: changes,
));
}
Logger.debug('ChangelogParser: parsed ${entries.length} entries');
return entries;
}