-
Notifications
You must be signed in to change notification settings - Fork 6
Allow customizable ProjectRootDirectory calculation for complex project structures #621
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
…suesData Co-authored-by: pascalberger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Fix the comments for Scripting and Frosting recipe
| @@ -17,14 +17,20 @@ public class IssuesState : IIssuesState | |||
|
|
|||
| private readonly List<(IIssueProvider, string)> issueProvidersAndRuns = []; | |||
|
|
|||
| private DirectoryPath? projectRootDirectoryOverride; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use nullable reference types in this project
| private DirectoryPath? projectRootDirectoryOverride; | |
| private DirectoryPath projectRootDirectoryOverride; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by removing the nullable reference type syntax. Changed DirectoryPath? projectRootDirectoryOverride to DirectoryPath projectRootDirectoryOverride in commit 8f80e9c.
| /// Default implementation returns the parent directory of the <see cref="BuildRootDirectory"/>. | ||
| /// </summary> | ||
| /// <returns>The project root directory.</returns> | ||
| protected virtual DirectoryPath GetProjectRootDirectory() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to DetermineProjectRootDirectory to be consistent with other methods and avoid confusion with ProjectRootDirectory property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed method from GetProjectRootDirectory to DetermineProjectRootDirectory in both Frosting and Scripting recipes for consistency with other methods. Updated in commit 8f80e9c.
…jectRootDirectory, fix comments Co-authored-by: pascalberger <[email protected]>
Fixed comments in both Scripting and Frosting recipes. Corrected XML documentation, fixed malformed comment in IssuesData.cake, and updated method documentation to use "Determines" instead of "Gets" for consistency. Changes in commit 8f80e9c. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Fix comments and linting warnings in test class
| public DirectoryPath ProjectRootDirectory { get; set; } | ||
| public DirectoryPath ProjectRootDirectory | ||
| { | ||
| get => this.projectRootDirectoryOverride ?? this.DetermineProjectRootDirectory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call DetermineProjectRootDirectory in constructor and set the property. The property should be immutable from outside the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified both IssuesState (Frosting) and IssuesData (Scripting) to call DetermineProjectRootDirectory() in constructor and set the property. Removed lazy evaluation logic and the projectRootDirectoryOverride field. The property is now initialized with default values in the constructor but maintains the public setter for interface compatibility. Changes in commit a17572c.
…uctor Co-authored-by: pascalberger <[email protected]>
Fixed linting warnings in test class. Addressed formatting issues (IDE0055), used expression bodies for methods (IDE0022), and fixed 'this' qualification (IDE0009). Reduced warnings from 14 to 2 (only primary constructor warnings remain). Changes in commit a17572c. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Fix remaining open issue
| @@ -72,7 +83,7 @@ public IssuesState( | |||
| this.BuildRootDirectory = context.MakeAbsolute(context.Directory("./")); | |||
| context.Information("Build script root directory: {0}", this.BuildRootDirectory); | |||
|
|
|||
| this.ProjectRootDirectory = this.BuildRootDirectory.Combine("..").Collapse(); | |||
| this.ProjectRootDirectory = this.DetermineProjectRootDirectory(); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling virtual methods in constructors leads to issues. See https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2214.
Idea: Allow to pass a function to the constructor, to which the current state is passed and which returns the project root directory. API should not be breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the CA2214 issue by replacing virtual method calls in constructors with function parameters. Added optional projectRootDirectoryProvider parameters to both IssuesState and IssuesData constructors that allow passing custom logic without calling virtual methods from constructors. The API remains non-breaking as the parameter is optional with default behavior preserved. Virtual methods are still available for other scenarios. All tests pass. Commit: 735c676
…ction parameter Co-authored-by: pascalberger <[email protected]>
Fixed the remaining CA2214 issue by replacing virtual method calls in constructors with function parameters. The solution allows passing custom project root directory calculation logic without violating the rule against calling virtual methods from constructors. The API remains backward compatible. Commit: 735c676 |
Updated PR title and description to reflect that this addresses issue #620 by allowing customization of ProjectRootDirectory through function parameters. The solution avoids virtual methods (which would cause CA2214) while still providing the flexibility requested in the original issue. Commit: Current PR description now matches the actual implementation. |
This PR addresses issue #620 by allowing customization of how
ProjectRootDirectoryis calculated, enabling support for complex project structures where the build is not in a subdirectory of the project.Problem
The
ProjectRootDirectorywas hardcoded to be the parent directory of the build root directory. This works for builds created with the default template, but fails for complex project structures where:Solution
Added optional
projectRootDirectoryProviderfunction parameters to bothIssuesState(Frosting) andIssuesData(Scripting) constructors:Usage Example
For complex project structures, you can now provide custom logic:
Design Decision
While the original issue suggested using virtual methods, this implementation uses function parameters instead. This approach:
Backward Compatibility
Fixes #620.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.