Skip to content

Commit 4c039e7

Browse files
committed
use ConfigurationConstants instead of hardcoded strings
1 parent f70f968 commit 4c039e7

20 files changed

+120
-106
lines changed

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ env:
3535

3636
jobs:
3737
format:
38-
runs-on: windows-latest
38+
runs-on: ubuntu-latest
3939
name: DotNet Format
4040
steps:
4141
- uses: actions/checkout@v3

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsM
111111
}
112112

113113
[Test(Description = "Well-known branches may not be present in the configuration file. This test confirms the validation check succeeds when the source-branches configuration contain these well-known branches.")]
114-
[TestCase(GitVersionConfiguration.MainBranchKey)]
115-
[TestCase(GitVersionConfiguration.DevelopBranchKey)]
114+
[TestCase(ConfigurationConstants.MainBranchKey)]
115+
[TestCase(ConfigurationConstants.DevelopBranchKey)]
116116
public void SourceBranchesValidationShouldSucceedForWellKnownBranches(string wellKnownBranchKey)
117117
{
118118
var text = $@"
@@ -245,7 +245,7 @@ public void CanReadDefaultDocument()
245245
configuration.AssemblyInformationalFormat.ShouldBe(null);
246246
configuration.Branches["develop"].Label.ShouldBe("alpha");
247247
configuration.Branches["release"].Label.ShouldBe("beta");
248-
configuration.LabelPrefix.ShouldBe(GitVersionConfiguration.DefaultLabelPrefix);
248+
configuration.LabelPrefix.ShouldBe(ConfigurationConstants.DefaultLabelPrefix);
249249
configuration.NextVersion.ShouldBe(null);
250250
}
251251

@@ -404,7 +404,7 @@ public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile()
404404
SetupConfigFileContent(text);
405405
var configuration = this.configurationProvider.ProvideInternal(this.repoPath);
406406

407-
configuration.LabelPrefix.ShouldBe(GitVersionConfiguration.DefaultLabelPrefix);
407+
configuration.LabelPrefix.ShouldBe(ConfigurationConstants.DefaultLabelPrefix);
408408
}
409409

410410
[Test]
@@ -443,7 +443,7 @@ public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig()
443443

444444
var configuration = this.configurationProvider.ProvideInternal(this.repoPath, overrideConfiguration);
445445

446-
configuration.LabelPrefix.ShouldBe(GitVersionConfiguration.DefaultLabelPrefix);
446+
configuration.LabelPrefix.ShouldBe(ConfigurationConstants.DefaultLabelPrefix);
447447
}
448448

449449
[Test]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public TestEffectiveConfiguration(
1313
string? assemblyFileVersioningFormat = null,
1414
string? assemblyInformationalFormat = null,
1515
VersioningMode versioningMode = VersioningMode.ContinuousDelivery,
16-
string labelPrefix = GitVersionConfiguration.DefaultLabelPrefix,
16+
string labelPrefix = ConfigurationConstants.DefaultLabelPrefix,
1717
string label = "ci",
1818
string? nextVersion = null,
1919
string branchPrefixToTrim = "",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void CanUseBranchNameOffAReleaseBranch()
169169
{
170170
var configuration = GitFlowConfigurationBuilder.New
171171
.WithBranch("release", builder => builder.WithLabel("build"))
172-
.WithBranch("feature", builder => builder.WithLabel("{BranchName}"))
172+
.WithBranch("feature", builder => builder.WithLabel(ConfigurationConstants.BranchNamePlaceholder))
173173
.Build();
174174

175175
using var fixture = new EmptyRepositoryFixture();
@@ -185,7 +185,7 @@ public void CanUseBranchNameOffAReleaseBranch()
185185

186186
[TestCase("alpha", "JIRA-123", "alpha")]
187187
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
188-
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
188+
[TestCase($"alpha.{ConfigurationConstants.BranchNamePlaceholder}", "JIRA-123", "alpha.JIRA-123")]
189189
public void ShouldUseConfiguredTag(string tag, string featureName, string preReleaseTagName)
190190
{
191191
var configuration = GitFlowConfigurationBuilder.New
@@ -454,7 +454,7 @@ public void ShouldHaveAGreaterSemVerAfterDevelopIsMergedIntoFeature()
454454
.WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.ContinuousDeployment))
455455
.WithBranch("develop", builder => builder.WithPreventIncrementOfMergedBranchVersion(true))
456456
.WithBranch("feature", builder => builder
457-
.WithLabel("feat-{BranchName}")
457+
.WithLabel($"feat-{ConfigurationConstants.BranchNamePlaceholder}")
458458
.WithVersioningMode(VersioningMode.ContinuousDeployment)
459459
)
460460
.WithCommitMessageIncrementing(CommitMessageIncrementMode.Disabled)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void CanSpecifyTagPrefixes()
201201
[Test]
202202
public void CanSpecifyTagPrefixesAsRegex()
203203
{
204-
var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix($"version-|{GitVersionConfiguration.DefaultLabelPrefix}").Build();
204+
var configuration = GitFlowConfigurationBuilder.New.WithLabelPrefix($"version-|{ConfigurationConstants.DefaultLabelPrefix}").Build();
205205
using var fixture = new EmptyRepositoryFixture();
206206
var taggedVersion = "v1.0.3";
207207
fixture.Repository.MakeATaggedCommit(taggedVersion);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void ShouldNotGetVersionFromFeatureBranchIfNotMerged()
5454

5555
[TestCase("alpha", "JIRA-123", "alpha")]
5656
[TestCase("useBranchName", "JIRA-123", "JIRA-123")]
57-
[TestCase("alpha.{BranchName}", "JIRA-123", "alpha.JIRA-123")]
57+
[TestCase($"alpha.{ConfigurationConstants.BranchNamePlaceholder}", "JIRA-123", "alpha.JIRA-123")]
5858
public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label, string branchName, string preReleaseTagName)
5959
{
6060
var configuration = GitFlowConfigurationBuilder.New

src/GitVersion.Core.Tests/MergeMessageTests.cs

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

1111
[Test]
1212
public void NullMessageStringThrows() =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void PreReleaseLabelCanUseBranchName()
7171
.WithNextVersion("1.0.0")
7272
.WithBranch("custom", builder => builder
7373
.WithRegex("custom/")
74-
.WithLabel("{BranchName}")
74+
.WithLabel(ConfigurationConstants.BranchNamePlaceholder)
7575
.WithSourceBranches()
7676
)
7777
.Build();
@@ -217,7 +217,7 @@ public void PreReleaseLabelCanUseBranchNameVariable()
217217
.WithNextVersion("1.0.0")
218218
.WithBranch("custom", builder => builder
219219
.WithRegex("custom/")
220-
.WithLabel("alpha.{BranchName}")
220+
.WithLabel($"alpha.{ConfigurationConstants.BranchNamePlaceholder}")
221221
.WithSourceBranches()
222222
)
223223
.Build();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class SemanticVersionTests : TestBase
2323
[TestCase("1.2.3+4.Branch.Foo", 1, 2, 3, null, null, 4, "Foo", null, null, null, null, SemanticVersionFormat.Strict)]
2424
[TestCase("1.2.3+randomMetaData", 1, 2, 3, null, null, null, null, null, "randomMetaData", null, null, SemanticVersionFormat.Strict)]
2525
[TestCase("1.2.3-beta.1+4.Sha.12234.Othershiz", 1, 2, 3, "beta", 1, 4, null, "12234", "Othershiz", null, null, SemanticVersionFormat.Strict)]
26-
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, GitVersionConfiguration.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
27-
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", GitVersionConfiguration.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
28-
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", GitVersionConfiguration.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
26+
[TestCase("1.2.3", 1, 2, 3, null, null, null, null, null, null, null, ConfigurationConstants.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
27+
[TestCase("v1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationConstants.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
28+
[TestCase("V1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", ConfigurationConstants.DefaultLabelPrefix, SemanticVersionFormat.Strict)]
2929
[TestCase("version-1.2.3", 1, 2, 3, null, null, null, null, null, null, "1.2.3", "version-", SemanticVersionFormat.Strict)]
3030
[TestCase("1.0.0-develop-20201007113711", 1, 0, 0, "develop-20201007113711", null, null, null, null, null, "1.0.0-develop-20201007113711", null, SemanticVersionFormat.Strict)]
3131
[TestCase("20201007113711.658165168461351.64136516984163213-develop-20201007113711.98848747823+65416321321", 20201007113711, 658165168461351, 64136516984163213, "develop-20201007113711", 98848747823, 65416321321, null, null, null, "20201007113711.658165168461351.64136516984163213-develop-20201007113711.98848747823+65416321321", null, SemanticVersionFormat.Strict)]
@@ -61,7 +61,7 @@ public void ValidateVersionParsing(
6161

6262
[TestCase("someText")]
6363
[TestCase("some-T-ext")]
64-
[TestCase("v.1.2.3", GitVersionConfiguration.DefaultLabelPrefix)]
64+
[TestCase("v.1.2.3", ConfigurationConstants.DefaultLabelPrefix)]
6565
public void ValidateInvalidVersionParsing(string versionString, string? tagPrefixRegex = null) =>
6666
Assert.IsFalse(SemanticVersion.TryParse(versionString, tagPrefixRegex, out _), "TryParse Result");
6767

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace GitVersion.Configuration;
2+
3+
public class ConfigurationConstants
4+
{
5+
public const string DefaultLabelPrefix = "[vV]?";
6+
public const string BranchNamePlaceholder = "{BranchName}";
7+
8+
public const string MainBranchKey = "main";
9+
public const string MasterBranchKey = "master";
10+
public const string DevelopBranchKey = "develop";
11+
public const string ReleaseBranchKey = "release";
12+
public const string FeatureBranchKey = "feature";
13+
public const string PullRequestBranchKey = "pull-request";
14+
public const string HotfixBranchKey = "hotfix";
15+
public const string SupportBranchKey = "support";
16+
public const string UnknownBranchKey = "unknown";
17+
18+
public const string MainBranchRegex = "^master$|^main$";
19+
public const string DevelopBranchRegex = "^dev(elop)?(ment)?$";
20+
public const string ReleaseBranchRegex = "^releases?[/-]";
21+
public const string FeatureBranchRegex = "^features?[/-]";
22+
public const string PullRequestBranchRegex = @"^(pull|pull\-requests|pr)[/-]";
23+
public const string HotfixBranchRegex = "^hotfix(es)?[/-]";
24+
public const string SupportBranchRegex = "^support[/-]";
25+
public const string UnknownBranchRegex = ".*";
26+
}

0 commit comments

Comments
 (0)