Skip to content

Commit 88d51cc

Browse files
committed
ConfigurationProvider cleanup
1 parent 46f41fd commit 88d51cc

13 files changed

+241
-241
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void CanReadDefaultDocument()
260260
config.AssemblyInformationalFormat.ShouldBe(null);
261261
config.Branches["develop"].Tag.ShouldBe("alpha");
262262
config.Branches["release"].Tag.ShouldBe("beta");
263-
config.TagPrefix.ShouldBe(ConfigurationProvider.DefaultTagPrefix);
263+
config.TagPrefix.ShouldBe(ConfigurationConstants.DefaultTagPrefix);
264264
config.NextVersion.ShouldBe(null);
265265
}
266266

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class GitToolsTestingExtensions
1717
{
1818
public static Config ApplyDefaults(this Config config)
1919
{
20-
ConfigurationProvider.ApplyDefaultsTo(config);
20+
ConfigurationUtils.ApplyDefaultsTo(config);
2121
return config;
2222
}
2323

@@ -26,7 +26,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
2626
if (configuration == null)
2727
{
2828
configuration = new Config();
29-
ConfigurationProvider.ApplyDefaultsTo(configuration);
29+
ConfigurationUtils.ApplyDefaultsTo(configuration);
3030
}
3131

3232
var log = new NullLog();
@@ -55,7 +55,7 @@ public static void AssertFullSemver(this RepositoryFixtureBase fixture, string f
5555

5656
public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
5757
{
58-
ConfigurationProvider.ApplyDefaultsTo(configuration);
58+
ConfigurationUtils.ApplyDefaultsTo(configuration);
5959
Console.WriteLine("---------");
6060

6161
try

src/GitVersionCore.Tests/GitVersionContextBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public GitVersionContextBuilder AddBranch(string branchName)
6363
public GitVersionContext Build()
6464
{
6565
var configuration = config ?? new Config();
66-
ConfigurationProvider.ApplyDefaultsTo(configuration);
66+
ConfigurationUtils.ApplyDefaultsTo(configuration);
6767
var repo = repository ?? CreateRepository();
6868
return new GitVersionContext(repo, new NullLog(), repo.Head, configuration);
6969
}

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void CanInheritVersioningMode(VersioningMode mode)
2121
{
2222
VersioningMode = mode
2323
};
24-
ConfigurationProvider.ApplyDefaultsTo(config);
24+
ConfigurationUtils.ApplyDefaultsTo(config);
2525

2626
var mockBranch = new MockBranch("master") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
2727
var mockRepository = new MockRepository
@@ -50,7 +50,7 @@ public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy?
5050
{
5151
Increment = increment
5252
};
53-
ConfigurationProvider.ApplyDefaultsTo(config);
53+
ConfigurationUtils.ApplyDefaultsTo(config);
5454

5555
using var fixture = new EmptyRepositoryFixture();
5656
fixture.MakeACommit();
@@ -78,7 +78,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
7878
}
7979
}
8080
};
81-
ConfigurationProvider.ApplyDefaultsTo(config);
81+
ConfigurationUtils.ApplyDefaultsTo(config);
8282
var develop = new MockBranch("develop") { new MockCommit { CommitterEx = Generate.SignatureNow() } };
8383
var mockRepository = new MockRepository
8484
{

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public void AssemblySemFileVerShouldBeWeightedByPreReleaseWeight()
532532
fixture.Repository.MakeCommits(5);
533533
fixture.Repository.CreateBranch("release-2.0.0");
534534
fixture.Checkout("release-2.0.0");
535-
ConfigurationProvider.ApplyDefaultsTo(config);
535+
ConfigurationUtils.ApplyDefaultsTo(config);
536536
var variables = fixture.GetVersion(config);
537537
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.1001");
538538
}
@@ -549,7 +549,7 @@ public void AssemblySemFileVerShouldBeWeightedByDefaultPreReleaseWeight()
549549
fixture.Repository.MakeCommits(5);
550550
fixture.Repository.CreateBranch("release-2.0.0");
551551
fixture.Checkout("release-2.0.0");
552-
ConfigurationProvider.ApplyDefaultsTo(config);
552+
ConfigurationUtils.ApplyDefaultsTo(config);
553553
var variables = fixture.GetVersion(config);
554554
Assert.AreEqual(variables.AssemblySemFileVer, "2.0.0.30001");
555555
}

src/GitVersionCore.Tests/SemanticVersionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class SemanticVersionTests : TestBase
2929
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null)]
3030
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null)]
3131
[TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null, null)]
32-
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, ConfigurationProvider.DefaultTagPrefix)]
33-
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)]
34-
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationProvider.DefaultTagPrefix)]
32+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, ConfigurationConstants.DefaultTagPrefix)]
33+
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationConstants.DefaultTagPrefix)]
34+
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationConstants.DefaultTagPrefix)]
3535
[TestCase("version-1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", "version-")]
3636
public void ValidateVersionParsing(
3737
string versionString, int major, int minor, int patch, string tag, int? tagNumber, int? numberOfBuilds,

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public BranchConfig GetBranchConfiguration(Branch targetBranch, IList<Branch> ex
3232
log.Info($"No branch configuration found for branch {targetBranch.FriendlyName}, falling back to default configuration");
3333

3434
matchingBranches = new BranchConfig { Name = FallbackConfigName };
35-
ConfigurationProvider.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
35+
ConfigurationUtils.ApplyBranchDefaults(context.FullConfiguration, matchingBranches, "", new List<string>());
3636
}
3737

3838
if (matchingBranches.Increment == IncrementStrategy.Inherit)
@@ -132,8 +132,8 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
132132
else
133133
errorMessage = "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.FriendlyName));
134134

135-
var developBranchRegex = config.Branches[ConfigurationProvider.DevelopBranchKey].Regex;
136-
var masterBranchRegex = config.Branches[ConfigurationProvider.MasterBranchKey].Regex;
135+
var developBranchRegex = config.Branches[ConfigurationConstants.DevelopBranchKey].Regex;
136+
var masterBranchRegex = config.Branches[ConfigurationConstants.MasterBranchKey].Regex;
137137

138138
var chosenBranch = repository.Branches.FirstOrDefault(b => Regex.IsMatch(b.FriendlyName, developBranchRegex, RegexOptions.IgnoreCase)
139139
|| Regex.IsMatch(b.FriendlyName, masterBranchRegex, RegexOptions.IgnoreCase));
@@ -223,29 +223,29 @@ private Branch[] CalculateWhenMultipleParents(IRepository repository, Commit cur
223223
private static BranchConfig ChooseMasterOrDevelopIncrementStrategyIfTheChosenBranchIsOneOfThem(Branch ChosenBranch, BranchConfig BranchConfiguration, Config config)
224224
{
225225
BranchConfig masterOrDevelopConfig = null;
226-
var developBranchRegex = config.Branches[ConfigurationProvider.DevelopBranchKey].Regex;
227-
var masterBranchRegex = config.Branches[ConfigurationProvider.MasterBranchKey].Regex;
226+
var developBranchRegex = config.Branches[ConfigurationConstants.DevelopBranchKey].Regex;
227+
var masterBranchRegex = config.Branches[ConfigurationConstants.MasterBranchKey].Regex;
228228
if (Regex.IsMatch(ChosenBranch.FriendlyName, developBranchRegex, RegexOptions.IgnoreCase))
229229
{
230230
// Normally we would not expect this to happen but for safety we add a check
231-
if (config.Branches[ConfigurationProvider.DevelopBranchKey].Increment !=
231+
if (config.Branches[ConfigurationConstants.DevelopBranchKey].Increment !=
232232
IncrementStrategy.Inherit)
233233
{
234234
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
235235
{
236-
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
236+
Increment = config.Branches[ConfigurationConstants.DevelopBranchKey].Increment
237237
};
238238
}
239239
}
240240
else if (Regex.IsMatch(ChosenBranch.FriendlyName, masterBranchRegex, RegexOptions.IgnoreCase))
241241
{
242242
// Normally we would not expect this to happen but for safety we add a check
243-
if (config.Branches[ConfigurationProvider.MasterBranchKey].Increment !=
243+
if (config.Branches[ConfigurationConstants.MasterBranchKey].Increment !=
244244
IncrementStrategy.Inherit)
245245
{
246246
masterOrDevelopConfig = new BranchConfig(BranchConfiguration)
247247
{
248-
Increment = config.Branches[ConfigurationProvider.DevelopBranchKey].Increment
248+
Increment = config.Branches[ConfigurationConstants.DevelopBranchKey].Increment
249249
};
250250
}
251251
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace GitVersion.Configuration
2+
{
3+
public class ConfigurationConstants
4+
{
5+
public const string DefaultTagPrefix = "[vV]";
6+
public const string ReleaseBranchRegex = "^releases?[/-]";
7+
public const string FeatureBranchRegex = "^features?[/-]";
8+
public const string PullRequestRegex = @"^(pull|pull\-requests|pr)[/-]";
9+
public const string HotfixBranchRegex = "^hotfix(es)?[/-]";
10+
public const string SupportBranchRegex = "^support[/-]";
11+
public const string DevelopBranchRegex = "^dev(elop)?(ment)?$";
12+
public const string MasterBranchRegex = "^master$";
13+
public const string MasterBranchKey = "master";
14+
public const string ReleaseBranchKey = "release";
15+
public const string FeatureBranchKey = "feature";
16+
public const string PullRequestBranchKey = "pull-request";
17+
public const string HotfixBranchKey = "hotfix";
18+
public const string SupportBranchKey = "support";
19+
public const string DevelopBranchKey = "develop";
20+
}
21+
}

0 commit comments

Comments
 (0)