Skip to content

Commit

Permalink
Merge pull request #7 from Crown0815/feature/#5_Add-Enhances-as-alias…
Browse files Browse the repository at this point in the history
…-for-Fixes

Feature/#5 add enhances as alias for fixes
  • Loading branch information
Crown0815 authored Sep 26, 2023
2 parents a805c71 + 1360756 commit c96a9cb
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
global-json-file: /global.json
global-json-file: global.json

- name: Install dependencies
run: dotnet restore
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "7.0.100",
"version": "7.0.306",
"rollForward": "latestPatch",
"allowPrerelease": false
}
}
}
18 changes: 10 additions & 8 deletions src/ConventionalChangelog/Changelog.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using System.Text.RegularExpressions;
using ConventionalChangelog.Conventional;
using LibGit2Sharp;
using static ConventionalChangelog.ChangelogOrder;
using static ConventionalChangelog.Configuration;

namespace ConventionalChangelog;

public static class Changelog
{
public static string From(params Commit[] messages) => From(messages.Select(CommitMessage.Parse));

private static string From(IEnumerable<CommitMessage> messages)
public static string From(IEnumerable<Commit> messages, ChangelogOrder order)
{
return messages
var logEntries = messages.Select(CommitMessage.Parse)
.Reduce()
.SelectMany(LogEntries)
.SelectMany(LogEntries);
if (order == OldestToNewest)
logEntries = logEntries.Reverse();

return logEntries
.OrderBy(x => x.Type, Comparer)
.Aggregate(new LogAggregate(), Add).ToString();
}
Expand All @@ -29,14 +32,13 @@ private static IEnumerable<LogEntry> LogEntries(CommitMessage commitMessage)
yield return new LogEntry(commitMessage.Type, commitMessage.Description);
}

public static string FromRepository(string path)
public static string FromRepository(string path, ChangelogOrder order = NewestToOldest)
{
using var repo = new Repository(path);
var dict = repo.Tags.GroupBy(x => x.Target).ToDictionary(x => x.Key, x => x.ToList());

var tag = (object)null!;


var filter0 = new CommitFilter
{
SortBy = CommitSortStrategies.Topological,
Expand All @@ -58,7 +60,7 @@ public static string FromRepository(string path)
ExcludeReachableFrom = tag,
};

return From(repo.Commits.QueryBy(filter).Select(AsCommit).ToArray());
return From(repo.Commits.QueryBy(filter).Select(AsCommit).ToArray(), order);
}

private static Commit AsCommit(LibGit2Sharp.Commit c) => new(c.Message, c.Sha);
Expand Down
7 changes: 7 additions & 0 deletions src/ConventionalChangelog/ChangelogOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ConventionalChangelog;

public enum ChangelogOrder
{
NewestToOldest,
OldestToNewest,
}
2 changes: 1 addition & 1 deletion src/ConventionalChangelog/MessageLinq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class MessageLinq

private static readonly Strategy[] Strategies =
{
new("fix(es|up)", true, true, true),
new("fix(es|up)|enhances", true, true, true),
new("reverts?", false, false, true),
new("overrides?", false, true, false),
};
Expand Down
4 changes: 4 additions & 0 deletions test/ConventionalChangelog.Unit.Tests/A.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System.Linq;
using ConventionalChangelog.Conventional;
using static System.Environment;
using static ConventionalChangelog.ChangelogOrder;

namespace ConventionalChangelog.Unit.Tests;

internal static class A
{
internal class Changelog
{
public static string From(params Commit[] messages) =>
ConventionalChangelog.Changelog.From(messages, NewestToOldest);

private const string ChangelogTitle = "# Changelog";
private const string GeneralCodeImprovementsMessage = "*General Code Improvements*";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class A_changelog_from
[MemberData(nameof(NullCases))]
public void null_throws_null_exception(params Commit[] nullCase)
{
Action fromNull = () => Changelog.From(nullCase);
Action fromNull = () => A.Changelog.From(nullCase);
fromNull.Should().Throw<Exception>();
}

Expand All @@ -32,7 +32,7 @@ public void null_throws_null_exception(params Commit[] nullCase)
[MemberData(nameof(EmptyCases))]
public void empty_changes_is_empty(params Commit[] noChanges)
{
var changelog = Changelog.From(noChanges);
var changelog = A.Changelog.From(noChanges);
changelog.Should().Be(A.Changelog.Empty);
}

Expand All @@ -41,7 +41,7 @@ public void empty_changes_is_empty(params Commit[] noChanges)
[InlineData("1234: abc")]
public void non_conventional_commits_is_empty(string nonConventionalCommitMessage)
{
var changelog = Changelog.From(new Commit(nonConventionalCommitMessage));
var changelog = A.Changelog.From(new Commit(nonConventionalCommitMessage));
changelog.Should().Be(A.Changelog.Empty);
}

Expand All @@ -58,7 +58,7 @@ public void changelog_irrelevant_conventional_commits_contains_general_code_impr
var type = indicator.ToCommitType();
var conventionalCommit1 = type.CommitWith("unused description");
var conventionalCommit2 = type.CommitWith("unused description");
var changelog = Changelog.From(conventionalCommit1, conventionalCommit2);
var changelog = A.Changelog.From(conventionalCommit1, conventionalCommit2);
changelog.Should().Be(A.Changelog.WithGeneralCodeImprovementsMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void is_the_changelog_header_plus_a_group_containing_the_descriptions(Com
var message1 = type.CommitWithDescription(1);
var message2 = type.CommitWithDescription(2);

var changelog = Changelog.From(message1, message2);
var changelog = A.Changelog.From(message1, message2);

changelog.Should().Be(A.Changelog.WithGroup(type, 1, 2));
}
Expand All @@ -32,7 +32,7 @@ public void and_irrelevant_commits_contains_all_relevant_entries()
var message1 = Feature.CommitWithDescription(1);
var message2 = Irrelevant.CommitWithDescription(2);

var changelog = Changelog.From(message1, message2);
var changelog = A.Changelog.From(message1, message2);

changelog.Should().Be(A.Changelog.WithGroup(Feature, 1));
}
Expand All @@ -50,7 +50,7 @@ public void in_random_order_is_for_each_type_the_changelog_header_plus_a_group_c
Bugfix.CommitWithDescription(6),
};

var changelog = Changelog.From(messages);
var changelog = A.Changelog.From(messages);

changelog.Should().Be(A.Changelog
.WithGroup(Feature, 1, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void commit_type_contains_message_within_special_breaking_changes_group()
{
var breakingChange = Breaking(Feature).CommitWithDescription(1);

var changelog = Changelog.From(breakingChange);
var changelog = A.Changelog.From(breakingChange);

changelog.Should().Be(A.Changelog
.WithGroup(BreakingChange, 1));
Expand All @@ -32,7 +32,7 @@ public void commit_type_and_non_breaking_commit_type_contains_breaking_changes_a
var breakingChange = Breaking(Feature).CommitWithDescription(1);
var anotherChange = Feature.CommitWithDescription(2);

var changelog = Changelog.From(breakingChange, anotherChange);
var changelog = A.Changelog.From(breakingChange, anotherChange);

changelog.Should().Be(A.Changelog
.WithGroup(BreakingChange, 1)
Expand All @@ -52,7 +52,7 @@ public void footer_contains_the_breaking_change_description_followed_by_the_comm
var breakingChange = Feature.CommitWithDescription(1)
.WithFooter(token, 2);

var changelog = Changelog.From(breakingChange);
var changelog = A.Changelog.From(breakingChange);

changelog.Should().Be(A.Changelog
.WithGroup(BreakingChange, 2)
Expand All @@ -66,7 +66,7 @@ public void footer_and_breaking_type_contains_the_breaking_change_description_fo
var breakingChange = Breaking(Feature).CommitWithDescription(1)
.WithFooter(token, 2);

var changelog = Changelog.From(breakingChange);
var changelog = A.Changelog.From(breakingChange);

changelog.Should().Be(A.Changelog
.WithGroup(BreakingChange, 2)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using FluentAssertions;
using Xunit;
using Base = ConventionalChangelog.Unit.Tests.Changelog_specs.A_changelog_from_changelog_relevant_conventional_commits;

namespace ConventionalChangelog.Unit.Tests.Changelog_specs;

public partial class A_changelog_from_changelog_relevant_conventional_commits
{
public class With_fixing_commits
{
private const string DefaultFixToken = "Fixes";
private const string LegacyFixToken = "FixUp";
private const string AlternativeFixToken = "Enhances";
private readonly Commit _target;
private readonly Commit _fixing;

public With_fixing_commits()
{
_target = CommitTypeFor.Feature.CommitWithDescription(1);
_fixing = CommitTypeFor.Feature.CommitWithDescription(2).WithFooter(DefaultFixToken, _target.Hash);
}

[Fact]
public void when_the_fixed_commit_is_part_of_the_changelog_excludes_the_fixing_commit_from_the_changelog()
{
var changelog = A.Changelog.From(_fixing, _target);

changelog.Should().Be(A.Changelog.WithGroup(CommitTypeFor.Feature, 1));
}

[Theory]
[CaseVariantData(DefaultFixToken)]
[CaseVariantData(LegacyFixToken)]
[CaseVariantData(AlternativeFixToken)]
public void recognizes_fixing_commits_by_the(string footer)
{
var fixing = CommitTypeFor.Feature.CommitWithDescription(2).WithFooter(footer, _target.Hash);
var changelog = A.Changelog.From(fixing, _target);

changelog.Should().Be(A.Changelog.WithGroup(CommitTypeFor.Feature, 1));
}

[Fact]
public void
when_a_fixed_fixing_commit_is_part_of_the_changelog_excludes_the_fixing_commit_from_the_changelog()
{
var fixing2 = CommitTypeFor.Feature.CommitWithDescription(3).WithFooter(DefaultFixToken, _fixing.Hash);

var changelog = A.Changelog.From(fixing2, _fixing, _target);

changelog.Should().Be(A.Changelog.WithGroup(CommitTypeFor.Feature, 1));
}

[Fact]
public void
when_multiple_fixing_commits_target_a_single_commit_that_is_part_of_the_changelog_excludes_all_the_fixing_commits_from_the_changelog()
{
var fixing2 = CommitTypeFor.Feature.CommitWithDescription(3).WithFooter(DefaultFixToken, _target.Hash);

var changelog = A.Changelog.From(fixing2, _fixing, _target);

changelog.Should().Be(A.Changelog.WithGroup(CommitTypeFor.Feature, 1));
}

[Fact]
public void when_the_fixed_commit_is_not_part_of_the_changelog_includes_fixing_commit_in_the_changelog()
{
var fixing2 = CommitTypeFor.Feature.CommitWithDescription(3).WithFooter(DefaultFixToken, "randomHash");

var changelog = A.Changelog.From(fixing2, _fixing, _target);

changelog.Should().Be(A.Changelog.WithGroup(CommitTypeFor.Feature, 3, 1));
}
}
}
Loading

0 comments on commit c96a9cb

Please sign in to comment.