diff --git a/src/ConventionalChangelog/Configuration.cs b/src/ConventionalChangelog/Configuration.cs index d83ea37..6b0ed22 100644 --- a/src/ConventionalChangelog/Configuration.cs +++ b/src/ConventionalChangelog/Configuration.cs @@ -6,6 +6,8 @@ namespace ConventionalChangelog; public class Configuration : IConfiguration, IComparer { + private const string ConventionalCommitSeparator = ": "; // see https://www.conventionalcommits.org/en/v1.0.0/#specification + // language=regex private const string BreakingChangeIndicator = "(?[a-z]+)!"; // language=regex @@ -54,7 +56,9 @@ private Configuration(IEnumerable commitTypes, string versionTagPref _order = order; } - public string TypeFor(string typeIndicator, IEnumerable footers) + public string Separator => ConventionalCommitSeparator; + + public string Sanitize(string typeIndicator, IEnumerable footers) { if (footers.Any(x => x is IPrintable)) return typeIndicator.ReplaceWith(BreakingChangeIndicator, "inner"); @@ -74,7 +78,7 @@ private CommitType InnerTypeFor(string typeIndicator) public bool IsVersionTag(string tagName) => tagName.Matches(_versionTagPrefix + SemanticVersionPattern); - public IEnumerable Ordered(IEnumerable logEntries) where T: IHasCommitType + public IEnumerable Ordered(IEnumerable logEntries) where T : IHasCommitType { if (_order == ChangelogOrder.OldestToNewest) logEntries = logEntries.Reverse(); diff --git a/src/ConventionalChangelog/Conventional/MessageParser.cs b/src/ConventionalChangelog/Conventional/MessageParser.cs index b8a1688..c57eb17 100644 --- a/src/ConventionalChangelog/Conventional/MessageParser.cs +++ b/src/ConventionalChangelog/Conventional/MessageParser.cs @@ -4,7 +4,6 @@ namespace ConventionalChangelog.Conventional; public class MessageParser { - private const string Separator = ": "; // see https://www.conventionalcommits.org/en/v1.0.0/#specification private readonly IConfiguration _configuration; public MessageParser(IConfiguration configuration) @@ -22,21 +21,21 @@ private CommitMessage Read(TextReader lines) { var (typeIndicator, description) = HeaderFrom(lines.ReadLine()); var (body, footers) = BodyFrom(lines); - typeIndicator = _configuration.TypeFor(typeIndicator, footers); + typeIndicator = _configuration.Sanitize(typeIndicator, footers); return new CommitMessage(typeIndicator, description, body, footers); } #if NET6_0 - private static (string, string) HeaderFrom(string? header) + private (string, string) HeaderFrom(string? header) { - var twoParts = header?.Split(Separator); + var twoParts = header?.Split(_configuration.Separator); return twoParts?.Length == 2 ? (twoParts.First(), twoParts.Last().Trim()) : ("", ""); } #elif NET7_0_OR_GREATER - private static (string, string) HeaderFrom(string? header) => header?.Split(Separator) is [var first, var second] + private (string, string) HeaderFrom(string? header) => header?.Split(_configuration.Separator) is [var first, var second] ? (first,second.Trim()) : ("", ""); #endif diff --git a/src/ConventionalChangelog/IConfiguration.cs b/src/ConventionalChangelog/IConfiguration.cs index 709218c..2ab05ce 100644 --- a/src/ConventionalChangelog/IConfiguration.cs +++ b/src/ConventionalChangelog/IConfiguration.cs @@ -4,7 +4,7 @@ namespace ConventionalChangelog; public interface IConfiguration { - string TypeFor(string typeIndicator, IEnumerable footers); + string Sanitize(string typeIndicator, IEnumerable footers); ChangelogType TypeFor(string typeIndicator); bool IsFooter(string line); @@ -13,4 +13,6 @@ public interface IConfiguration IEnumerable Ordered(IEnumerable logEntries) where T: IHasCommitType; bool IsVersionTag(string tagName); + + string Separator { get; } }