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 @@ -127,21 +127,39 @@ public void EnsureGetBranchSpecificLabelWorksWithoutEnvironmentWhenNoEnvPlacehol
}

[Test]
public void EnsureGetBranchSpecificLabelThrowsWhenEnvVarMissing()
public void EnsureGetBranchSpecificLabelReturnsLabelTemplateWhenEnvVarMissing()
{
var environment = new TestEnvironment();
// Do not set MISSING_VAR
var expectedLabel = "pr-{env:MISSING_VAR}";

var configuration = GitFlowConfigurationBuilder.New
.WithoutBranches()
.WithBranch(BranchName, builder => builder
.WithLabel("pr-{env:MISSING_VAR}")
.WithLabel(expectedLabel)
.WithRegularExpression(@"^pull[/-]"))
.Build();

var effectiveConfiguration = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName(BranchName));
Should.Throw<ArgumentException>(() =>
effectiveConfiguration.GetBranchSpecificLabel(ReferenceName.FromBranchName(BranchName), null, environment));
var actual = effectiveConfiguration.GetBranchSpecificLabel(ReferenceName.FromBranchName(BranchName), null, environment);
actual.ShouldBe(expectedLabel);
}

[Test]
public void EnsureGetBranchSpecificLabelReturnsLabelTemplateWhenPropertyMissing()
{
var expectedLabel = "{BranchName}";

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

var effectiveConfiguration = configuration.GetEffectiveConfiguration(ReferenceName.FromBranchName(BranchName));
var actual = effectiveConfiguration.GetBranchSpecificLabel(ReferenceName.FromBranchName(BranchName), null, new TestEnvironment());
actual.ShouldBe(expectedLabel);
}

[TestCase("case-00/my-branch", "case-00-my-branch")]
Expand Down
11 changes: 9 additions & 2 deletions src/GitVersion.Core/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,15 @@ private static bool ShouldBeIgnored(ICommit commit, IIgnoreConfiguration ignore)
var effectiveBranchName = branchNameOverride ?? branchName;
var labelPlaceholders = BuildLabelPlaceholders(configuration.RegularExpression, effectiveBranchName);

return label.FormatWith(labelPlaceholders, environment)
.RegexReplace(RegexPatterns.SanitizeLabelRegexPattern, "-");
try
{
return label.FormatWith(labelPlaceholders, environment)
.RegexReplace(RegexPatterns.SanitizeLabelRegexPattern, "-");
}
catch (Exception e) when (e is ArgumentException or FormatException)
{
return label;
}
}

public TaggedSemanticVersions GetTaggedSemanticVersion()
Expand Down
Loading