Skip to content

Commit e09d248

Browse files
committed
Fix no minor version detected on pull request that contains organization name
1 parent a0eef6b commit e09d248

15 files changed

+87
-73
lines changed

src/GitVersion.Core.Tests/Configuration/ConfigurationExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void GetReleaseBranchConfigReturnsAllReleaseBranches()
4040
[TestCase("refs/remotes/origin/release/2.0.0",
4141
"refs/remotes/origin/release/2.0.0", "origin/release/2.0.0", "release/2.0.0",
4242
false, false, true, false, true)]
43-
public void EnsureIsReleaseBranchWithReferenceNameWorksAsExpected(string branchName, string expectedCanonical, string expectedFriendly, string expectedWithoutRemote,
43+
public void EnsureIsReleaseBranchWithReferenceNameWorksAsExpected(string branchName, string expectedCanonical, string expectedFriendly, string expectedWithoutOrigin,
4444
bool expectedIsLocalBranch, bool expectedIsPullRequest, bool expectedIsRemoteBranch, bool expectedIsTag, bool expectedIsReleaseBranch)
4545
{
4646
var configuration = GitFlowConfigurationBuilder.New.Build();
@@ -50,7 +50,7 @@ public void EnsureIsReleaseBranchWithReferenceNameWorksAsExpected(string branchN
5050

5151
actual.Canonical.ShouldBe(expectedCanonical);
5252
actual.Friendly.ShouldBe(expectedFriendly);
53-
actual.WithoutRemote.ShouldBe(expectedWithoutRemote);
53+
actual.WithoutOrigin.ShouldBe(expectedWithoutOrigin);
5454
actual.IsLocalBranch.ShouldBe(expectedIsLocalBranch);
5555
actual.IsPullRequest.ShouldBe(expectedIsPullRequest);
5656
actual.IsRemoteBranch.ShouldBe(expectedIsRemoteBranch);

src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static IBranch CreateMockBranch(string name, params ICommit[] commits)
4646
}
4747

4848
public static IBranch FindBranch(this IGitRepository repository, string branchName)
49-
=> repository.Branches.FirstOrDefault(branch => branch.Name.WithoutRemote == branchName)
49+
=> repository.Branches.FirstOrDefault(branch => branch.Name.WithoutOrigin == branchName)
5050
?? throw new GitVersionException($"Branch {branchName} not found");
5151

5252
public static void DumpGraph(this IGitRepository repository, Action<string>? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.Path, writer, maxCommits);

src/GitVersion.Core.Tests/MergeMessageTests.cs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class MergeMessageTests : TestBase
1111
[Test]
1212
public void NullMessageStringThrows() =>
1313
// Act / Assert
14-
Should.Throw<NullReferenceException>(() => new MergeMessage(null, this.configuration));
14+
Should.Throw<ArgumentNullException>(() => new MergeMessage(null!, this.configuration));
1515

1616
[TestCase("")]
1717
[TestCase("\t\t ")]
@@ -22,7 +22,7 @@ public void EmptyMessageString(string message)
2222

2323
// Assert
2424
sut.TargetBranch.ShouldBeNull();
25-
sut.MergedBranch.ShouldBeEmpty();
25+
sut.MergedBranch.ShouldBeNull();
2626
sut.IsMergedPullRequest.ShouldBeFalse();
2727
sut.PullRequestNumber.ShouldBe(null);
2828
sut.Version.ShouldBeNull();
@@ -42,7 +42,7 @@ public void EmptyTagPrefix(string prefix)
4242

4343
// Assert
4444
sut.TargetBranch.ShouldBeNull();
45-
sut.MergedBranch.ShouldBeEmpty();
45+
sut.MergedBranch.ShouldBeNull();
4646
sut.IsMergedPullRequest.ShouldBeFalse();
4747
sut.PullRequestNumber.ShouldBe(null);
4848
sut.Version.ShouldBeNull();
@@ -72,21 +72,20 @@ public void ParsesMergeMessage(
7272
// Assert
7373
sut.FormatName.ShouldBe("Default");
7474
sut.TargetBranch.ShouldBe(expectedTargetBranch);
75-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
75+
sut.MergedBranch.ShouldNotBeNull();
76+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
7677
sut.IsMergedPullRequest.ShouldBeFalse();
7778
sut.PullRequestNumber.ShouldBe(null);
7879
sut.Version.ShouldBe(expectedVersion);
7980
}
8081

8182
private static readonly object?[] GitHubPullPullMergeMessages =
8283
{
83-
new object?[] { "Merge pull request #1234 from feature/one", "feature/one", null, null, 1234 },
84-
new object?[] { "Merge pull request #1234 in feature/one", "feature/one", null, null, 1234 },
84+
new object?[] { "Merge pull request #1234 from organization/feature/one", "feature/one", null, null, 1234 },
85+
new object?[] { "Merge pull request #1234 in organization/feature/one", "feature/one", null, null, 1234 },
8586
new object?[] { "Merge pull request #1234 in v4.0.0", "v4.0.0", null, new SemanticVersion(4), 1234 },
86-
new object?[] { "Merge pull request #1234 from origin/feature/one", "origin/feature/one", null, null, 1234 },
87-
new object?[] { "Merge pull request #1234 in feature/4.1.0/one", "feature/4.1.0/one", null, new SemanticVersion(4,1), 1234 },
88-
new object?[] { "Merge pull request #1234 in V://10.10.10.10", "V://10.10.10.10", null, null, 1234 },
89-
new object?[] { "Merge pull request #1234 from feature/one into dev", "feature/one", "dev", null, 1234 }
87+
new object?[] { "Merge pull request #1234 in organization/feature/4.1.0/one", "feature/4.1.0/one", null, new SemanticVersion(4,1), 1234 },
88+
new object?[] { "Merge pull request #1234 from organization/feature/one into dev", "feature/one", "dev", null, 1234 }
9089
};
9190

9291
[TestCaseSource(nameof(GitHubPullPullMergeMessages))]
@@ -103,7 +102,8 @@ public void ParsesGitHubPullMergeMessage(
103102
// Assert
104103
sut.FormatName.ShouldBe("GitHubPull");
105104
sut.TargetBranch.ShouldBe(expectedTargetBranch);
106-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
105+
sut.MergedBranch.ShouldNotBeNull();
106+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
107107
sut.IsMergedPullRequest.ShouldBeTrue();
108108
sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber);
109109
sut.Version.ShouldBe(expectedVersion);
@@ -137,7 +137,8 @@ public void ParsesBitBucketPullMergeMessage(
137137
// Assert
138138
sut.FormatName.ShouldBe("BitBucketPull");
139139
sut.TargetBranch.ShouldBe(expectedTargetBranch);
140-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
140+
sut.MergedBranch.ShouldNotBeNull();
141+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
141142
sut.IsMergedPullRequest.ShouldBeTrue();
142143
sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber);
143144
sut.Version.ShouldBe(expectedVersion);
@@ -166,7 +167,8 @@ public void ParsesBitBucketPullMergeMessage_v7(
166167
// Assert
167168
sut.FormatName.ShouldBe("BitBucketPullv7");
168169
sut.TargetBranch.ShouldBe(expectedTargetBranch);
169-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
170+
sut.MergedBranch.ShouldNotBeNull();
171+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
170172
sut.IsMergedPullRequest.ShouldBeTrue();
171173
sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber);
172174
sut.Version.ShouldBe(expectedVersion);
@@ -196,7 +198,8 @@ public void ParsesSmartGitMergeMessage(
196198
// Assert
197199
sut.FormatName.ShouldBe("SmartGit");
198200
sut.TargetBranch.ShouldBe(expectedTargetBranch);
199-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
201+
sut.MergedBranch.ShouldNotBeNull();
202+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
200203
sut.IsMergedPullRequest.ShouldBeFalse();
201204
sut.PullRequestNumber.ShouldBe(null);
202205
sut.Version.ShouldBe(expectedVersion);
@@ -226,37 +229,33 @@ public void ParsesRemoteTrackingMergeMessage(
226229
// Assert
227230
sut.FormatName.ShouldBe("RemoteTracking");
228231
sut.TargetBranch.ShouldBe(expectedTargetBranch);
229-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
232+
sut.MergedBranch.ShouldNotBeNull();
233+
sut.MergedBranch.Friendly.ShouldBe(expectedMergedBranch);
230234
sut.IsMergedPullRequest.ShouldBeFalse();
231235
sut.PullRequestNumber.ShouldBe(null);
232236
sut.Version.ShouldBe(expectedVersion);
233237
}
234238

235239
private static readonly object?[] InvalidMergeMessages =
236240
{
237-
new object?[] { "Merge pull request # from feature/one", "", null, null, null },
238-
new object?[] { $"Merge pull request # in feature/one from feature/two to {MainBranch}" , "", null, null, null },
239-
new object?[] { $"Zusammengeführter PR : feature/one mit {MainBranch} mergen", "", null, null, null }
241+
new object?[] { "Merge pull request # from feature/one" },
242+
new object?[] { $"Merge pull request # in feature/one from feature/two to {MainBranch}" },
243+
new object?[] { $"Zusammengeführter PR : feature/one mit {MainBranch} mergen" }
240244
};
241245

242246
[TestCaseSource(nameof(InvalidMergeMessages))]
243-
public void ParsesInvalidMergeMessage(
244-
string message,
245-
string expectedMergedBranch,
246-
string expectedTargetBranch,
247-
SemanticVersion expectedVersion,
248-
int? expectedPullRequestNumber)
247+
public void ParsesInvalidMergeMessage(string message)
249248
{
250249
// Act
251250
var sut = new MergeMessage(message, this.configuration);
252251

253252
// Assert
254253
sut.FormatName.ShouldBeNull();
255-
sut.TargetBranch.ShouldBe(expectedTargetBranch);
256-
sut.MergedBranch.ShouldBe(expectedMergedBranch);
254+
sut.TargetBranch.ShouldBeNull();
255+
sut.MergedBranch.ShouldBeNull();
257256
sut.IsMergedPullRequest.ShouldBeFalse();
258-
sut.PullRequestNumber.ShouldBe(expectedPullRequestNumber);
259-
sut.Version.ShouldBe(expectedVersion);
257+
sut.PullRequestNumber.ShouldBeNull();
258+
sut.Version.ShouldBeNull();
260259
}
261260

262261
[Test]
@@ -276,7 +275,8 @@ public void MatchesSingleCustomMessage()
276275
// Assert
277276
sut.FormatName.ShouldBe(definition);
278277
sut.TargetBranch.ShouldBeNull();
279-
sut.MergedBranch.ShouldBeEmpty();
278+
sut.MergedBranch.ShouldNotBeNull();
279+
sut.MergedBranch.Friendly.ShouldBeEmpty();
280280
sut.IsMergedPullRequest.ShouldBeFalse();
281281
sut.PullRequestNumber.ShouldBe(null);
282282
sut.Version.ShouldBeNull();
@@ -301,7 +301,8 @@ public void MatchesMultipleCustomMessages()
301301
// Assert
302302
sut.FormatName.ShouldBe(definition);
303303
sut.TargetBranch.ShouldBeNull();
304-
sut.MergedBranch.ShouldBeEmpty();
304+
sut.MergedBranch.ShouldNotBeNull();
305+
sut.MergedBranch.Friendly.ShouldBeEmpty();
305306
sut.IsMergedPullRequest.ShouldBeFalse();
306307
sut.PullRequestNumber.ShouldBe(null);
307308
sut.Version.ShouldBeNull();
@@ -327,7 +328,8 @@ public void MatchesCaptureGroupsFromCustomMessages()
327328
// Assert
328329
sut.FormatName.ShouldBe(definition);
329330
sut.TargetBranch.ShouldBe(target);
330-
sut.MergedBranch.ShouldBe(source);
331+
sut.MergedBranch.ShouldNotBeNull();
332+
sut.MergedBranch.Friendly.ShouldBe(source);
331333
sut.IsMergedPullRequest.ShouldBeTrue();
332334
sut.PullRequestNumber.ShouldBe(pr);
333335
sut.Version.ShouldBe(new SemanticVersion(2));
@@ -352,7 +354,8 @@ public void ReturnsAfterFirstMatchingPattern()
352354
// Assert
353355
sut.FormatName.ShouldBe(definition);
354356
sut.TargetBranch.ShouldBeNull();
355-
sut.MergedBranch.ShouldBe("this");
357+
sut.MergedBranch.ShouldNotBeNull();
358+
sut.MergedBranch.Friendly.ShouldBe("this");
356359
sut.IsMergedPullRequest.ShouldBeFalse();
357360
sut.PullRequestNumber.ShouldBe(null);
358361
sut.Version.ShouldBeNull();

src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public void ShouldNotTakeVersionFromMergeOfNonReleaseBranch(string message, bool
104104
AssertMergeMessage(message + "\n ", null, parents);
105105
}
106106

107-
[TestCase("Merge pull request #165 from Particular/release-1.0.0", true)]
108-
[TestCase("Merge pull request #165 in Particular/release-1.0.0", true)]
109-
[TestCase("Merge pull request #500 in FOO/bar from Particular/release-1.0.0 to develop)", true)]
107+
[TestCase("Merge pull request #165 from organization/Particular/release-1.0.0", true)]
108+
[TestCase("Merge pull request #165 in organization/Particular/release-1.0.0", true)]
109+
[TestCase("Merge pull request #500 in FOO/bar from organization/Particular/release-1.0.0 to develop)", true)]
110110
public void ShouldNotTakeVersionFromMergeOfReleaseBranchWithRemoteOtherThanOrigin(string message, bool isMergeCommit)
111111
{
112112
var parents = GetParents(isMergeCommit);

src/GitVersion.Core/Configuration/ConfigurationExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ public static BranchConfiguration GetBranchConfiguration(this GitVersionConfigur
2020

2121
public static BranchConfiguration GetBranchConfiguration(this GitVersionConfiguration configuration, ReferenceName branchName)
2222
{
23-
var branchConfiguration = GetBranchConfigurations(configuration, branchName.WithoutRemote).FirstOrDefault();
24-
branchConfiguration ??= new() { Name = branchName.WithoutRemote, Regex = string.Empty, Label = ConfigurationConstants.BranchNamePlaceholder, Increment = IncrementStrategy.Inherit };
23+
var branchConfiguration = GetBranchConfigurations(configuration, branchName.WithoutOrigin).FirstOrDefault();
24+
branchConfiguration ??= new()
25+
{
26+
Name = branchName.WithoutOrigin,
27+
Regex = string.Empty,
28+
Label = ConfigurationConstants.BranchNamePlaceholder,
29+
Increment = IncrementStrategy.Inherit
30+
};
2531
return branchConfiguration;
2632
}
2733

src/GitVersion.Core/Core/MainlineBranchFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public bool IsMainline(BranchConfiguration value)
6060
return false;
6161

6262
var mainlineRegex = value.Regex;
63-
var branchName = this.branch.Name.WithoutRemote;
63+
var branchName = this.branch.Name.WithoutOrigin;
6464
var match = Regex.IsMatch(branchName, mainlineRegex);
6565
this.log.Info($"'{mainlineRegex}' {(match ? "matches" : "does not match")} '{branchName}'.");
6666
return match;

src/GitVersion.Core/Core/MergeCommitFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public IEnumerable<BranchCommit> FindMergeCommitsFor(IBranch branch)
3636

3737
this.mergeBaseCommitsCache.Add(branch, branchMergeBases);
3838

39-
return branchMergeBases.Where(b => !branch.Name.EquivalentTo(b.Branch.Name.WithoutRemote));
39+
return branchMergeBases.Where(b => !branch.Name.EquivalentTo(b.Branch.Name.WithoutOrigin));
4040
}
4141

4242
private IEnumerable<BranchCommit> FindMergeBases(IBranch branch)

src/GitVersion.Core/Core/RepositoryStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public IBranch GetTargetBranch(string? targetBranchName)
113113
}
114114

115115
return this.repository.Branches.FirstOrDefault(b =>
116-
Regex.IsMatch(b.Name.WithoutRemote, mainBranchRegex, RegexOptions.IgnoreCase));
116+
Regex.IsMatch(b.Name.WithoutOrigin, mainBranchRegex, RegexOptions.IgnoreCase));
117117
}
118118

119119
public IEnumerable<IBranch> FindMainlineBranches(GitVersionConfiguration configuration)
@@ -134,7 +134,7 @@ public IEnumerable<IBranch> GetReleaseBranches(IEnumerable<KeyValuePair<string,
134134
=> this.repository.Branches.Where(b => IsReleaseBranch(b, releaseBranchConfig));
135135

136136
private static bool IsReleaseBranch(INamedReference branch, IEnumerable<KeyValuePair<string, BranchConfiguration>> releaseBranchConfig)
137-
=> releaseBranchConfig.Any(c => c.Value.Regex != null && Regex.IsMatch(branch.Name.WithoutRemote, c.Value.Regex));
137+
=> releaseBranchConfig.Any(c => c.Value.Regex != null && Regex.IsMatch(branch.Name.WithoutOrigin, c.Value.Regex));
138138

139139
public IEnumerable<IBranch> ExcludingBranches(IEnumerable<IBranch> branchesToExclude) => this.repository.Branches.ExcludeBranches(branchesToExclude);
140140

src/GitVersion.Core/Core/SourceBranchFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public bool IsSourceBranch(INamedReference sourceBranchCandidate)
3737
if (Equals(sourceBranchCandidate, this.branch))
3838
return false;
3939

40-
var branchName = sourceBranchCandidate.Name.WithoutRemote;
40+
var branchName = sourceBranchCandidate.Name.WithoutOrigin;
4141

4242
return this.sourceBranchRegexes.Any(regex => Regex.IsMatch(branchName, regex));
4343
}

src/GitVersion.Core/Git/ReferenceName.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ReferenceName : IEquatable<ReferenceName?>, IComparable<ReferenceNa
1212
public const string LocalBranchPrefix = "refs/heads/";
1313
public const string RemoteTrackingBranchPrefix = "refs/remotes/";
1414
public const string TagPrefix = "refs/tags/";
15-
public const string RemotePrefix = "origin/";
15+
public const string OriginPrefix = "origin/";
1616

1717
private static readonly string[] PullRequestPrefixes =
1818
{
@@ -32,7 +32,7 @@ public ReferenceName(string canonical)
3232
IsPullRequest = IsPrefixedBy(Canonical, PullRequestPrefixes);
3333

3434
Friendly = Shorten();
35-
WithoutRemote = RemoveRemote();
35+
WithoutOrigin = RemoveOrigin();
3636
}
3737

3838
public static ReferenceName Parse(string canonicalName)
@@ -64,7 +64,7 @@ public static ReferenceName FromBranchName(string branchName)
6464

6565
public string Canonical { get; }
6666
public string Friendly { get; }
67-
public string WithoutRemote { get; }
67+
public string WithoutOrigin { get; }
6868
public bool IsLocalBranch { get; }
6969
public bool IsRemoteBranch { get; }
7070
public bool IsTag { get; }
@@ -79,7 +79,7 @@ public static ReferenceName FromBranchName(string branchName)
7979
public bool EquivalentTo(string? name) =>
8080
Canonical.Equals(name, StringComparison.OrdinalIgnoreCase)
8181
|| Friendly.Equals(name, StringComparison.OrdinalIgnoreCase)
82-
|| WithoutRemote.Equals(name, StringComparison.OrdinalIgnoreCase);
82+
|| WithoutOrigin.Equals(name, StringComparison.OrdinalIgnoreCase);
8383

8484
private string Shorten()
8585
{
@@ -95,11 +95,11 @@ private string Shorten()
9595
return Canonical;
9696
}
9797

98-
private string RemoveRemote()
98+
private string RemoveOrigin()
9999
{
100-
if (IsRemoteBranch && !IsPullRequest && Friendly.StartsWith(RemotePrefix, StringComparison.Ordinal))
100+
if (IsRemoteBranch && !IsPullRequest && Friendly.StartsWith(OriginPrefix, StringComparison.Ordinal))
101101
{
102-
return Friendly[RemotePrefix.Length..];
102+
return Friendly[OriginPrefix.Length..];
103103
}
104104
return Friendly;
105105
}

0 commit comments

Comments
 (0)