checkChangelog function
Checks every version section of markdown against each platform's limit.
Two failures are reported, and they are different in kind:
- a version with no section at all, which means somebody forgot — the uploaders refuse this rather than inventing a note; and
- a section that survives filtering for a platform but is longer than that store accepts, which the store itself would only say after the upload.
A changelog with no version headings is itself a problem: it is far more likely that the format drifted than that a project has no releases, and silently checking nothing is the failure this whole function exists to prevent.
Implementation
List<ReleaseProblem> checkChangelog(
String markdown, {
Map<String, int> limits = defaultReleaseNotesLimits,
}) {
final problems = <ReleaseProblem>[];
final versions = changelogVersions(markdown);
if (versions.isEmpty) {
problems.add(
const ReleaseProblem(
'CHANGELOG.md',
'no version headings found — expected at least one "## 1.2.3", '
'optionally bracketed and dated',
),
);
return problems;
}
for (final version in versions) {
for (final limit in limits.entries) {
final where = 'CHANGELOG.md § $version → ${limit.key}';
final notes = changelogNotes(markdown, version, platform: limit.key);
if (notes is! NotesText) {
problems.add(
ReleaseProblem(
where,
'no section for this version, which the uploaders also refuse',
),
);
continue;
}
if (notes.text.length > limit.value) {
problems.add(
ReleaseProblem(
where,
'filtered to ${notes.text.length} characters, over the '
'${limit.value} this store accepts — shorten it in '
'CHANGELOG.md',
),
);
}
}
}
return problems;
}