Skip to content

Support for bitbucket pull request merge message #1375

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
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 @@ -54,6 +54,8 @@ public void ShouldNotAllowIncrementOfVersion()
[TestCase("Merge pull request #95 in Particular/issue-94", true, null)]
[TestCase("Merge pull request #95 in Particular/issue-94", false, null)]
[TestCase("Merge pull request #64 from arledesma/feature-VS2013_3rd_party_test_framework_support", true, null)]
[TestCase("Merge pull request #500 in FOO/bar from Particular/release-1.0.0 to develop)", true, "1.0.0")]
[TestCase("Merge pull request #500 in FOO/bar from feature/new-service to develop)", true, null)]
[TestCase("Finish Release-0.12.0", true, "0.12.0")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Release' branch
[TestCase("Finish 0.14.1", true, "0.14.1")] //Support Syntevo SmartGit/Hg's Gitflow merge commit messages for finishing a 'Hotfix' branch
[TestCase("Merge branch 'Release-v0.2.0'", true, "0.2.0")]
Expand Down
27 changes: 22 additions & 5 deletions src/GitVersionCore/MergeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class MergeMessage
static Regex parseGitHubPullMergeMessage = new Regex(
@"^Merge pull request #(?<PullRequestNumber>\d*) (from|in) (?<Source>.*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
static Regex parseBitBucketPullMergeMessage = new Regex(
@"^Merge pull request #(?<PullRequestNumber>\d*) (from|in) (?<Source>.*) from (?<SourceBranch>.*) to (?<TargetBranch>.*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
static Regex smartGitMergeMessage = new Regex(
@"^Finish (?<Branch>.*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
Expand Down Expand Up @@ -67,15 +70,19 @@ private string ParseBranch()
return match.Groups["Branch"].Value;
}

match = parseBitBucketPullMergeMessage.Match(mergeMessage);
if (match.Success)
{
IsMergedPullRequest = true;
PullRequestNumber = GetPullRequestNumber(match);
return match.Groups["SourceBranch"].Value;
}

match = parseGitHubPullMergeMessage.Match(mergeMessage);
if (match.Success)
{
IsMergedPullRequest = true;
int pullNumber;
if (int.TryParse(match.Groups["PullRequestNumber"].Value, out pullNumber))
{
PullRequestNumber = pullNumber;
}
PullRequestNumber = GetPullRequestNumber(match);
var from = match.Groups["Source"].Value;
// TODO We could remove/separate the remote name at this point?
return from;
Expand All @@ -91,6 +98,16 @@ private string ParseBranch()
return "";
}

private int GetPullRequestNumber(Match match)
{
int pullNumber;
if (int.TryParse(match.Groups["PullRequestNumber"].Value, out pullNumber))
{
PullRequestNumber = pullNumber;
}
return pullNumber;
}

public string TargetBranch { get; }
public string MergedBranch { get; }
public bool IsMergedPullRequest { get; private set; }
Expand Down