Skip to content

Change GitVersionConfiguration and BranchConfiguration to record type and extract interfaces #3433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -13,9 +13,9 @@ public void GetReleaseBranchConfigReturnsAllReleaseBranches()
{
Branches = new Dictionary<string, BranchConfiguration>
{
{ "foo", new BranchConfiguration { Name = "foo" } },
{ "bar", new BranchConfiguration { Name = "bar", IsReleaseBranch = true } },
{ "baz", new BranchConfiguration { Name = "baz", IsReleaseBranch = true } }
{ "foo", new BranchConfiguration() },
{ "bar", new BranchConfiguration { IsReleaseBranch = true } },
{ "baz", new BranchConfiguration { IsReleaseBranch = true } }
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ branches:
track-merge-target: true
regex: ^dev(elop)?(ment)?$
source-branches: []
is-source-branch-for: []
tracks-release-branches: true
is-release-branch: false
is-mainline: false
Expand All @@ -32,6 +33,7 @@ branches:
source-branches:
- develop
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: true
Expand All @@ -47,6 +49,7 @@ branches:
- main
- support
- release
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: true
is-mainline: false
Expand All @@ -63,6 +66,7 @@ branches:
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
pull-request:
mode: ContinuousDelivery
Expand All @@ -77,6 +81,7 @@ branches:
- feature
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
hotfix:
mode: ContinuousDelivery
Expand All @@ -88,6 +93,7 @@ branches:
- main
- support
- hotfix
is-source-branch-for: []
pre-release-weight: 30000
support:
label: ''
Expand All @@ -97,6 +103,7 @@ branches:
regex: ^support[/-]
source-branches:
- main
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: true
Expand All @@ -114,6 +121,7 @@ branches:
- pull-request
- hotfix
- support
is-source-branch-for: []
ignore:
sha: []
mode: ContinuousDelivery
Expand All @@ -124,6 +132,8 @@ track-merge-target: false
track-merge-message: true
commit-message-incrementing: Enabled
regex: ''
source-branches: []
is-source-branch-for: []
tracks-release-branches: false
is-release-branch: false
is-mainline: false
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ public void RegexIsRequired()
"See https://gitversion.net/docs/reference/configuration for more info");
}

[Test]
public void SourceBranchIsRequired()
{
const string text = @"
next-version: 2.0.0
branches:
bug:
regex: 'bug[/-]'
label: bugfix";
SetupConfigFileContent(text);
var ex = Should.Throw<ConfigurationException>(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'source-branches'{System.Environment.NewLine}" +
"See https://gitversion.net/docs/reference/configuration for more info");
}

[Test(Description = "This test proves the configuration validation will fail early with a helpful message when a branch listed in source-branches has no configuration.")]
public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsMissing()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ branches: {}
ignore:
sha: []
increment: None
source-branches: []
is-source-branch-for: []
44 changes: 22 additions & 22 deletions src/GitVersion.Core.Tests/MergeMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace GitVersion.Core.Tests;
[TestFixture]
public class MergeMessageTests : TestBase
{
private readonly GitVersionConfiguration configuration = new() { LabelPrefix = ConfigurationConstants.DefaultLabelPrefix };
private readonly GitFlowConfigurationBuilder configurationBuilder = GitFlowConfigurationBuilder.New;

[Test]
public void NullMessageStringThrows() =>
// Act / Assert
Should.Throw<ArgumentNullException>(() => new MergeMessage(null!, this.configuration));
Should.Throw<ArgumentNullException>(() => new MergeMessage(null!, this.configurationBuilder.Build()));

[TestCase("")]
[TestCase("\t\t ")]
public void EmptyMessageString(string message)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.TargetBranch.ShouldBeNull();
Expand Down Expand Up @@ -67,7 +67,7 @@ public void ParsesMergeMessage(
SemanticVersion expectedVersion)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("Default");
Expand Down Expand Up @@ -97,7 +97,7 @@ public void ParsesGitHubPullMergeMessage(
int? expectedPullRequestNumber)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("GitHubPull");
Expand Down Expand Up @@ -132,7 +132,7 @@ public void ParsesBitBucketPullMergeMessage(
int? expectedPullRequestNumber)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("BitBucketPull");
Expand Down Expand Up @@ -162,7 +162,7 @@ public void ParsesBitBucketPullMergeMessage_v7(
int? expectedPullRequestNumber)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("BitBucketPullv7");
Expand Down Expand Up @@ -193,7 +193,7 @@ public void ParsesSmartGitMergeMessage(
SemanticVersion expectedVersion)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("SmartGit");
Expand Down Expand Up @@ -224,7 +224,7 @@ public void ParsesRemoteTrackingMergeMessage(
SemanticVersion expectedVersion)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe("RemoteTracking");
Expand All @@ -247,7 +247,7 @@ public void ParsesRemoteTrackingMergeMessage(
public void ParsesInvalidMergeMessage(string message)
{
// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBeNull();
Expand All @@ -264,13 +264,13 @@ public void MatchesSingleCustomMessage()
// Arrange
const string message = "My custom message";
const string definition = "MyCustom";
this.configuration.MergeMessageFormats = new Dictionary<string, string>
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
{
[definition] = message
};
});

// Act
var sut = new MergeMessage(message, this.configuration);
var sut = new MergeMessage(message, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe(definition);
Expand All @@ -288,15 +288,15 @@ public void MatchesMultipleCustomMessages()
// Arrange
const string format = "My custom message";
const string definition = "MyCustom";
this.configuration.MergeMessageFormats = new Dictionary<string, string>
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
{
["Default2"] = "some example",
["Default3"] = "another example",
[definition] = format
};
});

// Act
var sut = new MergeMessage(format, this.configuration);
var sut = new MergeMessage(format, this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe(definition);
Expand All @@ -314,16 +314,16 @@ public void MatchesCaptureGroupsFromCustomMessages()
// Arrange
const string format = @"^Merged PR #(?<PullRequestNumber>\d+) into (?<TargetBranch>[^\s]*) from (?:(?<SourceBranch>[^\s]*))";
const string definition = "MyCustom";
this.configuration.MergeMessageFormats = new Dictionary<string, string>
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
{
[definition] = format
};
});
const int pr = 1234;
const string target = MainBranch;
const string source = "feature/2.0.0/example";

// Act
var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", this.configuration);
var sut = new MergeMessage($"Merged PR #{pr} into {target} from {source}", this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe(definition);
Expand All @@ -341,15 +341,15 @@ public void ReturnsAfterFirstMatchingPattern()
// Arrange
const string format = @"^Merge (branch|tag) '(?<SourceBranch>[^']*)'(?: into (?<TargetBranch>[^\s]*))*";
const string definition = "MyCustom";
this.configuration.MergeMessageFormats = new Dictionary<string, string>
this.configurationBuilder.WithMergeMessageFormats(new Dictionary<string, string>
{
[definition] = format,
["Default2"] = format,
["Default3"] = format
};
});

// Act
var sut = new MergeMessage("Merge branch 'this'", this.configuration);
var sut = new MergeMessage("Merge branch 'this'", this.configurationBuilder.Build());

// Assert
sut.FormatName.ShouldBe(definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ public void MergeFeatureIntoMainline()
public void MergeFeatureIntoMainlineWithMinorIncrement()
{
var configuration = GitFlowConfigurationBuilder.New
.WithIgnoreConfiguration(new())
.WithMergeMessageFormats(new())
.WithBranch("main", builder => builder.WithVersioningMode(VersioningMode.Mainline))
.WithBranch("feature", builder => builder
.WithVersioningMode(VersioningMode.Mainline)
Expand All @@ -176,8 +174,6 @@ public void MergeFeatureIntoMainlineWithMinorIncrement()
public void MergeFeatureIntoMainlineWithMinorIncrementAndThenMergeHotfix()
{
var configuration = GitFlowConfigurationBuilder.New
.WithIgnoreConfiguration(new())
.WithMergeMessageFormats(new())
.WithVersioningMode(VersioningMode.Mainline)
.WithBranch("feature", builder => builder
.WithIncrement(IncrementStrategy.Minor)
Expand Down Expand Up @@ -477,7 +473,7 @@ public void ShouldIgnorePreReleaseVersionInMainlineMode()
nextVersion.BaseVersion.SemanticVersion.ShouldBe(lowerVersion.SemanticVersion);
}

private class TestIgnoreConfig : IgnoreConfiguration
private record TestIgnoreConfig : IgnoreConfiguration
{
private readonly IVersionFilter filter;

Expand Down
Loading