Skip to content

Commit

Permalink
feat: exclamation mark to signifying breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
saintedlama authored and cabauman committed May 13, 2022
1 parent 7f59f11 commit 74576d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Versionize.Tests/ConventionalCommitParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Xunit;
using LibGit2Sharp;
using Shouldly;
using Xunit;

namespace Versionize.Tests;

Expand Down Expand Up @@ -58,6 +59,19 @@ public void ShouldExtractCommitNotes()
Assert.Equal("BREAKING CHANGE", breakingChangeNote.Title);
Assert.Equal("this will break rc1 compatibility", breakingChangeNote.Text);
}

[Theory]
[InlineData("feat!: broadcast $destroy: event on scope destruction")]
[InlineData("feat(scope)!: broadcast $destroy: event on scope destruction")]
public void ShouldSupportExclamationMarkToSignifyingBreakingChanges(string commitMessage)
{
var testCommit = new TestCommit("c360d6a307909c6e571b29d4a329fd786c5d4543", commitMessage);
var conventionalCommit = ConventionalCommitParser.Parse(testCommit);

conventionalCommit.Notes.ShouldHaveSingleItem();
conventionalCommit.Notes[0].Title.ShouldBe("BREAKING CHANGE");
conventionalCommit.Notes[0].Text.ShouldBe(string.Empty);
}
}

public class TestCommit : Commit
Expand Down
13 changes: 11 additions & 2 deletions Versionize/ConventionalCommitParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class ConventionalCommitParser
{
private static readonly string[] NoteKeywords = new string[] { "BREAKING CHANGE" };

private static readonly Regex HeaderPattern = new Regex("^(?<type>\\w*)(?:\\((?<scope>.*)\\))?: (?<subject>.*)$", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);
private static readonly Regex HeaderPattern = new("^(?<type>\\w*)(?:\\((?<scope>.*)\\))?(?<breakingChangeMarker>!)?: (?<subject>.*)$", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);

public static List<ConventionalCommit> Parse(List<Commit> commits)
{
Expand Down Expand Up @@ -43,6 +43,15 @@ public static ConventionalCommit Parse(Commit commit)
conventionalCommit.Scope = match.Groups["scope"].Value;
conventionalCommit.Type = match.Groups["type"].Value;
conventionalCommit.Subject = match.Groups["subject"].Value;

if (match.Groups["breakingChangeMarker"].Success)
{
conventionalCommit.Notes.Add(new ConventionalCommitNote
{
Title = "BREAKING CHANGE",
Text = string.Empty
});
}
}
else
{
Expand All @@ -59,7 +68,7 @@ public static ConventionalCommit Parse(Commit commit)
conventionalCommit.Notes.Add(new ConventionalCommitNote
{
Title = noteKeyword,
Text = line.Substring($"{noteKeyword}:".Length).TrimStart()
Text = line[$"{noteKeyword}:".Length..].TrimStart()
});
}
}
Expand Down

0 comments on commit 74576d4

Please sign in to comment.