Skip to content

Commit ab638a1

Browse files
committed
add new regex and some refactoring
1 parent c533986 commit ab638a1

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/GitVersionCore/MergeMessage.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class MergeMessage
1212
static Regex parseGitHubPullMergeMessage = new Regex(
1313
@"^Merge pull request #(?<PullRequestNumber>\d*) (from|in) (?<Source>.*)",
1414
RegexOptions.IgnoreCase | RegexOptions.Compiled);
15+
static Regex parseBitBucketPullMergeMessage = new Regex(
16+
@"^Merge pull request #(?<PullRequestNumber>\d*) (from|in) (?<Source>.*) from (?<SourceBranch>.*) to (?<TargetBranch>.*)",
17+
RegexOptions.IgnoreCase | RegexOptions.Compiled);
1518
static Regex smartGitMergeMessage = new Regex(
1619
@"^Finish (?<Branch>.*)",
1720
RegexOptions.IgnoreCase | RegexOptions.Compiled);
@@ -67,15 +70,19 @@ private string ParseBranch()
6770
return match.Groups["Branch"].Value;
6871
}
6972

73+
match = parseBitBucketPullMergeMessage.Match(mergeMessage);
74+
if (match.Success)
75+
{
76+
IsMergedPullRequest = true;
77+
PullRequestNumber = GetPullRequestNumber(match);
78+
return match.Groups["SourceBranch"].Value;
79+
}
80+
7081
match = parseGitHubPullMergeMessage.Match(mergeMessage);
7182
if (match.Success)
7283
{
7384
IsMergedPullRequest = true;
74-
int pullNumber;
75-
if (int.TryParse(match.Groups["PullRequestNumber"].Value, out pullNumber))
76-
{
77-
PullRequestNumber = pullNumber;
78-
}
85+
PullRequestNumber = GetPullRequestNumber(match);
7986
var from = match.Groups["Source"].Value;
8087
// TODO We could remove/separate the remote name at this point?
8188
return from;
@@ -91,6 +98,16 @@ private string ParseBranch()
9198
return "";
9299
}
93100

101+
private int GetPullRequestNumber(Match match)
102+
{
103+
int pullNumber;
104+
if (int.TryParse(match.Groups["PullRequestNumber"].Value, out pullNumber))
105+
{
106+
PullRequestNumber = pullNumber;
107+
}
108+
return pullNumber;
109+
}
110+
94111
public string TargetBranch { get; }
95112
public string MergedBranch { get; }
96113
public bool IsMergedPullRequest { get; private set; }

0 commit comments

Comments
 (0)