Skip to content

[SPIKE] A more strict approach for finding versions in commit messages #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2015
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ public void AssertMergeMessage(string message, bool isMergeCommit, string expect
AssertMergeMessage(message + "\n ", expectedVersion, parents);
}

[TestCase(@"Merge pull request #1 in FOO/bar from feature/ISSUE-1 to develop

* commit '38560a7eed06e8d3f3f1aaf091befcdf8bf50fea':
Updated jQuery to v2.1.3")]
[TestCase(@"Merge pull request #45 in BRIKKS/brikks from feature/NOX-68 to develop

* commit '38560a7eed06e8d3f3f1aaf091befcdf8bf50fea':
Another commit message
Commit message including a IP-number https://10.50.1.1
A commit message")]
[TestCase(@"Merge branch 'release/Sprint_2.0_Holdings_Computed_Balances'")]
public void MergeMessagesThatsNotRelatedToGitVersion(string commitMessage)
{

var parents = GetParents(true);

AssertMergeMessage(commitMessage, null, parents);
}

static void AssertMergeMessage(string message, string expectedVersion, List<Commit> parents)
{
var commit = new MockCommit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace GitVersion.VersionCalculation.BaseVersionCalculators
{
using System;
using System.Linq;
using System.Text.RegularExpressions;
using LibGit2Sharp;

public class MergeMessageBaseVersionStrategy : BaseVersionStrategy
Expand Down Expand Up @@ -42,39 +42,16 @@ private static SemanticVersion Inner(Commit mergeCommit, EffectiveConfiguration
return null;
}

return mergeCommit
.Message.Split('/', '-', '\'', '"', ' ')
var possibleVersions = Regex.Matches(mergeCommit.Message, @"^.*?(-|/|'|Finish )(?<PossibleVersions>\d+\.\d+\.\d+)")
.Cast<Match>()
.Select(m => m.Groups["PossibleVersions"].Value);

return possibleVersions
.Select(part =>
{
SemanticVersion v;
return SemanticVersion.TryParse(part, configuration.GitTagPrefix, out v) ? v : null;
}).FirstOrDefault(v => v != null)
;

}

static bool TryGetPrefix(string target, out string result, string splitter)
{
var indexOf = target.IndexOf(splitter, StringComparison.Ordinal);
if (indexOf == -1)
{
result = null;
return false;
}
result = target.Substring(0, indexOf);
return true;
}

static bool TryGetSuffix(string target, out string result, string splitter)
{
var indexOf = target.IndexOf(splitter, StringComparison.Ordinal);
if (indexOf == -1)
{
result = null;
return false;
}
result = target.Substring(indexOf + 1, target.Length - indexOf - 1);
return true;
}).FirstOrDefault(v => v != null);
}
}
}