generateReleaseNotes method
void
generateReleaseNotes(})
Implementation
void generateReleaseNotes(
String projectRootPath, Version? newVersion, Version? currentVersion,
{required bool autoAnswer, required bool dryrun}) {
// see https://blogs.sap.com/2018/06/22/generating-release-notes-from-git-commit-messages-using-basic-shell-commands-gitgrep/
// for better ideas.
final changeLogPath = join(projectRootPath, 'CHANGELOG.md');
if (!exists(changeLogPath)) {
touch(changeLogPath, create: true);
}
final tmpReleaseNotes = join(projectRootPath, 'release.notes.tmp');
tmpReleaseNotes.write('# ${newVersion.toString()}');
final usingGit = Git().usingGit(projectRootPath)!;
/// add commit messages to release notes.
if (usingGit) {
final lastTag = Git().getLatestTag();
// just the messages from each commit
final messages = Git().getCommitMessages(lastTag);
for (final message in messages) {
tmpReleaseNotes.append(message!);
}
tmpReleaseNotes.append('');
}
/// append the changelog to the new release notes
read(changeLogPath).toList().forEach((line) {
tmpReleaseNotes.append(line);
});
// give the user a chance to clean up the change log.
if (!autoAnswer && confirm('Would you like to edit the release notes')) {
showEditor(tmpReleaseNotes);
}
if (!dryrun) {
// write the edited commit messages to the change log.
final backup = '$changeLogPath.bak';
/// move the change log out of the way.
move(changeLogPath, backup);
/// replace the newly updated change log over the old one.
move(tmpReleaseNotes, changeLogPath);
delete(backup);
} else {
delete(tmpReleaseNotes);
}
}