fetchChangelog method
Fetch the CHANGELOG content from a GitHub repository.
Tries multiple common filenames in order: CHANGELOG.md, changelog.md,
CHANGES.md, HISTORY.md. Returns the raw Markdown text, or null if
no changelog is found.
An optional ref (branch/tag/commit) can be specified; defaults to the
repository's default branch.
Implementation
Future<String?> fetchChangelog(
String owner,
String repo, {
String? ref,
}) async {
final branch = ref ?? 'main';
final candidates = ['CHANGELOG.md', 'changelog.md', 'CHANGES.md', 'HISTORY.md'];
for (final filename in candidates) {
final content = await fetchFileContent(owner, repo, filename, ref: branch);
if (content != null) {
Logger.debug('Found changelog at $filename for $owner/$repo');
return content;
}
}
// Also try the `master` branch if the caller did not specify a ref and
// `main` yielded nothing.
if (ref == null) {
for (final filename in candidates) {
final content =
await fetchFileContent(owner, repo, filename, ref: 'master');
if (content != null) {
Logger.debug(
'Found changelog at $filename on master for $owner/$repo',
);
return content;
}
}
}
Logger.warn('No changelog found for $owner/$repo');
return null;
}