Skip to content

Commit 711107a

Browse files
committed
Create GitFlowConfigurationBuilder and ScratchConfigurationBuilder class.
1 parent 57aaae1 commit 711107a

8 files changed

+527
-128
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using GitVersion.Configuration;
2+
3+
namespace GitVersion.Core.Tests.Helpers;
4+
5+
internal sealed class GitFlowConfigurationBuilder : TestConfigurationBuilderBase<GitFlowConfigurationBuilder>
6+
{
7+
public static GitFlowConfigurationBuilder New => new();
8+
9+
private GitFlowConfigurationBuilder()
10+
{
11+
ConfigurationBuilder configurationBuilder = new();
12+
var configuration = configurationBuilder.Build();
13+
WithConfiguration(configuration);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace GitVersion.Core.Tests.Helpers;
2+
3+
internal sealed class ScratchConfigurationBuilder : TestConfigurationBuilderBase<ScratchConfigurationBuilder>
4+
{
5+
public static ScratchConfigurationBuilder New => new();
6+
7+
private ScratchConfigurationBuilder()
8+
{
9+
}
10+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
using GitVersion.Configuration;
2+
using GitVersion.VersionCalculation;
3+
4+
namespace GitVersion.Core.Tests.Helpers;
5+
6+
public class TestBranchConfigurationBuilder
7+
{
8+
public static TestBranchConfigurationBuilder New => new();
9+
10+
private string name;
11+
private VersioningMode? versioningMode;
12+
private string? tag;
13+
private IncrementStrategy? increment;
14+
private bool? preventIncrementOfMergedBranchVersion;
15+
private string? tagNumberPattern;
16+
private bool? trackMergeTarget;
17+
private CommitMessageIncrementMode? commitMessageIncrementing;
18+
private string? regex;
19+
private HashSet<string>? sourceBranches;
20+
private HashSet<string>? isSourceBranchFor;
21+
private bool? tracksReleaseBranches;
22+
private bool? isReleaseBranch;
23+
private bool? isMainline;
24+
private int? preReleaseWeight;
25+
26+
private TestBranchConfigurationBuilder() => this.name = "Just-A-Test";
27+
28+
public virtual TestBranchConfigurationBuilder WithName(string value)
29+
{
30+
this.name = value;
31+
return this;
32+
}
33+
34+
public virtual TestBranchConfigurationBuilder WithVersioningMode(VersioningMode? value)
35+
{
36+
this.versioningMode = value;
37+
return this;
38+
}
39+
40+
public virtual TestBranchConfigurationBuilder WithTag(string? value)
41+
{
42+
this.tag = value;
43+
return this;
44+
}
45+
46+
public virtual TestBranchConfigurationBuilder WithIncrement(IncrementStrategy? value)
47+
{
48+
this.increment = value;
49+
return this;
50+
}
51+
52+
public virtual TestBranchConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(bool? value)
53+
{
54+
this.preventIncrementOfMergedBranchVersion = value;
55+
return this;
56+
}
57+
58+
public virtual TestBranchConfigurationBuilder WithTagNumberPattern(string? value)
59+
{
60+
this.tagNumberPattern = value;
61+
return this;
62+
}
63+
64+
public virtual TestBranchConfigurationBuilder WithTrackMergeTarget(bool? value)
65+
{
66+
this.trackMergeTarget = value;
67+
return this;
68+
}
69+
70+
public virtual TestBranchConfigurationBuilder WithCommitMessageIncrementing(CommitMessageIncrementMode? value)
71+
{
72+
this.commitMessageIncrementing = value;
73+
return this;
74+
}
75+
76+
public virtual TestBranchConfigurationBuilder WithRegex(string? value)
77+
{
78+
this.regex = value;
79+
return this;
80+
}
81+
82+
public virtual TestBranchConfigurationBuilder WithSourceBranches(IEnumerable<string> values)
83+
{
84+
WithSourceBranches(values.ToArray());
85+
return this;
86+
}
87+
88+
public virtual TestBranchConfigurationBuilder WithSourceBranches(params string[] values)
89+
{
90+
this.sourceBranches = new HashSet<string>(values);
91+
return this;
92+
}
93+
94+
public virtual TestBranchConfigurationBuilder WithIsSourceBranchFor(IEnumerable<string> values)
95+
{
96+
WithIsSourceBranchFor(values.ToArray());
97+
return this;
98+
}
99+
100+
public virtual TestBranchConfigurationBuilder WithIsSourceBranchFor(params string[] values)
101+
{
102+
this.isSourceBranchFor = new HashSet<string>(values);
103+
return this;
104+
}
105+
106+
public virtual TestBranchConfigurationBuilder WithTracksReleaseBranches(bool? value)
107+
{
108+
this.tracksReleaseBranches = value;
109+
return this;
110+
}
111+
112+
public virtual TestBranchConfigurationBuilder WithIsReleaseBranch(bool? value)
113+
{
114+
this.isReleaseBranch = value;
115+
return this;
116+
}
117+
118+
public virtual TestBranchConfigurationBuilder WithIsMainline(bool? value)
119+
{
120+
this.isMainline = value;
121+
return this;
122+
}
123+
124+
public virtual TestBranchConfigurationBuilder WithPreReleaseWeight(int? value)
125+
{
126+
this.preReleaseWeight = value;
127+
return this;
128+
}
129+
130+
public virtual TestBranchConfigurationBuilder WithConfiguration(BranchConfiguration value)
131+
{
132+
WithName(value.Name);
133+
WithVersioningMode(value.VersioningMode);
134+
WithTag(value.Tag);
135+
WithIncrement(value.Increment);
136+
WithPreventIncrementOfMergedBranchVersion(value.PreventIncrementOfMergedBranchVersion);
137+
WithTagNumberPattern(value.TagNumberPattern);
138+
WithTrackMergeTarget(value.TrackMergeTarget);
139+
WithCommitMessageIncrementing(value.CommitMessageIncrementing);
140+
WithRegex(value.Regex);
141+
WithTracksReleaseBranches(value.TracksReleaseBranches);
142+
WithIsReleaseBranch(value.IsReleaseBranch);
143+
WithIsMainline(value.IsMainline);
144+
WithPreReleaseWeight(value.PreReleaseWeight);
145+
WithSourceBranches(value.SourceBranches ?? Enumerable.Empty<string>());
146+
WithIsSourceBranchFor(value.IsSourceBranchFor ?? Enumerable.Empty<string>());
147+
return this;
148+
}
149+
150+
public BranchConfiguration Build()
151+
{
152+
var result = new BranchConfiguration()
153+
{
154+
Name = name,
155+
VersioningMode = versioningMode,
156+
Tag = tag,
157+
Increment = increment,
158+
Regex = regex,
159+
TracksReleaseBranches = tracksReleaseBranches,
160+
TrackMergeTarget = trackMergeTarget,
161+
CommitMessageIncrementing = commitMessageIncrementing,
162+
IsMainline = isMainline,
163+
IsReleaseBranch = isReleaseBranch,
164+
TagNumberPattern = tagNumberPattern,
165+
PreventIncrementOfMergedBranchVersion = preventIncrementOfMergedBranchVersion,
166+
PreReleaseWeight = preReleaseWeight,
167+
SourceBranches = sourceBranches,
168+
IsSourceBranchFor = isSourceBranchFor
169+
};
170+
return result;
171+
}
172+
}

src/GitVersion.Core.Tests/Helpers/TestConfigurationBuilder.cs

Lines changed: 23 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3,158 +3,66 @@
33

44
namespace GitVersion.Core.Tests.Helpers;
55

6-
public sealed class TestConfigurationBuilder
6+
// Please use GitFlowConfigurationBuilder or ScratchConfigurationBuilder class instead of this class.
7+
internal sealed class TestConfigurationBuilder : TestConfigurationBuilderBase<TestConfigurationBuilder>
78
{
89
public static TestConfigurationBuilder New => new();
910

10-
private string? nextVersion;
11-
private VersioningMode? versioningMode;
12-
private readonly Dictionary<string, VersioningMode?> versioningModeDictionary = new();
13-
private bool withoutAnyTrackMergeTargets;
14-
private readonly Dictionary<string, bool> trackMergeTargetsDictionary = new();
15-
private readonly Dictionary<string, bool> preventIncrementOfMergedBranchVersionDictionary = new();
16-
private IncrementStrategy? increment;
17-
private readonly Dictionary<string, IncrementStrategy> incrementDictionary = new();
18-
private readonly Dictionary<string, string?> tagDictionary = new();
19-
private IgnoreConfiguration? ignoreConfig;
20-
2111
private TestConfigurationBuilder()
2212
{
23-
withoutAnyTrackMergeTargets = false;
24-
increment = IncrementStrategy.Inherit;
25-
versioningMode = VersioningMode.ContinuousDelivery;
26-
}
27-
28-
public TestConfigurationBuilder WithNextVersion(string? value)
29-
{
30-
nextVersion = value;
31-
return this;
32-
}
33-
34-
public TestConfigurationBuilder WithVersioningMode(VersioningMode value)
35-
{
36-
versioningMode = value;
37-
return this;
38-
}
39-
40-
public TestConfigurationBuilder WithoutVersioningMode()
41-
{
42-
versioningMode = null;
43-
return this;
44-
}
45-
46-
public TestConfigurationBuilder WithVersioningMode(string branch, VersioningMode value)
47-
{
48-
versioningModeDictionary[branch] = value;
49-
return this;
50-
}
51-
52-
public TestConfigurationBuilder WithoutVersioningMode(string branch)
53-
{
54-
versioningModeDictionary[branch] = null;
55-
return this;
56-
}
57-
58-
public TestConfigurationBuilder WithTrackMergeTarget(string branch, bool value)
59-
{
60-
trackMergeTargetsDictionary[branch] = value;
61-
return this;
13+
ConfigurationBuilder configurationBuilder = new();
14+
var configuration = configurationBuilder.Build();
15+
WithConfiguration(configuration);
6216
}
6317

64-
public TestConfigurationBuilder WithoutAnyTrackMergeTargets()
18+
public TestConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(string branchName, bool? value)
6519
{
66-
withoutAnyTrackMergeTargets = true;
67-
trackMergeTargetsDictionary.Clear();
20+
WithBranch(branchName).WithPreventIncrementOfMergedBranchVersion(value);
6821
return this;
6922
}
7023

71-
public TestConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(string branch, bool value)
24+
public TestConfigurationBuilder WithVersioningMode(string branchName, VersioningMode? value)
7225
{
73-
preventIncrementOfMergedBranchVersionDictionary[branch] = value;
26+
WithBranch(branchName).WithVersioningMode(value);
7427
return this;
7528
}
7629

77-
public TestConfigurationBuilder WithIncrement(IncrementStrategy? value)
30+
public TestConfigurationBuilder WithoutTag(string branchName)
7831
{
79-
increment = value;
32+
WithBranch(branchName).WithTag(null);
8033
return this;
8134
}
8235

83-
public TestConfigurationBuilder WithIncrement(string branch, IncrementStrategy value)
36+
public TestConfigurationBuilder WithTag(string branchName, string value)
8437
{
85-
incrementDictionary[branch] = value;
38+
WithBranch(branchName).WithTag(value);
8639
return this;
8740
}
8841

89-
public TestConfigurationBuilder WithoutTag(string branch)
42+
public TestConfigurationBuilder WithoutVersioningMode(string branchName)
9043
{
91-
tagDictionary[branch] = null;
44+
WithBranch(branchName).WithVersioningMode(null);
9245
return this;
9346
}
9447

95-
public TestConfigurationBuilder WithTag(string branch, string value)
48+
public TestConfigurationBuilder WithoutIncrement(string branchName)
9649
{
97-
tagDictionary[branch] = value;
50+
WithBranch(branchName).WithIncrement(null);
9851
return this;
9952
}
10053

101-
public TestConfigurationBuilder WithIgnoreConfig(IgnoreConfiguration value)
54+
public TestConfigurationBuilder WithIncrement(string branchName, IncrementStrategy value)
10255
{
103-
ignoreConfig = value;
56+
WithBranch(branchName).WithIncrement(value);
10457
return this;
10558
}
10659

107-
public GitVersionConfiguration Build()
60+
public TestConfigurationBuilder WithoutAnyTrackMergeTargets()
10861
{
109-
GitVersionConfiguration configuration = new()
110-
{
111-
NextVersion = nextVersion,
112-
VersioningMode = versioningMode
113-
};
114-
115-
if (ignoreConfig != null)
116-
{
117-
configuration.Ignore = ignoreConfig;
118-
}
119-
120-
ConfigurationBuilder configurationBuilder = new();
121-
configuration = configurationBuilder.Add(configuration).Build();
122-
123-
if (withoutAnyTrackMergeTargets)
124-
{
125-
foreach (var branchConfiguration in configuration.Branches.Values)
126-
{
127-
branchConfiguration.TrackMergeTarget = false;
128-
}
129-
}
130-
131-
foreach (var item in trackMergeTargetsDictionary)
132-
{
133-
configuration.Branches[item.Key].TrackMergeTarget = item.Value;
134-
}
135-
136-
foreach (var item in versioningModeDictionary)
137-
{
138-
configuration.Branches[item.Key].VersioningMode = item.Value;
139-
}
140-
141-
foreach (var item in preventIncrementOfMergedBranchVersionDictionary)
62+
foreach (var item in base.branchConfigurationBuilders)
14263
{
143-
configuration.Branches[item.Key].PreventIncrementOfMergedBranchVersion = item.Value;
64+
item.Value.WithTrackMergeTarget(false);
14465
}
145-
146-
configuration.Increment = increment;
147-
148-
foreach (var item in incrementDictionary)
149-
{
150-
configuration.Branches[item.Key].Increment = item.Value;
151-
}
152-
153-
foreach (var item in tagDictionary)
154-
{
155-
configuration.Branches[item.Key].Tag = item.Value;
156-
}
157-
158-
return configuration;
66+
return this;
15967
}
16068
}

0 commit comments

Comments
 (0)