Skip to content

Commit 506b6ec

Browse files
authored
Merge pull request #3433 from HHobeck/feature/change-configuration-to-record-type-and-extract-interfaces
Change GitVersionConfiguration and BranchConfiguration to record type and extract interfaces
2 parents be17f07 + 642a7da commit 506b6ec

File tree

48 files changed

+593
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+593
-553
lines changed

schemas/6.0/GitVersion.configuration.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"$ref": "#/$defs/string1"
8585
},
8686
"label-prefix": {
87-
"description": "A regex which is used to trim Git tags before processing. Defaults to [vV]?",
87+
"description": "A regular expression which is used to trim Git tags before processing. Defaults to [vV]?",
8888
"type": "string"
8989
},
9090
"label-pre-release-weight": {
@@ -97,7 +97,7 @@
9797
"major-version-bump-message": {
9898
"format": "regex",
9999
"pattern": "\u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
100-
"description": "The regex to match commit messages with to perform a major version increment. Default set to \u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
100+
"description": "The regular expression to match commit messages with to perform a major version increment. Default set to \u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
101101
"type": "string"
102102
},
103103
"merge-message-formats": {
@@ -110,7 +110,7 @@
110110
"minor-version-bump-message": {
111111
"format": "regex",
112112
"pattern": "\u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
113-
"description": "The regex to match commit messages with to perform a minor version increment. Default set to \u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
113+
"description": "The regular expression to match commit messages with to perform a minor version increment. Default set to \u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
114114
"type": "string"
115115
},
116116
"next-version": {
@@ -126,7 +126,7 @@
126126
"patch-version-bump-message": {
127127
"format": "regex",
128128
"pattern": "\u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
129-
"description": "The regex to match commit messages with to perform a patch version increment. Default set to \u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
129+
"description": "The regular expression to match commit messages with to perform a patch version increment. Default set to \u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
130130
"type": "string"
131131
},
132132
"pre-release-weight": {
@@ -246,7 +246,7 @@
246246
]
247247
},
248248
"Nullable\u006012": {
249-
"description": "Indicates this branch config represents a release branch in GitFlow.",
249+
"description": "Indicates this branch configuration represents a release branch in GitFlow.",
250250
"type": [
251251
"boolean",
252252
"null"
@@ -267,7 +267,7 @@
267267
"string1": {
268268
"format": "regex",
269269
"pattern": "[/-](?\u003Cnumber\u003E\\d\u002B)[-/]",
270-
"description": "The regex pattern to use to extract the number from the branch name. Defaults to \u0027[/-](?\u003Cnumber\u003E\\d\u002B)[-/]\u0027.",
270+
"description": "The regular expression pattern to use to extract the number from the branch name. Defaults to \u0027[/-](?\u003Cnumber\u003E\\d\u002B)[-/]\u0027.",
271271
"type": "string"
272272
},
273273
"Nullable\u006013": {
@@ -285,7 +285,7 @@
285285
]
286286
},
287287
"string2": {
288-
"description": "The regex pattern to use to match this branch.",
288+
"description": "The regular expression pattern to use to match this branch.",
289289
"type": "string"
290290
},
291291
"array1": {
@@ -311,7 +311,7 @@
311311
]
312312
},
313313
"Nullable\u006017": {
314-
"description": "Indicates this branch config represents develop in GitFlow.",
314+
"description": "Indicates this branch configuration represents develop in GitFlow.",
315315
"type": [
316316
"boolean",
317317
"null"

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

+3-3
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

+10
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

+2-17
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
{
@@ -139,7 +124,7 @@ public void CanProvideConfigForNewBranch()
139124
SetupConfigFileContent(text);
140125
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
141126

142-
configuration.Branches["bug"].Regex.ShouldBe("bug[/-]");
127+
configuration.Branches["bug"].RegularExpression.ShouldBe("bug[/-]");
143128
configuration.Branches["bug"].Label.ShouldBe("bugfix");
144129
}
145130

@@ -179,7 +164,7 @@ public void CanWriteOutEffectiveConfiguration()
179164
{
180165
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
181166

182-
configuration.ToString().ShouldMatchApproved();
167+
configuration.ToString()!.ShouldMatchApproved();
183168
}
184169

185170
[Test]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void WhenBadDateFormatShouldFail()
7373
[Test]
7474
public void NewInstanceShouldBeEmpty()
7575
{
76-
var ignoreConfig = new IgnoreConfiguration();
76+
IIgnoreConfiguration ignoreConfig = new IgnoreConfiguration();
7777

7878
ignoreConfig.IsEmpty.ShouldBeTrue();
7979
}

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

+2
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/Extensions/GitToolsTestingExtensions.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public static class GitToolsTestingExtensions
1919
public static ICommit CreateMockCommit()
2020
{
2121
var objectId = Substitute.For<IObjectId>();
22-
objectId.Sha.Returns(Guid.NewGuid().ToString("n") + "00000000");
23-
22+
var sha = Guid.NewGuid().ToString("n") + "00000000";
23+
objectId.Sha.Returns(sha);
2424
var commit = Substitute.For<ICommit>();
2525
commit.Id.Returns(objectId);
26-
commit.Sha.Returns(objectId.Sha);
26+
commit.Sha.Returns(sha);
2727
commit.Message.Returns("Commit " + commitCount++);
2828
commit.Parents.Returns(Enumerable.Empty<ICommit>());
2929
commit.When.Returns(when.AddSeconds(1));
@@ -49,11 +49,14 @@ public static IBranch FindBranch(this IGitRepository repository, string branchNa
4949
=> repository.Branches.FirstOrDefault(branch => branch.Name.WithoutOrigin == branchName)
5050
?? throw new GitVersionException($"Branch {branchName} not found");
5151

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

54-
public static void DumpGraph(this IRepository repository, Action<string>? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits);
55+
public static void DumpGraph(this IRepository repository, Action<string>? writer = null, int? maxCommits = null)
56+
=> GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits);
5557

56-
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
58+
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, IGitVersionConfiguration? configuration = null,
59+
IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
5760
{
5861
repository ??= fixture.Repository;
5962
configuration ??= GitFlowConfigurationBuilder.New.Build();
@@ -106,7 +109,8 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str
106109
writer.Write(versionInfo.ToString());
107110
}
108111

109-
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
112+
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver,
113+
IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
110114
{
111115
repository ??= fixture.Repository;
112116

src/GitVersion.Core.Tests/IntegrationTests/DevelopScenarios.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommi
396396
)
397397
.WithBranch("hotfix", builder => builder
398398
.WithPreventIncrementOfMergedBranchVersion(true)
399-
.WithRegex("^(origin/)?hotfix[/-]")
399+
.WithRegularExpression("^(origin/)?hotfix[/-]")
400400
)
401401
.Build();
402402

src/GitVersion.Core.Tests/IntegrationTests/FeatureBranchScenarios.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
4040
var configuration = GitFlowConfigurationBuilder.New
4141
.WithBranch("unstable", builder => builder
4242
.WithIncrement(IncrementStrategy.Minor)
43-
.WithRegex("unstable")
43+
.WithRegularExpression("unstable")
4444
.WithSourceBranches()
4545
.WithIsSourceBranchFor("feature"))
4646
.Build();

src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label,
6868
var configuration = GitFlowConfigurationBuilder.New
6969
.WithBranch("other", builder => builder
7070
.WithIncrement(IncrementStrategy.Patch)
71-
.WithRegex(".*")
71+
.WithRegularExpression(".*")
7272
.WithSourceBranches()
7373
.WithLabel(label))
7474
.Build();

0 commit comments

Comments
 (0)