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

Conversation

HHobeck
Copy link
Contributor

@HHobeck HHobeck commented Mar 10, 2023

Change GitVersionConfiguration and BranchConfiguration to record type and extract interfaces

Description

Preparation for #3306

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -104,8 +104,9 @@ public IBranch GetTargetBranch(string? targetBranchName)

public IBranch? FindMainBranch(GitVersionConfiguration configuration)
{
var branches = configuration.Branches;
var mainBranchRegex = configuration.Branches[ConfigurationConstants.MainBranchKey].Regex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var mainBranchRegex = configuration.Branches[ConfigurationConstants.MainBranchKey].Regex
var mainBranchRegex = branches[ConfigurationConstants.MainBranchKey].Regex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

[JsonPropertyDescription("The regex pattern to use to match this branch.")]
public string? Regex { get; set; }
[JsonPropertyDescription("The regular expression pattern to use to match this branch.")]
public string? Regex { get; internal set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public string? Regex { get; internal set; }
public string? RegularExpression { get; internal set; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public SemanticVersionFormat SemanticVersionFormat { get; internal set; }

[JsonIgnore]
IReadOnlyDictionary<string, BranchConfiguration> IGitVersionConfiguration.Branches => Branches;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use the newly interface here

Suggested change
IReadOnlyDictionary<string, BranchConfiguration> IGitVersionConfiguration.Branches => Branches;
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches => Branches;

and the next line as well?

Copy link
Contributor Author

@HHobeck HHobeck Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the first line because the second line is used for initialiization.

@arturcic
Copy link
Member

@HHobeck will this follow up with a PR that will start using the new interfaces in the core instead of the classes? Or we can include that in the current PR?

@arturcic
Copy link
Member

Please also run from the root

dotnet run --project .\src\GitVersion.Schema --framework net7.0 -- --outputdirectory schemas --version 6.0

to generate the updated schema as you've changed the descriptions

HHobeck added 2 commits March 10, 2023 22:27
…sible. Execute: dotnet run --project .\src\GitVersion.Schema --framework net7.0 -- --outputdirectory schemas --version 6.0
@HHobeck
Copy link
Contributor Author

HHobeck commented Mar 10, 2023

@HHobeck will this follow up with a PR that will start using the new interfaces in the core instead of the classes? Or we can include that in the current PR?

I think it might be better to separate it and create another PR.

@arturcic
Copy link
Member

arturcic commented Mar 11, 2023

TODOs for the next PR:

  • make IgnoreConfiguration, BranchConfiguration and GitVersionConfiguration records internal
  • make usage of the respective interfaces in the code (maybe with the exception of unit tests)
  • consider making the properties init instead of private set for the above records, and maybe readonly were possible
  • consider moving the [JsonProperty*] attributes from the record to the interface and adapt the schema generation to use the interfaces instead

Please add more to this list what you have in mind, and then you can use this list as description for the new PR

@arturcic
Copy link
Member

LGTM! It moves in the direction that will allow us to move the implementations details of Configuration into its own module

@HHobeck
Copy link
Contributor Author

HHobeck commented Mar 11, 2023

TODOs for the next PR:

  • make IgnoreConfiguration, BranchConfiguration and GitVersionConfiguration records internal
  • make usage of the respective interfaces in the code (maybe with the exception of unit tests)
  • consider making the properties init instead of private set for the above records, and maybe readonly were possible
  • consider moving the [JsonProperty*] attributes from the record to the interface and adapt the schema generation to use the interfaces instead

Beside the fact that it might be a lot of work and tricky doing it I think it is not feasible (last point) moving the JsonProperty to the interface. The reason is that we are using interfaces and mutable data types in the interface and YamlDotnet cannot handle it.

LGTM! It moves in the direction that will allow us to move the implementations details of Configuration into its own module

Yes that's the goal to seperate the aspect of loading/merging the configuration from using it. I'm done please merge this PR to main.

@arturcic arturcic enabled auto-merge March 11, 2023 07:48
@arturcic arturcic merged commit 506b6ec into GitTools:main Mar 11, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 11, 2023

Thank you @HHobeck for your contribution!

@arturcic arturcic deleted the feature/change-configuration-to-record-type-and-extract-interfaces branch March 11, 2023 08:01
@arturcic
Copy link
Member

Beside the fact that it might be a lot of work and tricky doing it I think it is not feasible (last point) moving the JsonProperty to the interface. The reason is that we are using interfaces and mutable data types in the interface and YamlDotnet cannot handle it.

That's the reason I put consider. I will have a look if it's feasible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants