Skip to content
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

Use IGitVersionConfiguration instead of GitVersionConfiguration (where possible) #3454

Merged
merged 2 commits into from
Mar 29, 2023
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
4 changes: 2 additions & 2 deletions src/GitVersion.App.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData
}

[TestCaseSource(nameof(OverrideConfigWithSingleOptionTestData))]
public void OverrideConfigWithSingleOptions(string options, GitVersionConfiguration expected)
public void OverrideConfigWithSingleOptions(string options, IGitVersionConfiguration expected)
{
var arguments = this.argumentParser.ParseArguments($"/overrideconfig {options}");

Expand Down Expand Up @@ -534,7 +534,7 @@ private static IEnumerable<TestCaseData> OverrideConfigWithSingleOptionTestData(
}

[TestCaseSource(nameof(OverrideConfigWithMultipleOptionsTestData))]
public void OverrideConfigWithMultipleOptions(string options, GitVersionConfiguration expected)
public void OverrideConfigWithMultipleOptions(string options, IGitVersionConfiguration expected)
{
var arguments = this.argumentParser.ParseArguments(options);
ConfigurationHelper configurationHelper = new(arguments.OverrideConfiguration);
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.BuildAgents/GitVersionBuildAgentsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace GitVersion.Agents;

public class GitVersionBuildAgentsModule : GitVersionModule
public class GitVersionBuildAgentsModule : IGitVersionModule
{
public override void RegisterTypes(IServiceCollection services)
public void RegisterTypes(IServiceCollection services)
{
var buildAgents = FindAllDerivedTypes<BuildAgentBase>(Assembly.GetAssembly(GetType()));
var buildAgents = IGitVersionModule.FindAllDerivedTypes<BuildAgentBase>(Assembly.GetAssembly(GetType()));

foreach (var buildAgent in buildAgents)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.BuildAgents/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
GitVersion.Agents.GitVersionBuildAgentsModule
GitVersion.Agents.GitVersionBuildAgentsModule.GitVersionBuildAgentsModule() -> void
override GitVersion.Agents.GitVersionBuildAgentsModule.RegisterTypes(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void
GitVersion.Agents.GitVersionBuildAgentsModule.RegisterTypes(Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ConfigurationExtensionsTests : TestBase
[Test]
public void GetReleaseBranchConfigReturnsAllReleaseBranches()
{
var configuration = new GitVersionConfiguration()
var configuration = new GitVersionConfiguration
{
Branches = new Dictionary<string, BranchConfiguration>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ShouldFallbackToBaseVersionWhenAllCommitsAreIgnored(string? nextVers
fixture.MakeACommit();

var configuration = GitFlowConfigurationBuilder.New.WithNextVersion(nextVersion)
.WithIgnoreConfiguration(new() { Before = dateTimeNow.AddDays(1) }).Build();
.WithIgnoreConfiguration(new IgnoreConfiguration() { Before = dateTimeNow.AddDays(1) }).Build();

fixture.AssertFullSemver(expectedFullSemVer, configuration);
}
Expand All @@ -33,7 +33,7 @@ public void ShouldNotFallbackToBaseVersionWhenAllCommitsAreNotIgnored(string? ne
fixture.MakeACommit();

var configuration = GitFlowConfigurationBuilder.New.WithNextVersion(nextVersion)
.WithIgnoreConfiguration(new() { Before = dateTimeNow.AddDays(-1) }).Build();
.WithIgnoreConfiguration(new IgnoreConfiguration() { Before = dateTimeNow.AddDays(-1) }).Build();

fixture.AssertFullSemver(expectedFullSemVer, configuration);
}
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersion.Core/Agents/IBuildAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ public interface IBuildAgent
bool IsDefault { get; }

bool CanApplyToCurrentContext();
void WriteIntegration(Action<string?> writer, GitVersionVariables variables, bool updateBuildNumber = true);
string? GetCurrentBranch(bool usingDynamicRepos);
bool PreventFetch();
bool ShouldCleanUpRemotes();

void WriteIntegration(Action<string?> writer, GitVersionVariables variables, bool updateBuildNumber = true);
}

public interface ICurrentBuildAgent : IBuildAgent { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace GitVersion.Configuration;
public interface IConfigurationFileLocator
{
bool TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath);
GitVersionConfiguration ReadConfiguration(string? configFilePath);
IGitVersionConfiguration ReadConfiguration(string? configFilePath);
IReadOnlyDictionary<object, object?>? ReadOverrideConfiguration(string? configFilePath);
void Verify(string? workingDirectory, string? projectRootDirectory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion.Configuration;

public class BranchConfigurationBuilder
internal class BranchConfigurationBuilder
{
public static BranchConfigurationBuilder New => new();

Expand Down Expand Up @@ -148,7 +148,7 @@ public virtual BranchConfigurationBuilder WithConfiguration(IBranchConfiguration
return this;
}

public BranchConfiguration Build() => new()
public IBranchConfiguration Build() => new BranchConfiguration
{
VersioningMode = versioningMode,
Label = label,
Expand Down
25 changes: 14 additions & 11 deletions src/GitVersion.Core/Configuration/ConfigurationBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public virtual TConfigurationBuilder WithLabelPreReleaseWeight(int? value)
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithIgnoreConfiguration(IgnoreConfiguration value)
public virtual TConfigurationBuilder WithIgnoreConfiguration(IIgnoreConfiguration value)
{
this.ignore = value;
this.ignore = (IgnoreConfiguration)value;
return (TConfigurationBuilder)this;
}

Expand Down Expand Up @@ -206,6 +206,9 @@ public virtual TConfigurationBuilder WithoutBranches()
public virtual BranchConfigurationBuilder WithBranch(string value)
=> this.branchConfigurationBuilders.GetOrAdd(value, () => BranchConfigurationBuilder.New);

public virtual BranchConfigurationBuilder WithBranch(string value, BranchConfigurationBuilder builder)
=> this.branchConfigurationBuilders.GetOrAdd(value, () => builder);

public virtual TConfigurationBuilder WithBranch(string value, Action<BranchConfigurationBuilder> action)
{
var result = this.branchConfigurationBuilders.GetOrAdd(value, () => BranchConfigurationBuilder.New);
Expand Down Expand Up @@ -291,7 +294,7 @@ public virtual TConfigurationBuilder WithPreReleaseWeight(int? value)
return (TConfigurationBuilder)this;
}

public virtual TConfigurationBuilder WithConfiguration(GitVersionConfiguration value)
public virtual TConfigurationBuilder WithConfiguration(IGitVersionConfiguration value)
{
WithAssemblyVersioningScheme(value.AssemblyVersioningScheme);
WithAssemblyFileVersioningScheme(value.AssemblyFileVersioningScheme);
Expand Down Expand Up @@ -338,15 +341,15 @@ public void AddOverride(IReadOnlyDictionary<object, object?> value)
}
}

public virtual GitVersionConfiguration Build()
public virtual IGitVersionConfiguration Build()
{
Dictionary<string, BranchConfiguration> branches = new();
foreach (var (name, branchConfigurationBuilder) in this.branchConfigurationBuilders)
{
branches.Add(name, branchConfigurationBuilder.Build());
branches.Add(name, (BranchConfiguration)branchConfigurationBuilder.Build());
}

GitVersionConfiguration configuration = new()
IGitVersionConfiguration configuration = new GitVersionConfiguration
{
AssemblyVersioningScheme = this.assemblyVersioningScheme,
AssemblyFileVersioningScheme = this.assemblyFileVersioningScheme,
Expand Down Expand Up @@ -397,26 +400,26 @@ public virtual GitVersionConfiguration Build()
return configuration;
}

private static void FinalizeConfiguration(GitVersionConfiguration configuration)
private static void FinalizeConfiguration(IGitVersionConfiguration configuration)
{
foreach (var (name, branchConfiguration) in configuration.Branches)
{
FinalizeBranchConfiguration(configuration, name, branchConfiguration);
}
}

private static void FinalizeBranchConfiguration(GitVersionConfiguration configuration, string branchName,
private static void FinalizeBranchConfiguration(IGitVersionConfiguration configuration, string branchName,
IBranchConfiguration branchConfiguration)
{
var branches = new Dictionary<string, BranchConfiguration>(configuration.Branches);
var branches = configuration.Branches;
foreach (var targetBranchName in branchConfiguration.IsSourceBranchFor)
{
var targetBranchConfiguration = branches[targetBranchName];
var targetBranchConfiguration = (BranchConfiguration)branches[targetBranchName];
targetBranchConfiguration.SourceBranches.Add(branchName);
}
}

private static void ValidateConfiguration(GitVersionConfiguration configuration)
private static void ValidateConfiguration(IGitVersionConfiguration configuration)
{
foreach (var (name, branchConfiguration) in configuration.Branches)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
WarnAboutAmbiguousConfigFileSelection(workingDirectory, projectRootDirectory);
}

public GitVersionConfiguration ReadConfiguration(string? configFilePath)
public IGitVersionConfiguration ReadConfiguration(string? configFilePath)
{
if (configFilePath == null || !this.fileSystem.Exists(configFilePath)) return new GitVersionConfiguration();

Expand Down
8 changes: 4 additions & 4 deletions src/GitVersion.Core/Configuration/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ internal class ConfigurationHelper
if (this._dictionary == null)
{
this._yaml ??= ConfigurationSerializer.Serialize(this.configuration!);
this._dictionary = ConfigurationSerializer.Deserialize<Dictionary<object, object?>>(this._yaml!);
this._dictionary = ConfigurationSerializer.Deserialize<Dictionary<object, object?>>(this._yaml);
}
return this._dictionary;
}
}
private IReadOnlyDictionary<object, object?>? _dictionary;

public GitVersionConfiguration Configuration => this.configuration ??= ConfigurationSerializer.Deserialize<GitVersionConfiguration>(Yaml);
private GitVersionConfiguration? configuration;
public IGitVersionConfiguration Configuration => this.configuration ??= ConfigurationSerializer.Deserialize<GitVersionConfiguration>(Yaml);
private IGitVersionConfiguration? configuration;

internal ConfigurationHelper(string yaml) => this._yaml = yaml.NotNull();

internal ConfigurationHelper(IReadOnlyDictionary<object, object?> dictionary) => this._dictionary = dictionary.NotNull();

public ConfigurationHelper(GitVersionConfiguration configuration) => this.configuration = configuration.NotNull();
public ConfigurationHelper(IGitVersionConfiguration configuration) => this.configuration = configuration.NotNull();

public void Override(IReadOnlyDictionary<object, object?> value)
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Configuration/ConfigurationSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace GitVersion.Configuration;

public static class ConfigurationSerializer
internal static class ConfigurationSerializer
{
private static IDeserializer Deserializer => new DeserializerBuilder()
.WithNamingConvention(HyphenatedNamingConvention.Instance)
Expand All @@ -20,7 +20,7 @@ public static class ConfigurationSerializer

public static string Serialize(object graph) => Serializer.Serialize(graph);

public static GitVersionConfiguration Read(TextReader reader)
public static IGitVersionConfiguration Read(TextReader reader)
{
var configuration = Deserializer.Deserialize<GitVersionConfiguration?>(reader);
return configuration ?? new GitVersionConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class GitFlowConfigurationBuilder : ConfigurationBuilderBase<Git

private GitFlowConfigurationBuilder()
{
WithConfiguration(new()
WithConfiguration(new GitVersionConfiguration()
{
AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch,
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class GitHubFlowConfigurationBuilder : ConfigurationBuilderBase<

private GitHubFlowConfigurationBuilder()
{
WithConfiguration(new()
WithConfiguration(new GitVersionConfiguration()
{
AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch,
AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace GitVersion.Configuration;

public sealed record GitVersionConfiguration : BranchConfiguration, IGitVersionConfiguration
internal sealed record GitVersionConfiguration : BranchConfiguration, IGitVersionConfiguration
{
[JsonPropertyName("workflow")]
[JsonPropertyDescription("The base template of the configuration to use. Possible values are: GitFlow/v1 or GitHubFlow/v1")]
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Configuration/IConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ internal interface IConfigurationBuilder
{
void AddOverride(IReadOnlyDictionary<object, object?> value);

GitVersionConfiguration Build();
IGitVersionConfiguration Build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public IgnoreConfigurationBuilder WithShas(HashSet<string> value)
return this;
}

public IgnoreConfiguration Build() => new()
public IIgnoreConfiguration Build() => new IgnoreConfiguration()
{
Before = before,
Shas = shas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public AppVeyorSetup WithData(ProjectVisibility visibility)
return this;
}

protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, GitVersionConfiguration configuration, string workingDirectory)
protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, ConfigurationBuilder configurationBuilder, string workingDirectory)
{
var editConfigStep = this.StepFactory.CreateStep<EditConfigStep>();
switch (result)
Expand Down Expand Up @@ -80,7 +80,7 @@ private void WriteConfig(string workingDirectory, IFileSystem fileSystem, string
this.Log.Info($"AppVeyor sample configuration file written to {outputFilename}");
}

protected override string GetPrompt(GitVersionConfiguration configuration, string workingDirectory)
protected override string GetPrompt(ConfigurationBuilder configurationBuilder, string workingDirectory)
{
var prompt = new StringBuilder();
if (AppVeyorConfigExists(workingDirectory, this.FileSystem))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public AppveyorPublicPrivate(IConsole console, IFileSystem fileSystem, ILog log,
{
}

protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, GitVersionConfiguration configuration, string workingDirectory)
protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, ConfigurationBuilder configurationBuilder, string workingDirectory)
{
switch (result)
{
Expand All @@ -26,7 +26,7 @@ protected override StepResult HandleResult(string? result, Queue<ConfigInitWizar
return StepResult.Ok();
}

protected override string GetPrompt(GitVersionConfiguration configuration, string workingDirectory) => @"Is your project public or private?
protected override string GetPrompt(ConfigurationBuilder configurationBuilder, string workingDirectory) => @"Is your project public or private?

That is ... does it require authentication to clone/pull?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public SetupBuildScripts(IConsole console, IFileSystem fileSystem, ILog log, ICo
{
}

protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, GitVersionConfiguration configuration, string workingDirectory)
protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, ConfigurationBuilder configurationBuilder, string workingDirectory)
{
switch (result)
{
Expand All @@ -23,7 +23,7 @@ protected override StepResult HandleResult(string? result, Queue<ConfigInitWizar
return StepResult.Ok();
}

protected override string GetPrompt(GitVersionConfiguration configuration, string workingDirectory) => @"What build server are you using?
protected override string GetPrompt(ConfigurationBuilder configurationBuilder, string workingDirectory) => @"What build server are you using?

Want to see more? Contribute a pull request!

Expand Down
10 changes: 7 additions & 3 deletions src/GitVersion.Core/Configuration/Init/EditConfigStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace GitVersion.Configuration.Init;

public class EditConfigStep : ConfigInitWizardStep
internal class EditConfigStep : ConfigInitWizardStep
{
public EditConfigStep(IConsole console, IFileSystem fileSystem, ILog log, IConfigInitStepFactory stepFactory) : base(console, fileSystem, log, stepFactory)
{
}

protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, GitVersionConfiguration configuration, string workingDirectory)
protected override StepResult HandleResult(string? result, Queue<ConfigInitWizardStep> steps, ConfigurationBuilder configurationBuilder, string workingDirectory)
{
switch (result)
{
Expand Down Expand Up @@ -45,7 +45,10 @@ protected override StepResult HandleResult(string? result, Queue<ConfigInitWizar
return StepResult.InvalidResponseSelected();
}

protected override string GetPrompt(GitVersionConfiguration configuration, string workingDirectory) => $@"Which would you like to change?
protected override string GetPrompt(ConfigurationBuilder configurationBuilder, string workingDirectory)
{
var configuration = configurationBuilder.Build();
return $@"Which would you like to change?

0) Save changes and exit
1) Exit without saving
Expand All @@ -57,6 +60,7 @@ protected override string GetPrompt(GitVersionConfiguration configuration, strin
5) Branch Increment mode (per commit/after tag) (Current: {configuration.VersioningMode ?? VersionCalculation.VersioningMode.ContinuousDeployment})
6) Assembly versioning scheme (Current: {configuration.AssemblyVersioningScheme})
7) Setup build scripts";
}

protected override string? DefaultResult => null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace GitVersion.Configuration.Init;

public class GitVersionInitModule : GitVersionModule
public class GitVersionInitModule : IGitVersionModule
{
public override void RegisterTypes(IServiceCollection services)
public void RegisterTypes(IServiceCollection services)
{
services.AddTransient<IConfigInitWizard, ConfigInitWizard>();
services.AddTransient<IConfigInitStepFactory, ConfigInitStepFactory>();

var steps = FindAllDerivedTypes<ConfigInitWizardStep>(Assembly.GetAssembly(GetType()));
var steps = IGitVersionModule.FindAllDerivedTypes<ConfigInitWizardStep>(Assembly.GetAssembly(GetType()));

foreach (var step in steps)
{
Expand Down
Loading