Skip to content

Commit 6da7059

Browse files
committed
Change GitVersionConfiguration and BranchConfiguration to record type and extract interfaces.
1 parent be17f07 commit 6da7059

23 files changed

+343
-326
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public void GetReleaseBranchConfigReturnsAllReleaseBranches()
1313
{
1414
Branches = new Dictionary<string, BranchConfiguration>
1515
{
16-
{ "foo", new BranchConfiguration { Name = "foo" } },
17-
{ "bar", new BranchConfiguration { Name = "bar", IsReleaseBranch = true } },
18-
{ "baz", new BranchConfiguration { Name = "baz", IsReleaseBranch = true } }
16+
{ "foo", new BranchConfiguration() },
17+
{ "bar", new BranchConfiguration { IsReleaseBranch = true } },
18+
{ "baz", new BranchConfiguration { IsReleaseBranch = true } }
1919
}
2020
};
2121

src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ branches:
1919
track-merge-target: true
2020
regex: ^dev(elop)?(ment)?$
2121
source-branches: []
22+
is-source-branch-for: []
2223
tracks-release-branches: true
2324
is-release-branch: false
2425
is-mainline: false
@@ -32,6 +33,7 @@ branches:
3233
source-branches:
3334
- develop
3435
- release
36+
is-source-branch-for: []
3537
tracks-release-branches: false
3638
is-release-branch: false
3739
is-mainline: true
@@ -47,6 +49,7 @@ branches:
4749
- main
4850
- support
4951
- release
52+
is-source-branch-for: []
5053
tracks-release-branches: false
5154
is-release-branch: true
5255
is-mainline: false
@@ -63,6 +66,7 @@ branches:
6366
- feature
6467
- support
6568
- hotfix
69+
is-source-branch-for: []
6670
pre-release-weight: 30000
6771
pull-request:
6872
mode: ContinuousDelivery
@@ -77,6 +81,7 @@ branches:
7781
- feature
7882
- support
7983
- hotfix
84+
is-source-branch-for: []
8085
pre-release-weight: 30000
8186
hotfix:
8287
mode: ContinuousDelivery
@@ -88,6 +93,7 @@ branches:
8893
- main
8994
- support
9095
- hotfix
96+
is-source-branch-for: []
9197
pre-release-weight: 30000
9298
support:
9399
label: ''
@@ -97,6 +103,7 @@ branches:
97103
regex: ^support[/-]
98104
source-branches:
99105
- main
106+
is-source-branch-for: []
100107
tracks-release-branches: false
101108
is-release-branch: false
102109
is-mainline: true
@@ -114,6 +121,7 @@ branches:
114121
- pull-request
115122
- hotfix
116123
- support
124+
is-source-branch-for: []
117125
ignore:
118126
sha: []
119127
mode: ContinuousDelivery
@@ -124,6 +132,8 @@ track-merge-target: false
124132
track-merge-message: true
125133
commit-message-incrementing: Enabled
126134
regex: ''
135+
source-branches: []
136+
is-source-branch-for: []
127137
tracks-release-branches: false
128138
is-release-branch: false
129139
is-mainline: false

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,6 @@ public void RegexIsRequired()
7979
"See https://gitversion.net/docs/reference/configuration for more info");
8080
}
8181

82-
[Test]
83-
public void SourceBranchIsRequired()
84-
{
85-
const string text = @"
86-
next-version: 2.0.0
87-
branches:
88-
bug:
89-
regex: 'bug[/-]'
90-
label: bugfix";
91-
SetupConfigFileContent(text);
92-
var ex = Should.Throw<ConfigurationException>(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
93-
ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'source-branches'{System.Environment.NewLine}" +
94-
"See https://gitversion.net/docs/reference/configuration for more info");
95-
}
96-
9782
[Test(Description = "This test proves the configuration validation will fail early with a helpful message when a branch listed in source-branches has no configuration.")]
9883
public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsMissing()
9984
{

src/GitVersion.Core.Tests/Configuration/Init/InitScenarios.CanSetNextVersion.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ branches: {}
66
ignore:
77
sha: []
88
increment: None
9+
source-branches: []
10+
is-source-branch-for: []

src/GitVersion.Core.Tests/MergeMessageTests.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ namespace GitVersion.Core.Tests;
66
[TestFixture]
77
public class MergeMessageTests : TestBase
88
{
9-
private readonly GitVersionConfiguration configuration = new() { LabelPrefix = ConfigurationConstants.DefaultLabelPrefix };
9+
private readonly GitFlowConfigurationBuilder configurationBuilder = GitFlowConfigurationBuilder.New;
1010

1111
[Test]
1212
public void NullMessageStringThrows() =>
1313
// Act / Assert
14-
Should.Throw<ArgumentNullException>(() => new MergeMessage(null!, this.configuration));
14+
Should.Throw<ArgumentNullException>(() => new MergeMessage(null!, this.configurationBuilder.Build()));
1515

1616
[TestCase("")]
1717
[TestCase("\t\t ")]
1818
public void EmptyMessageString(string message)
1919
{
2020
// Act
21-
var sut = new MergeMessage(message, this.configuration);
21+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
2222

2323
// Assert
2424
sut.TargetBranch.ShouldBeNull();
@@ -67,7 +67,7 @@ public void ParsesMergeMessage(
6767
SemanticVersion expectedVersion)
6868
{
6969
// Act
70-
var sut = new MergeMessage(message, this.configuration);
70+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
7171

7272
// Assert
7373
sut.FormatName.ShouldBe("Default");
@@ -97,7 +97,7 @@ public void ParsesGitHubPullMergeMessage(
9797
int? expectedPullRequestNumber)
9898
{
9999
// Act
100-
var sut = new MergeMessage(message, this.configuration);
100+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
101101

102102
// Assert
103103
sut.FormatName.ShouldBe("GitHubPull");
@@ -132,7 +132,7 @@ public void ParsesBitBucketPullMergeMessage(
132132
int? expectedPullRequestNumber)
133133
{
134134
// Act
135-
var sut = new MergeMessage(message, this.configuration);
135+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
136136

137137
// Assert
138138
sut.FormatName.ShouldBe("BitBucketPull");
@@ -162,7 +162,7 @@ public void ParsesBitBucketPullMergeMessage_v7(
162162
int? expectedPullRequestNumber)
163163
{
164164
// Act
165-
var sut = new MergeMessage(message, this.configuration);
165+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
166166

167167
// Assert
168168
sut.FormatName.ShouldBe("BitBucketPullv7");
@@ -193,7 +193,7 @@ public void ParsesSmartGitMergeMessage(
193193
SemanticVersion expectedVersion)
194194
{
195195
// Act
196-
var sut = new MergeMessage(message, this.configuration);
196+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
197197

198198
// Assert
199199
sut.FormatName.ShouldBe("SmartGit");
@@ -224,7 +224,7 @@ public void ParsesRemoteTrackingMergeMessage(
224224
SemanticVersion expectedVersion)
225225
{
226226
// Act
227-
var sut = new MergeMessage(message, this.configuration);
227+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
228228

229229
// Assert
230230
sut.FormatName.ShouldBe("RemoteTracking");
@@ -247,7 +247,7 @@ public void ParsesRemoteTrackingMergeMessage(
247247
public void ParsesInvalidMergeMessage(string message)
248248
{
249249
// Act
250-
var sut = new MergeMessage(message, this.configuration);
250+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
251251

252252
// Assert
253253
sut.FormatName.ShouldBeNull();
@@ -264,13 +264,13 @@ public void MatchesSingleCustomMessage()
264264
// Arrange
265265
const string message = "My custom message";
266266
const string definition = "MyCustom";
267-
this.configuration.MergeMessageFormats = new Dictionary<string, string>
267+
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
268268
{
269269
[definition] = message
270-
};
270+
});
271271

272272
// Act
273-
var sut = new MergeMessage(message, this.configuration);
273+
var sut = new MergeMessage(message, this.configurationBuilder.Build());
274274

275275
// Assert
276276
sut.FormatName.ShouldBe(definition);
@@ -288,15 +288,15 @@ public void MatchesMultipleCustomMessages()
288288
// Arrange
289289
const string format = "My custom message";
290290
const string definition = "MyCustom";
291-
this.configuration.MergeMessageFormats = new Dictionary<string, string>
291+
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
292292
{
293293
["Default2"] = "some example",
294294
["Default3"] = "another example",
295295
[definition] = format
296-
};
296+
});
297297

298298
// Act
299-
var sut = new MergeMessage(format, this.configuration);
299+
var sut = new MergeMessage(format, this.configurationBuilder.Build());
300300

301301
// Assert
302302
sut.FormatName.ShouldBe(definition);
@@ -314,16 +314,16 @@ public void MatchesCaptureGroupsFromCustomMessages()
314314
// Arrange
315315
const string format = @"^Merged PR #(?<PullRequestNumber>\d+) into (?<TargetBranch>[^\s]*) from (?:(?<SourceBranch>[^\s]*))";
316316
const string definition = "MyCustom";
317-
this.configuration.MergeMessageFormats = new Dictionary<string, string>
317+
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
318318
{
319319
[definition] = format
320-
};
320+
});
321321
const int pr = 1234;
322322
const string target = MainBranch;
323323
const string source = "feature/2.0.0/example";
324324

325325
// Act
326-
var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", this.configuration);
326+
var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", this.configurationBuilder.Build());
327327

328328
// Assert
329329
sut.FormatName.ShouldBe(definition);
@@ -341,15 +341,15 @@ public void ReturnsAfterFirstMatchingPattern()
341341
// Arrange
342342
const string format = @"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*";
343343
const string definition = "MyCustom";
344-
this.configuration.MergeMessageFormats = new Dictionary<string, string>
344+
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
345345
{
346346
[definition] = format,
347347
["Default2"] = format,
348348
["Default3"] = format
349-
};
349+
});
350350

351351
// Act
352-
var sut = new MergeMessage("Merge branch 'this'", this.configuration);
352+
var sut = new MergeMessage("Merge branch 'this'", this.configurationBuilder.Build());
353353

354354
// Assert
355355
sut.FormatName.ShouldBe(definition);

src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ public void MergeFeatureIntoMainline()
148148
public void MergeFeatureIntoMainlineWithMinorIncrement()
149149
{
150150
var configuration = GitFlowConfigurationBuilder.New
151-
.WithIgnoreConfiguration(new())
152-
.WithMergeMessageFormats(new())
153151
.WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline))
154152
.WithBranch("feature", builder => builder
155153
.WithVersioningMode(VersioningMode.Mainline)
@@ -176,8 +174,6 @@ public void MergeFeatureIntoMainlineWithMinorIncrement()
176174
public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix()
177175
{
178176
var configuration = GitFlowConfigurationBuilder.New
179-
.WithIgnoreConfiguration(new())
180-
.WithMergeMessageFormats(new())
181177
.WithVersioningMode(VersioningMode.Mainline)
182178
.WithBranch("feature", builder => builder
183179
.WithIncrement(IncrementStrategy.Minor)
@@ -477,7 +473,7 @@ public void ShouldIgnorePreReleaseVersionInMainlineMode()
477473
nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion);
478474
}
479475

480-
private class TestIgnoreConfig : IgnoreConfiguration
476+
private record TestIgnoreConfig : IgnoreConfiguration
481477
{
482478
private readonly IVersionFilter filter;
483479

0 commit comments

Comments
 (0)