Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fallout.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Project Path="build\_build.csproj">
<Configuration Solution="Debug|Any CPU" Project="Debug|Any CPU|NoBuild" />
<Configuration Solution="Release|Any CPU" Project="Debug|Any CPU|NoBuild" />
<Build Project="false" />
</Project>
<Project Path="src\Fallout.Build.Shared\Fallout.Build.Shared.csproj" />
<Project Path="src\Fallout.Build\Fallout.Build.csproj" />
Expand Down
47 changes: 39 additions & 8 deletions src/Fallout.Common/ChangeLog/ChangeLogTasks.cs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, thats probably the way. Fault tolerant, if its not there skip.
Mind to call the logger to spit out a warning? I'd expect if someone calls the Changelog Task they intend to write it (which in our case was the actual issue, we didnt fully remove it from our internal build process before I killed the Changelog.md)

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
// ReSharper disable ArgumentsStyleLiteral
namespace Fallout.Common.ChangeLog;

/// <summary>
/// Provides a set of tasks and utility methods for working with changelogs in a software repository.
/// This class includes methods for reading, extracting, and finalizing changelog entries, as well as
/// preparing release notes for publishing on platforms such as NuGet.
/// </summary>
public static class ChangelogTasks
{
public static string GetNuGetReleaseNotes(string changelogFile, GitRepository repository = null)
Expand Down Expand Up @@ -150,18 +155,44 @@ public static void FinalizeChangelog(AbsolutePath changelogFile, string tag, Git
}

/// <summary>
/// Extracts the notes of the specified changelog section.
/// Extracts the notes from a specific section of the given changelog file, optionally filtered by a section tag.
/// </summary>
/// <param name="changelogFile">The path to the changelog file.</param>
/// <param name="tag">The tag which release notes should get extracted.</param>
/// <returns>A collection of the release notes.</returns>
/// <param name="tag">The optional tag to identify the specific section to extract notes from. If null, the first valid section is used.</param>
/// <returns>An enumerable collection of strings representing the notes in the specified section. If the file does not exist or the section is not found, an empty collection is returned.</returns>
public static IEnumerable<string> ExtractChangelogSectionNotes(AbsolutePath changelogFile, string tag = null)
{
var content = changelogFile.ReadAllLines().Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
var sections = GetReleaseSections(content);
var section = tag == null
? sections.First(x => x.StartIndex < x.EndIndex)
: sections.FirstOrDefault(x => x.Caption.EqualsOrdinalIgnoreCase(tag)).NotNull($"Could not find release section for '{tag}'.");
if (!changelogFile.FileExists())
{
// We treat a non-existing changelog file as empty.
return Array.Empty<string>();
}

List<string> content = changelogFile.ReadAllLines().Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
List<ReleaseSection> sections = GetReleaseSections(content).ToList();
if (!sections.Any())
{
// We treat an empty changelog as if the section does not exist.
return Array.Empty<string>();
}

ReleaseSection section;
if (tag == null)
{
section = sections.FirstOrDefault(x => x.StartIndex < x.EndIndex);
if (section == null)
{
return Array.Empty<string>();
}
}
else
{
section = sections.FirstOrDefault(x => x.Caption.EqualsOrdinalIgnoreCase(tag));
if (section == null)
{
throw new Exception($"Could not find release section for '{tag}'.");
}
}

return content
.Skip(section.StartIndex + 1)
Expand Down
10 changes: 10 additions & 0 deletions tests/Fallout.Common.Tests/ChangelogTasksTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public void ExtractChangelogSectionNotes_ChangelogReferenceFile_ThrowsNoExceptio
act.Should().NotThrow();
}

[Fact]
public void Extracting_a_changelog_from_a_non_existing_file_returns_an_empty_collection()
{
// Arrange
var file = RootDirectory / "does-not-exist.md";

// Act / Assert
ChangelogTasks.ExtractChangelogSectionNotes(file).Should().BeEmpty();
}

[Fact]
public void GetReleaseSections_ChangelogReferenceFileWithoutReleaseHead_ReturnsEmpty()
{
Expand Down
Loading