Skip to content

Commit

Permalink
Merge pull request #4202 from arturcic/feature/regex
Browse files Browse the repository at this point in the history
Move regex patterns to a common file
  • Loading branch information
arturcic authored Sep 8, 2024
2 parents 1e376ce + e507abf commit 719899e
Show file tree
Hide file tree
Showing 40 changed files with 222 additions and 164 deletions.
1 change: 1 addition & 0 deletions new-cli/GitVersion.Common/GitVersion.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IEnvironment.cs" Link="Infrastructure\%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Core\Abstractions\IFileSystem.cs" Link="Infrastructure\%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Core\Exceptions\WarningException.cs" Link="Exceptions\%(Filename)%(Extension)"/>
<Compile Include="..\..\src\GitVersion.Core\Core\RegexPatterns.cs" Link="%(Filename)%(Extension)" />
<Compile Include="..\..\src\GitVersion.Core\Extensions\StringExtensions.cs" Link="Extensions\StringExtensions.cs" />
<Compile Include="..\..\src\GitVersion.Core\Extensions\CommonExtensions.cs" Link="Extensions\CommonExtensions.cs" />
<Compile Include="..\..\src\GitVersion.Core\Helpers\*.cs" Link="Helpers\%(Filename)%(Extension)" />
Expand Down
12 changes: 8 additions & 4 deletions src/GitVersion.App/ArgumentParserExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.RegularExpressions;
using GitVersion.Core;
using GitVersion.Helpers;

namespace GitVersion;
Expand Down Expand Up @@ -39,9 +39,13 @@ public static bool IsValidPath(this string? path)
}

public static bool IsSwitchArgument(this string? value)
=> value != null
&& (value.StartsWith('-') || value.StartsWith('/'))
&& !Regex.Match(value, @"/\w+:").Success; //Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names.
{
var patternRegex = RegexPatterns.Common.SwitchArgumentRegex;
return value != null
&& (value.StartsWith('-') || value.StartsWith('/'))
&& !patternRegex.Match(value).Success;
//Exclude msbuild & project parameters in form /blah:, which should be parsed as values, not switch names.
}

public static bool IsSwitch(this string? value, string switchName)
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Configuration/BranchConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public virtual IBranchConfiguration Inherit(IBranchConfiguration configuration)
Increment = Increment == IncrementStrategy.Inherit ? configuration.Increment : Increment,
DeploymentMode = DeploymentMode ?? configuration.DeploymentMode,
Label = Label ?? configuration.Label,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = PreventIncrement.OfMergedBranch ?? configuration.PreventIncrement.OfMergedBranch,
WhenBranchMerged = PreventIncrement.WhenBranchMerged ?? configuration.PreventIncrement.WhenBranchMerged,
Expand All @@ -117,7 +117,7 @@ public virtual IBranchConfiguration Inherit(EffectiveConfiguration configuration
Increment = Increment == IncrementStrategy.Inherit ? configuration.Increment : Increment,
DeploymentMode = DeploymentMode ?? configuration.DeploymentMode,
Label = Label ?? configuration.Label,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = PreventIncrement.OfMergedBranch ?? configuration.PreventIncrementOfMergedBranch,
WhenBranchMerged = PreventIncrement.WhenBranchMerged ?? configuration.PreventIncrementWhenBranchMerged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration
IsMainBranch = isMainBranch,
IsReleaseBranch = isReleaseBranch,
LabelNumberPattern = labelNumberPattern,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = preventIncrementOfMergedBranch,
WhenBranchMerged = preventIncrementWhenBranchMerged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public virtual IGitVersionConfiguration Build()
IsMainBranch = this.isMainBranch,
IsReleaseBranch = this.isReleaseBranch,
LabelNumberPattern = this.labelNumberPattern,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = this.preventIncrementOfMergedBranch,
WhenBranchMerged = this.preventIncrementWhenBranchMerged,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Core;
using GitVersion.VersionCalculation;

namespace GitVersion.Configuration;
Expand All @@ -13,10 +14,10 @@ private GitFlowConfigurationBuilder()
AssemblyFileVersioningScheme = ConfigurationConstants.DefaultAssemblyFileVersioningScheme,
AssemblyVersioningScheme = ConfigurationConstants.DefaultAssemblyVersioningScheme,
CommitDateFormat = ConfigurationConstants.DefaultCommitDateFormat,
MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern,
MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern,
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
MajorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMajorPattern,
MinorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMinorPattern,
NoBumpMessage = RegexPatterns.VersionCalculation.DefaultNoBumpPattern,
PatchVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultPatchPattern,
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
Expand All @@ -28,7 +29,7 @@ private GitFlowConfigurationBuilder()
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Inherit,
CommitMessageIncrementing = CommitMessageIncrementMode.Enabled,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = false,
WhenBranchMerged = false,
Expand All @@ -48,7 +49,7 @@ private GitFlowConfigurationBuilder()
RegularExpression = DevelopBranch.RegexPattern,
SourceBranches = [this.MainBranch.Name],
Label = "alpha",
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -66,7 +67,7 @@ private GitFlowConfigurationBuilder()
RegularExpression = MainBranch.RegexPattern,
SourceBranches = [],
Label = string.Empty,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true
},
Expand All @@ -89,7 +90,7 @@ private GitFlowConfigurationBuilder()
this.SupportBranch.Name,
],
Label = "beta",
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true,
WhenCurrentCommitTagged = false
Expand All @@ -115,7 +116,7 @@ private GitFlowConfigurationBuilder()
this.HotfixBranch.Name
],
Label = ConfigurationConstants.BranchNamePlaceholder,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -139,7 +140,7 @@ private GitFlowConfigurationBuilder()
this.HotfixBranch.Name
],
Label = "PullRequest",
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true,
WhenCurrentCommitTagged = false
Expand All @@ -154,7 +155,7 @@ private GitFlowConfigurationBuilder()
Increment = IncrementStrategy.Inherit,
RegularExpression = HotfixBranch.RegexPattern,
DeploymentMode = DeploymentMode.ManualDeployment,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -175,7 +176,7 @@ private GitFlowConfigurationBuilder()
RegularExpression = SupportBranch.RegexPattern,
SourceBranches = [this.MainBranch.Name],
Label = string.Empty,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true
},
Expand All @@ -202,7 +203,7 @@ private GitFlowConfigurationBuilder()
this.SupportBranch.Name
],
Label = ConfigurationConstants.BranchNamePlaceholder,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Core;
using GitVersion.VersionCalculation;

namespace GitVersion.Configuration;
Expand All @@ -13,10 +14,10 @@ private GitHubFlowConfigurationBuilder()
AssemblyFileVersioningScheme = ConfigurationConstants.DefaultAssemblyFileVersioningScheme,
AssemblyVersioningScheme = ConfigurationConstants.DefaultAssemblyVersioningScheme,
CommitDateFormat = ConfigurationConstants.DefaultCommitDateFormat,
MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern,
MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern,
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
MajorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMajorPattern,
MinorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMinorPattern,
NoBumpMessage = RegexPatterns.VersionCalculation.DefaultNoBumpPattern,
PatchVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultPatchPattern,
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
VersionStrategies = ConfigurationConstants.DefaultVersionStrategies,
TagPrefix = ConfigurationConstants.DefaultTagPrefix,
Expand All @@ -26,7 +27,7 @@ private GitHubFlowConfigurationBuilder()
DeploymentMode = DeploymentMode.ContinuousDelivery,
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Inherit,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = false,
WhenBranchMerged = false,
Expand All @@ -45,7 +46,7 @@ private GitHubFlowConfigurationBuilder()
{
Label = string.Empty,
Increment = IncrementStrategy.Patch,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true
},
Expand All @@ -64,7 +65,7 @@ private GitHubFlowConfigurationBuilder()
DeploymentMode = DeploymentMode.ManualDeployment,
Label = "beta",
Increment = IncrementStrategy.Patch,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true,
WhenBranchMerged = false,
Expand All @@ -88,7 +89,7 @@ private GitHubFlowConfigurationBuilder()
DeploymentMode = DeploymentMode.ManualDeployment,
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Inherit,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -108,7 +109,7 @@ private GitHubFlowConfigurationBuilder()
DeploymentMode = DeploymentMode.ContinuousDelivery,
Label = "PullRequest",
Increment = IncrementStrategy.Inherit,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true,
WhenCurrentCommitTagged = false
Expand All @@ -130,7 +131,7 @@ private GitHubFlowConfigurationBuilder()
DeploymentMode = DeploymentMode.ManualDeployment,
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Inherit,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Core;
using GitVersion.VersionCalculation;

namespace GitVersion.Configuration;
Expand All @@ -8,15 +9,15 @@ internal sealed class TrunkBasedConfigurationBuilder : ConfigurationBuilderBase<

private TrunkBasedConfigurationBuilder()
{
WithConfiguration(new GitVersionConfiguration()
WithConfiguration(new GitVersionConfiguration
{
AssemblyFileVersioningScheme = ConfigurationConstants.DefaultAssemblyFileVersioningScheme,
AssemblyVersioningScheme = ConfigurationConstants.DefaultAssemblyVersioningScheme,
CommitDateFormat = ConfigurationConstants.DefaultCommitDateFormat,
MajorVersionBumpMessage = IncrementStrategyFinder.DefaultMajorPattern,
MinorVersionBumpMessage = IncrementStrategyFinder.DefaultMinorPattern,
NoBumpMessage = IncrementStrategyFinder.DefaultNoBumpPattern,
PatchVersionBumpMessage = IncrementStrategyFinder.DefaultPatchPattern,
MajorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMajorPattern,
MinorVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultMinorPattern,
NoBumpMessage = RegexPatterns.VersionCalculation.DefaultNoBumpPattern,
PatchVersionBumpMessage = RegexPatterns.VersionCalculation.DefaultPatchPattern,
SemanticVersionFormat = ConfigurationConstants.DefaultSemanticVersionFormat,
VersionStrategies = [
VersionStrategies.ConfiguredNextVersion,
Expand All @@ -31,7 +32,7 @@ private TrunkBasedConfigurationBuilder()
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Inherit,
CommitMessageIncrementing = CommitMessageIncrementMode.Enabled,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = false,
WhenBranchMerged = false,
Expand All @@ -44,12 +45,12 @@ private TrunkBasedConfigurationBuilder()
IsMainBranch = false
});

WithBranch(MainBranch.Name).WithConfiguration(new BranchConfiguration()
WithBranch(MainBranch.Name).WithConfiguration(new BranchConfiguration
{
DeploymentMode = DeploymentMode.ContinuousDeployment,
Label = string.Empty,
Increment = IncrementStrategy.Patch,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true
},
Expand All @@ -63,12 +64,12 @@ private TrunkBasedConfigurationBuilder()
PreReleaseWeight = 55000
});

WithBranch(FeatureBranch.Name).WithConfiguration(new BranchConfiguration()
WithBranch(FeatureBranch.Name).WithConfiguration(new BranchConfiguration
{
DeploymentMode = DeploymentMode.ContinuousDelivery,
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Minor,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -82,12 +83,12 @@ private TrunkBasedConfigurationBuilder()
PreReleaseWeight = 30000
});

WithBranch(HotfixBranch.Name).WithConfiguration(new BranchConfiguration()
WithBranch(HotfixBranch.Name).WithConfiguration(new BranchConfiguration
{
DeploymentMode = DeploymentMode.ContinuousDelivery,
Label = ConfigurationConstants.BranchNamePlaceholder,
Increment = IncrementStrategy.Patch,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand All @@ -106,7 +107,7 @@ private TrunkBasedConfigurationBuilder()
DeploymentMode = DeploymentMode.ContinuousDelivery,
Label = "PullRequest",
Increment = IncrementStrategy.Inherit,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
OfMergedBranch = true,
WhenCurrentCommitTagged = false
Expand All @@ -126,7 +127,7 @@ private TrunkBasedConfigurationBuilder()
WithBranch(UnknownBranch.Name).WithConfiguration(new BranchConfiguration
{
Increment = IncrementStrategy.Patch,
PreventIncrement = new PreventIncrementConfiguration()
PreventIncrement = new PreventIncrementConfiguration
{
WhenCurrentCommitTagged = false
},
Expand Down
Loading

0 comments on commit 719899e

Please sign in to comment.