Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ public void EnsureGetBranchSpecificLabelThrowsWhenEnvVarMissing()
Should.Throw<ArgumentException>(() =>
effectiveConfiguration.GetBranchSpecificLabel(ReferenceName.FromBranchName(BranchName), null, environment));
}

[TestCase("case-00/my-branch", "case-00-my-branch")]
[TestCase("my-branch", "my-branch")]
[TestCase("my_branch/valid", "my-branch-valid")]
public void EnsureGetBranchSpecificLabelReturnsValidLabelForEnvironmentVariables(string variable, string expectedLabel)
{
var environment = new TestEnvironment();
environment.SetEnvironmentVariable("GITHUB_HEAD_REF", variable);

var configuration = GitFlowConfigurationBuilder.New
.WithoutBranches()
.WithBranch("feature/test-feature", builder => builder
.WithLabel("{env:GITHUB_HEAD_REF}")
.WithRegularExpression(@"^features?[\/-](?<BranchName>.+)"))
.Build();

var effectiveConfiguration = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName("feature/test-feature"));
var actual = effectiveConfiguration.GetBranchSpecificLabel(ReferenceName.FromBranchName("feature/test-feature"), null, environment);
actual.ShouldBe(expectedLabel);
}
}
3 changes: 3 additions & 0 deletions src/GitVersion.Core/Core/RegexPatterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ internal static partial class RegexPatterns
[StringSyntax(StringSyntaxAttribute.Regex, Options)]
internal const string SanitizeNameRegexPattern = "[^a-zA-Z0-9-]";

[StringSyntax(StringSyntaxAttribute.Regex, Options)]
internal const string SanitizeLabelRegexPattern = "[^a-zA-Z0-9-.]";

#if NET9_0_OR_GREATER
[GeneratedRegex(SwitchArgumentRegexPattern, Options)]
public static partial Regex SwitchArgumentRegex { get; }
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersion.Core/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private static bool ShouldBeIgnored(ICommit commit, IIgnoreConfiguration ignore)
var effectiveBranchName = branchNameOverride ?? branchName;
var labelPlaceholders = BuildLabelPlaceholders(configuration.RegularExpression, effectiveBranchName);

return label.FormatWith(labelPlaceholders, environment);
return label.FormatWith(labelPlaceholders, environment)
.RegexReplace(RegexPatterns.SanitizeLabelRegexPattern, "-");
}

public TaggedSemanticVersions GetTaggedSemanticVersion()
Expand Down
Loading