|
3 | 3 |
|
4 | 4 | namespace GitVersion.Core.Tests.Helpers;
|
5 | 5 |
|
6 |
| -public sealed class TestConfigurationBuilder |
| 6 | +// Please use GitFlowConfigurationBuilder or ScratchConfigurationBuilder class instead of this class. |
| 7 | +internal sealed class TestConfigurationBuilder : TestConfigurationBuilderBase<TestConfigurationBuilder> |
7 | 8 | {
|
8 | 9 | public static TestConfigurationBuilder New => new();
|
9 | 10 |
|
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 |
| - |
21 | 11 | private TestConfigurationBuilder()
|
22 | 12 | {
|
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); |
62 | 16 | }
|
63 | 17 |
|
64 |
| - public TestConfigurationBuilder WithoutAnyTrackMergeTargets() |
| 18 | + public TestConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(string branchName, bool? value) |
65 | 19 | {
|
66 |
| - withoutAnyTrackMergeTargets = true; |
67 |
| - trackMergeTargetsDictionary.Clear(); |
| 20 | + WithBranch(branchName).WithPreventIncrementOfMergedBranchVersion(value); |
68 | 21 | return this;
|
69 | 22 | }
|
70 | 23 |
|
71 |
| - public TestConfigurationBuilder WithPreventIncrementOfMergedBranchVersion(string branch, bool value) |
| 24 | + public TestConfigurationBuilder WithVersioningMode(string branchName, VersioningMode? value) |
72 | 25 | {
|
73 |
| - preventIncrementOfMergedBranchVersionDictionary[branch] = value; |
| 26 | + WithBranch(branchName).WithVersioningMode(value); |
74 | 27 | return this;
|
75 | 28 | }
|
76 | 29 |
|
77 |
| - public TestConfigurationBuilder WithIncrement(IncrementStrategy? value) |
| 30 | + public TestConfigurationBuilder WithoutTag(string branchName) |
78 | 31 | {
|
79 |
| - increment = value; |
| 32 | + WithBranch(branchName).WithTag(null); |
80 | 33 | return this;
|
81 | 34 | }
|
82 | 35 |
|
83 |
| - public TestConfigurationBuilder WithIncrement(string branch, IncrementStrategy value) |
| 36 | + public TestConfigurationBuilder WithTag(string branchName, string value) |
84 | 37 | {
|
85 |
| - incrementDictionary[branch] = value; |
| 38 | + WithBranch(branchName).WithTag(value); |
86 | 39 | return this;
|
87 | 40 | }
|
88 | 41 |
|
89 |
| - public TestConfigurationBuilder WithoutTag(string branch) |
| 42 | + public TestConfigurationBuilder WithoutVersioningMode(string branchName) |
90 | 43 | {
|
91 |
| - tagDictionary[branch] = null; |
| 44 | + WithBranch(branchName).WithVersioningMode(null); |
92 | 45 | return this;
|
93 | 46 | }
|
94 | 47 |
|
95 |
| - public TestConfigurationBuilder WithTag(string branch, string value) |
| 48 | + public TestConfigurationBuilder WithoutIncrement(string branchName) |
96 | 49 | {
|
97 |
| - tagDictionary[branch] = value; |
| 50 | + WithBranch(branchName).WithIncrement(null); |
98 | 51 | return this;
|
99 | 52 | }
|
100 | 53 |
|
101 |
| - public TestConfigurationBuilder WithIgnoreConfig(IgnoreConfiguration value) |
| 54 | + public TestConfigurationBuilder WithIncrement(string branchName, IncrementStrategy value) |
102 | 55 | {
|
103 |
| - ignoreConfig = value; |
| 56 | + WithBranch(branchName).WithIncrement(value); |
104 | 57 | return this;
|
105 | 58 | }
|
106 | 59 |
|
107 |
| - public GitVersionConfiguration Build() |
| 60 | + public TestConfigurationBuilder WithoutAnyTrackMergeTargets() |
108 | 61 | {
|
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) |
142 | 63 | {
|
143 |
| - configuration.Branches[item.Key].PreventIncrementOfMergedBranchVersion = item.Value; |
| 64 | + item.Value.WithTrackMergeTarget(false); |
144 | 65 | }
|
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; |
159 | 67 | }
|
160 | 68 | }
|
0 commit comments