diff --git a/src/Titano.Tools/Commands/ChangelogCommand.cs b/src/Titano.Tools/Commands/ChangelogCommand.cs index 6e9731bc..5db4e6a7 100644 --- a/src/Titano.Tools/Commands/ChangelogCommand.cs +++ b/src/Titano.Tools/Commands/ChangelogCommand.cs @@ -60,11 +60,14 @@ internal sealed partial class ChangelogCommand : ICommand var sb = new StringBuilder(); if (title is not null) sb.Append("# ").AppendLine(title).AppendLine(); + // The title alone says nothing about the release: the fallback depends on the entries written, not on the text. + var written = false; if (breaking.Count > 0) { sb.AppendLine("### Breaking changes"); foreach (var e in breaking) sb.AppendLine(e); sb.AppendLine(); + written = true; } foreach (var (type, heading) in Sections) { @@ -72,8 +75,9 @@ internal sealed partial class ChangelogCommand : ICommand sb.Append("### ").AppendLine(heading); foreach (var e in entries) sb.AppendLine(e); sb.AppendLine(); + written = true; } - if (sb.Length == 0) sb.AppendLine("Maintenance release."); + if (!written) sb.AppendLine("Maintenance release."); return sb.ToString(); } diff --git a/tests/Titano.Tools.Tests/ChangelogCommandTests.cs b/tests/Titano.Tools.Tests/ChangelogCommandTests.cs new file mode 100644 index 00000000..7e8c98de --- /dev/null +++ b/tests/Titano.Tools.Tests/ChangelogCommandTests.cs @@ -0,0 +1,33 @@ +using Titano.Testing; +using Titano.Tools.Commands; + +namespace Titano.Tools.Tests; + +/// Release notes from Conventional Commits (BRIEF ยง19.3), as release.yml renders them with a title. +public sealed class ChangelogCommandTests +{ + [Test] + public void EntriesAreGroupedByTypeUnderTheTitle() + { + var notes = ChangelogCommand.Render(["abc1234\tfeat(editor): save the project as a .titano file", "def5678\tfix: keep user data", "0a1b2c3\tchore: bump"], "Titano 1.2.0"); + Assert.Equal( + "# Titano 1.2.0\n\n### Added\n- **editor**: save the project as a .titano file (abc1234)\n\n### Fixed\n- keep user data (def5678)\n\n", + notes.ReplaceLineEndings("\n")); + } + + [Test] + public void ATitledReleaseWithoutListedChangesSaysItIsAMaintenanceRelease() + { + string[] lines = ["abc1234\tchore: bump", "def5678\tci: cache", "0a1b2c3\ttest(setup): cover uninstall", "not a conventional subject"]; + Assert.Equal("# Titano 1.2.1\n\nMaintenance release.\n", ChangelogCommand.Render(lines, "Titano 1.2.1").ReplaceLineEndings("\n")); + Assert.Equal("Maintenance release.\n", ChangelogCommand.Render(lines, null).ReplaceLineEndings("\n")); + Assert.Equal("Maintenance release.\n", ChangelogCommand.Render([], null).ReplaceLineEndings("\n")); + } + + [Test] + public void ABreakingChangeOfAnUnlistedTypeIsStillWritten() + { + var notes = ChangelogCommand.Render(["abc1234\trefactor(core)!: rename the archive layout"], "Titano 2.0.0").ReplaceLineEndings("\n"); + Assert.Equal("# Titano 2.0.0\n\n### Breaking changes\n- **core**: rename the archive layout (abc1234)\n\n", notes); + } +}