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

16 changes: 8 additions & 8 deletions schemas/6.0/GitVersion.configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"$ref": "#/$defs/string1"
},
"label-prefix": {
"description": "A regex which is used to trim Git tags before processing. Defaults to [vV]?",
"description": "A regular expression which is used to trim Git tags before processing. Defaults to [vV]?",
"type": "string"
},
"label-pre-release-weight": {
Expand All @@ -97,7 +97,7 @@
"major-version-bump-message": {
"format": "regex",
"pattern": "\u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
"description": "The regex to match commit messages with to perform a major version increment. Default set to \u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
"description": "The regular expression to match commit messages with to perform a major version increment. Default set to \u0027\\\u002Bsemver:\\s?(breaking|major)\u0027",
"type": "string"
},
"merge-message-formats": {
Expand All @@ -110,7 +110,7 @@
"minor-version-bump-message": {
"format": "regex",
"pattern": "\u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
"description": "The regex to match commit messages with to perform a minor version increment. Default set to \u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
"description": "The regular expression to match commit messages with to perform a minor version increment. Default set to \u0027\\\u002Bsemver:\\s?(feature|minor)\u0027",
"type": "string"
},
"next-version": {
Expand All @@ -126,7 +126,7 @@
"patch-version-bump-message": {
"format": "regex",
"pattern": "\u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
"description": "The regex to match commit messages with to perform a patch version increment. Default set to \u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
"description": "The regular expression to match commit messages with to perform a patch version increment. Default set to \u0027\\\u002Bsemver:\\s?(fix|patch)\u0027",
"type": "string"
},
"pre-release-weight": {
Expand Down Expand Up @@ -246,7 +246,7 @@
]
},
"Nullable\u006012": {
"description": "Indicates this branch config represents a release branch in GitFlow.",
"description": "Indicates this branch configuration represents a release branch in GitFlow.",
"type": [
"boolean",
"null"
Expand All @@ -267,7 +267,7 @@
"string1": {
"format": "regex",
"pattern": "[/-](?\u003Cnumber\u003E\\d\u002B)[-/]",
"description": "The regex pattern to use to extract the number from the branch name. Defaults to \u0027[/-](?\u003Cnumber\u003E\\d\u002B)[-/]\u0027.",
"description": "The regular expression pattern to use to extract the number from the branch name. Defaults to \u0027[/-](?\u003Cnumber\u003E\\d\u002B)[-/]\u0027.",
"type": "string"
},
"Nullable\u006013": {
Expand All @@ -285,7 +285,7 @@
]
},
"string2": {
"description": "The regex pattern to use to match this branch.",
"description": "The regular expression pattern to use to match this branch.",
"type": "string"
},
"array1": {
Expand All @@ -311,7 +311,7 @@
]
},
"Nullable\u006017": {
"description": "Indicates this branch config represents develop in GitFlow.",
"description": "Indicates this branch configuration represents develop in GitFlow.",
"type": [
"boolean",
"null"
Expand Down
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 Expand Up @@ -139,7 +124,7 @@ public void CanProvideConfigForNewBranch()
SetupConfigFileContent(text);
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);

configuration.Branches["bug"].Regex.ShouldBe("bug[/-]");
configuration.Branches["bug"].RegularExpression.ShouldBe("bug[/-]");
configuration.Branches["bug"].Label.ShouldBe("bugfix");
}

Expand Down Expand Up @@ -179,7 +164,7 @@ public void CanWriteOutEffectiveConfiguration()
{
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);

configuration.ToString().ShouldMatchApproved();
configuration.ToString()!.ShouldMatchApproved();
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void WhenBadDateFormatShouldFail()
[Test]
public void NewInstanceShouldBeEmpty()
{
var ignoreConfig = new IgnoreConfiguration();
IIgnoreConfiguration ignoreConfig = new IgnoreConfiguration();

ignoreConfig.IsEmpty.ShouldBeTrue();
}
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: []
18 changes: 11 additions & 7 deletions src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static class GitToolsTestingExtensions
public static ICommit CreateMockCommit()
{
var objectId = Substitute.For<IObjectId>();
objectId.Sha.Returns(Guid.NewGuid().ToString("n") + "00000000");

var sha = Guid.NewGuid().ToString("n") + "00000000";
objectId.Sha.Returns(sha);
var commit = Substitute.For<ICommit>();
commit.Id.Returns(objectId);
commit.Sha.Returns(objectId.Sha);
commit.Sha.Returns(sha);
commit.Message.Returns("Commit " + commitCount++);
commit.Parents.Returns(Enumerable.Empty<ICommit>());
commit.When.Returns(when.AddSeconds(1));
Expand All @@ -49,11 +49,14 @@ public static IBranch FindBranch(this IGitRepository repository, string branchNa
=> repository.Branches.FirstOrDefault(branch => branch.Name.WithoutOrigin == branchName)
?? throw new GitVersionException($"Branch {branchName} not found");

public static void DumpGraph(this IGitRepository repository, Action<string>? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.Path, writer, maxCommits);
public static void DumpGraph(this IGitRepository repository, Action<string>? writer = null, int? maxCommits = null)
=> GitExtensions.DumpGraph(repository.Path, writer, maxCommits);

public static void DumpGraph(this IRepository repository, Action<string>? writer = null, int? maxCommits = null) => GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits);
public static void DumpGraph(this IRepository repository, Action<string>? writer = null, int? maxCommits = null)
=> GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits);

public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, IGitVersionConfiguration? configuration = null,
IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
{
repository ??= fixture.Repository;
configuration ??= GitFlowConfigurationBuilder.New.Build();
Expand Down Expand Up @@ -106,7 +109,8 @@ public static void WriteVersionVariables(this RepositoryFixtureBase fixture, str
writer.Write(versionInfo.ToString());
}

public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, GitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver,
IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null)
{
repository ??= fixture.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public void WhenPreventIncrementOfMergedBranchVersionIsSetToFalseForDevelopCommi
)
.WithBranch("hotfix", builder => builder
.WithPreventIncrementOfMergedBranchVersion(true)
.WithRegex("^(origin/)?hotfix[/-]")
.WithRegularExpression("^(origin/)?hotfix[/-]")
)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void BranchCreatedAfterFastForwardMergeShouldInheritCorrectly()
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("unstable", builder => builder
.WithIncrement(IncrementStrategy.Minor)
.WithRegex("unstable")
.WithRegularExpression("unstable")
.WithSourceBranches()
.WithIsSourceBranchFor("feature"))
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void LabelIsBranchNameForBranchesWithoutPrefixedBranchName(string label,
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("other", builder => builder
.WithIncrement(IncrementStrategy.Patch)
.WithRegex(".*")
.WithRegularExpression(".*")
.WithSourceBranches()
.WithLabel(label))
.Build();
Expand Down
Loading